Commit 6852e253 authored by o9000's avatar o9000

Refactoring

parent ac8256a9
......@@ -117,6 +117,8 @@ set( SOURCES src/config.c
src/panel.c
src/server.c
src/tint.c
src/mouse_actions.c
src/drag_and_drop.c
src/clock/clock.c
src/systray/systraybar.c
src/launcher/launcher.c
......
This diff is collapsed.
/**************************************************************************
* Copyright (C) 2017 tint2 authors
*
**************************************************************************/
#ifndef DRAG_AND_DROP_H
#define DRAG_AND_DROP_H
#include <X11/Xlib.h>
void dnd_init();
void handle_dnd_enter(XClientMessageEvent *e);
void handle_dnd_position(XClientMessageEvent *e);
void handle_dnd_drop(XClientMessageEvent *e);
void handle_dnd_selection_notify(XSelectionEvent *e);
#endif
This diff is collapsed.
#ifndef MOUSE_ACTIONS_H
#define MOUSE_ACTIONS_H
#include "panel.h"
gboolean tint2_handles_click(Panel *panel, XButtonEvent *e);
void handle_mouse_press_event(XEvent *e);
void handle_mouse_move_event(XEvent *e);
void handle_mouse_release_event(XEvent *e);
#endif
......@@ -18,11 +18,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**************************************************************************/
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xrender.h>
#include <X11/extensions/Xrandr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "server.h"
......@@ -118,6 +120,118 @@ void server_init_atoms()
server.atom.TARGETS = XInternAtom(server.display, "TARGETS", False);
}
const char *GetAtomName(Display *disp, Atom a)
{
if (a == None)
return "None";
else
return XGetAtomName(disp, a);
}
// This fetches all the data from a property
struct Property read_property(Display *disp, Window w, Atom property)
{
Atom actual_type;
int actual_format;
unsigned long nitems;
unsigned long bytes_after;
unsigned char *ret = 0;
int read_bytes = 1024;
// Keep trying to read the property until there are no
// bytes unread.
do {
if (ret != 0)
XFree(ret);
XGetWindowProperty(disp,
w,
property,
0,
read_bytes,
False,
AnyPropertyType,
&actual_type,
&actual_format,
&nitems,
&bytes_after,
&ret);
read_bytes *= 2;
} while (bytes_after != 0);
fprintf(stderr, "DnD %s:%d: Property:\n", __FILE__, __LINE__);
fprintf(stderr, "DnD %s:%d: Actual type: %s\n", __FILE__, __LINE__, GetAtomName(disp, actual_type));
fprintf(stderr, "DnD %s:%d: Actual format: %d\n", __FILE__, __LINE__, actual_format);
fprintf(stderr, "DnD %s:%d: Number of items: %lu\n", __FILE__, __LINE__, nitems);
Property p;
p.data = ret;
p.format = actual_format;
p.nitems = nitems;
p.type = actual_type;
return p;
}
// This function takes a list of targets which can be converted to (atom_list, nitems)
// and a list of acceptable targets with prioritees (datatypes). It returns the highest
// entry in datatypes which is also in atom_list: ie it finds the best match.
Atom pick_target_from_list(Display *disp, Atom *atom_list, int nitems)
{
Atom to_be_requested = None;
int i;
for (i = 0; i < nitems; i++) {
const char *atom_name = GetAtomName(disp, atom_list[i]);
fprintf(stderr, "DnD %s:%d: Type %d = %s\n", __FILE__, __LINE__, i, atom_name);
// See if this data type is allowed and of higher priority (closer to zero)
// than the present one.
if (strcmp(atom_name, "STRING") == 0) {
to_be_requested = atom_list[i];
}
}
return to_be_requested;
}
// Finds the best target given up to three atoms provided (any can be None).
// Useful for part of the Xdnd protocol.
Atom pick_target_from_atoms(Display *disp, Atom t1, Atom t2, Atom t3)
{
Atom atoms[3];
int n = 0;
if (t1 != None)
atoms[n++] = t1;
if (t2 != None)
atoms[n++] = t2;
if (t3 != None)
atoms[n++] = t3;
return pick_target_from_list(disp, atoms, n);
}
// Finds the best target given a local copy of a property.
Atom pick_target_from_targets(Display *disp, Property p)
{
// The list of targets is a list of atoms, so it should have type XA_ATOM
// but it may have the type TARGETS instead.
if ((p.type != XA_ATOM && p.type != server.atom.TARGETS) || p.format != 32) {
// This would be really broken. Targets have to be an atom list
// and applications should support this. Nevertheless, some
// seem broken (MATLAB 7, for instance), so ask for STRING
// next instead as the lowest common denominator
return XA_STRING;
} else {
Atom *atom_list = (Atom *)p.data;
return pick_target_from_list(disp, atom_list, p.nitems);
}
}
void cleanup_server()
{
if (server.colormap)
......@@ -597,3 +711,25 @@ void server_init_visual()
server.visual = DefaultVisual(server.display, server.screen);
}
}
void server_init_xdamage()
{
XDamageQueryExtension(server.display, &server.xdamage_event_type, &server.xdamage_event_error_type);
server.xdamage_event_type += XDamageNotify;
server.xdamage_event_error_type += XDamageNotify;
}
// Forward mouse click to the desktop window
void forward_click(XEvent *e)
{
// forward the click to the desktop window (thanks conky)
XUngrabPointer(server.display, e->xbutton.time);
e->xbutton.window = server.root_win;
// icewm doesn't open under the mouse.
// and xfce doesn't open at all.
e->xbutton.x = e->xbutton.x_root;
e->xbutton.y = e->xbutton.y_root;
// printf("**** %d, %d\n", e->xbutton.x, e->xbutton.y);
// XSetInputFocus(server.display, e->xbutton.window, RevertToParent, e->xbutton.time);
XSendEvent(server.display, e->xbutton.window, False, ButtonPressMask, e);
}
......@@ -93,6 +93,30 @@ typedef struct Global_atom {
Atom TARGETS;
} Global_atom;
typedef struct Property {
unsigned char *data;
int format, nitems;
Atom type;
} Property;
// Returns the name of an Atom as string. Do not free the string.
const char *GetAtomName(Display *disp, Atom a);
// This function takes a list of targets which can be converted to (atom_list, nitems)
// and a list of acceptable targets with prioritees (datatypes). It returns the highest
// entry in datatypes which is also in atom_list: ie it finds the best match.
Atom pick_target_from_list(Display *disp, Atom *atom_list, int nitems);
// Finds the best target given up to three atoms provided (any can be None).
// Useful for part of the Xdnd protocol.
Atom pick_target_from_atoms(Display *disp, Atom t1, Atom t2, Atom t3);
// Finds the best target given a local copy of a property.
Atom pick_target_from_targets(Display *disp, Property p);
// This fetches all the data from a property
struct Property read_property(Display *disp, Window w, Atom property);
typedef struct Monitor {
int x;
int y;
......@@ -135,6 +159,8 @@ typedef struct Server {
Colormap colormap;
Colormap colormap32;
Global_atom atom;
int xdamage_event_type;
int xdamage_event_error_type;
#ifdef HAVE_SN
SnDisplay *sn_display;
GTree *pids;
......@@ -153,6 +179,7 @@ Atom server_get_atom(char *atom_name);
void server_catch_error(Display *d, XErrorEvent *ev);
void server_init_atoms();
void server_init_visual();
void server_init_xdamage();
// detect root background
void get_root_pixmap();
......@@ -167,4 +194,7 @@ GSList *get_desktop_names();
int get_current_desktop();
void change_desktop(int desktop);
// Forward mouse click to the desktop window
void forward_click(XEvent *e);
#endif
......@@ -478,7 +478,7 @@ void start_net()
XSendEvent(server.display, server.root_win, False, StructureNotifyMask, (XEvent *)&ev);
}
void net_message(XClientMessageEvent *e)
void handle_systray_event(XClientMessageEvent *e)
{
if (systray_profile)
fprintf(stderr, "[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__);
......
......@@ -96,7 +96,7 @@ gboolean systray_on_monitor(int i_monitor, int num_panels);
// many tray icon doesn't manage stop/restart of the systray manager
void start_net();
void stop_net();
void net_message(XClientMessageEvent *e);
void handle_systray_event(XClientMessageEvent *e);
gboolean add_icon(Window id);
gboolean reparent_icon(TrayWindow *traywin);
......
......@@ -719,3 +719,66 @@ void del_urgent(Task *task)
urgent_timeout = NULL;
}
}
void task_handle_mouse_event(Task *task, MouseAction action)
{
if (!task)
return;
switch (action) {
case NONE:
break;
case CLOSE:
close_window(task->win);
break;
case TOGGLE:
activate_window(task->win);
break;
case ICONIFY:
XIconifyWindow(server.display, task->win, server.screen);
break;
case TOGGLE_ICONIFY:
if (active_task && task->win == active_task->win)
XIconifyWindow(server.display, task->win, server.screen);
else
activate_window(task->win);
break;
case SHADE:
toggle_window_shade(task->win);
break;
case MAXIMIZE_RESTORE:
toggle_window_maximized(task->win);
break;
case MAXIMIZE:
toggle_window_maximized(task->win);
break;
case RESTORE:
toggle_window_maximized(task->win);
break;
case DESKTOP_LEFT: {
if (task->desktop == 0)
break;
int desktop = task->desktop - 1;
change_window_desktop(task->win, desktop);
if (desktop == server.desktop)
activate_window(task->win);
break;
}
case DESKTOP_RIGHT: {
if (task->desktop == server.num_desktops)
break;
int desktop = task->desktop + 1;
change_window_desktop(task->win, desktop);
if (desktop == server.desktop)
activate_window(task->win);
break;
}
case NEXT_TASK: {
Task *task1 = next_task(find_active_task(task));
activate_window(task1->win);
} break;
case PREV_TASK: {
Task *task1 = prev_task(find_active_task(task));
activate_window(task1->win);
}
}
}
......@@ -10,6 +10,7 @@
#include <X11/Xlib.h>
#include <pango/pangocairo.h>
#include <Imlib2.h>
#include "common.h"
#include "timer.h"
......@@ -88,6 +89,7 @@ void task_update_icon(Task *task);
gboolean task_update_title(Task *task);
void reset_active_task();
void set_task_state(Task *task, TaskState state);
void task_handle_mouse_event(Task *task, MouseAction action);
// Given a pointer to the task that is currently under the mouse (current_task),
// returns a pointer to the Task for the active window on the same taskbar.
......
This diff is collapsed.
......@@ -630,7 +630,7 @@ void free_area(Area *a)
free_area_gradient_instances(a);
}
void mouse_over(Area *area, int pressed)
void mouse_over(Area *area, gboolean pressed)
{
if (mouse_over_area == area && !area)
return;
......
......@@ -357,7 +357,7 @@ void free_area_gradient_instances(Area *area);
void area_dump_geometry(Area *area, int indent);
void mouse_over(Area *area, int pressed);
void mouse_over(Area *area, gboolean pressed);
void mouse_out();
void update_gradient(GradientInstance *gi);
......
......@@ -225,3 +225,7 @@ src/tint2rc.c
src/tint2rc.h
src/button/button.c
src/button/button.h
src/drag_and_drop.c
src/drag_and_drop.h
src/mouse_actions.c
src/mouse_actions.h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment