Refactoring

This commit is contained in:
o9000 2017-08-31 16:42:05 +02:00
parent ac8256a96b
commit 6852e25372
15 changed files with 1025 additions and 861 deletions

View file

@ -117,6 +117,8 @@ set( SOURCES src/config.c
src/panel.c src/panel.c
src/server.c src/server.c
src/tint.c src/tint.c
src/mouse_actions.c
src/drag_and_drop.c
src/clock/clock.c src/clock/clock.c
src/systray/systraybar.c src/systray/systraybar.c
src/launcher/launcher.c src/launcher/launcher.c

283
src/drag_and_drop.c Normal file
View file

@ -0,0 +1,283 @@
/**************************************************************************
* Copyright (C) 2017 tint2 authors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "drag_and_drop.h"
#include "panel.h"
#include "server.h"
#include "task.h"
// Drag and Drop state variables
static Window dnd_source_window;
static Window dnd_target_window;
static int dnd_version;
static Atom dnd_selection;
static Atom dnd_atom;
static int dnd_sent_request;
static char *dnd_launcher_exec;
static gboolean dnd_debug = FALSE;
void dnd_init()
{
dnd_source_window = 0;
dnd_target_window = 0;
dnd_version = 0;
dnd_selection = XInternAtom(server.display, "PRIMARY", 0);
dnd_atom = None;
dnd_sent_request = 0;
dnd_launcher_exec = 0;
}
void handle_dnd_enter(XClientMessageEvent *e)
{
dnd_atom = None;
int more_than_3 = e->data.l[1] & 1;
dnd_source_window = e->data.l[0];
dnd_version = (e->data.l[1] >> 24);
if (dnd_debug) {
fprintf(stderr, "DnD %s:%d: DnDEnter\n", __FILE__, __LINE__);
fprintf(stderr,
"DnD %s:%d: DnDEnter. Supports > 3 types = %s\n",
__FILE__,
__LINE__,
more_than_3 ? "yes" : "no");
fprintf(stderr, "DnD %s:%d: Protocol version = %d\n", __FILE__, __LINE__, dnd_version);
fprintf(stderr, "DnD %s:%d: Type 1 = %s\n", __FILE__, __LINE__, GetAtomName(server.display, e->data.l[2]));
fprintf(stderr, "DnD %s:%d: Type 2 = %s\n", __FILE__, __LINE__, GetAtomName(server.display, e->data.l[3]));
fprintf(stderr, "DnD %s:%d: Type 3 = %s\n", __FILE__, __LINE__, GetAtomName(server.display, e->data.l[4]));
}
// Query which conversions are available and pick the best
if (more_than_3) {
// Fetch the list of possible conversions
// Notice the similarity to TARGETS with paste.
Property p = read_property(server.display, dnd_source_window, server.atom.XdndTypeList);
dnd_atom = pick_target_from_targets(server.display, p);
XFree(p.data);
} else {
// Use the available list
dnd_atom = pick_target_from_atoms(server.display, e->data.l[2], e->data.l[3], e->data.l[4]);
}
if (dnd_debug)
fprintf(stderr, "DnD %s:%d: Requested type = %s\n", __FILE__, __LINE__, GetAtomName(server.display, dnd_atom));
}
void handle_dnd_position(XClientMessageEvent *e)
{
dnd_target_window = e->window;
int accept = 0;
Panel *panel = get_panel(e->window);
int x, y, mapX, mapY;
Window child;
x = (e->data.l[2] >> 16) & 0xFFFF;
y = e->data.l[2] & 0xFFFF;
XTranslateCoordinates(server.display, server.root_win, e->window, x, y, &mapX, &mapY, &child);
Task *task = click_task(panel, mapX, mapY);
if (task) {
if (task->desktop != server.desktop)
change_desktop(task->desktop);
task_handle_mouse_event(task, TOGGLE);
} else {
LauncherIcon *icon = click_launcher_icon(panel, mapX, mapY);
if (icon) {
accept = 1;
dnd_launcher_exec = icon->cmd;
} else {
dnd_launcher_exec = 0;
}
}
// send XdndStatus event to get more XdndPosition events
XClientMessageEvent se;
se.type = ClientMessage;
se.window = e->data.l[0];
se.message_type = server.atom.XdndStatus;
se.format = 32;
se.data.l[0] = e->window; // XID of the target window
se.data.l[1] = accept ? 1 : 0; // bit 0: accept drop bit 1: send XdndPosition events if inside rectangle
se.data.l[2] = 0; // Rectangle x,y for which no more XdndPosition events
se.data.l[3] = (1 << 16) | 1; // Rectangle w,h for which no more XdndPosition events
if (accept) {
se.data.l[4] = dnd_version >= 2 ? e->data.l[4] : server.atom.XdndActionCopy;
} else {
se.data.l[4] = None; // None = drop will not be accepted
}
XSendEvent(server.display, e->data.l[0], False, NoEventMask, (XEvent *)&se);
}
void handle_dnd_drop(XClientMessageEvent *e)
{
if (dnd_target_window && dnd_launcher_exec) {
if (dnd_version >= 1) {
XConvertSelection(server.display,
server.atom.XdndSelection,
XA_STRING,
dnd_selection,
dnd_target_window,
e->data.l[2]);
} else {
XConvertSelection(server.display,
server.atom.XdndSelection,
XA_STRING,
dnd_selection,
dnd_target_window,
CurrentTime);
}
} else {
// The source is sending anyway, despite instructions to the contrary.
// So reply that we're not interested.
XClientMessageEvent m;
memset(&m, 0, sizeof(m));
m.type = ClientMessage;
m.display = e->display;
m.window = e->data.l[0];
m.message_type = server.atom.XdndFinished;
m.format = 32;
m.data.l[0] = dnd_target_window;
m.data.l[1] = 0;
m.data.l[2] = None; // Failed.
XSendEvent(server.display, e->data.l[0], False, NoEventMask, (XEvent *)&m);
}
}
void handle_dnd_selection_notify(XSelectionEvent *e)
{
Atom target = e->target;
if (dnd_debug) {
fprintf(stderr, "DnD %s:%d: A selection notify has arrived!\n", __FILE__, __LINE__);
fprintf(stderr,
"DnD %s:%d: Selection atom = %s\n",
__FILE__,
__LINE__,
GetAtomName(server.display, e->selection));
fprintf(stderr, "DnD %s:%d: Target atom = %s\n", __FILE__, __LINE__, GetAtomName(server.display, target));
fprintf(stderr,
"DnD %s:%d: Property atom = %s\n",
__FILE__,
__LINE__,
GetAtomName(server.display, e->property));
}
if (e->property != None && dnd_launcher_exec) {
Property prop = read_property(server.display, dnd_target_window, dnd_selection);
// If we're being given a list of targets (possible conversions)
if (target == server.atom.TARGETS && !dnd_sent_request) {
dnd_sent_request = 1;
dnd_atom = pick_target_from_targets(server.display, prop);
if (dnd_atom == None) {
if (dnd_debug)
fprintf(stderr, "No matching datatypes.\n");
} else {
// Request the data type we are able to select
if (dnd_debug)
fprintf(stderr, "Now requsting type %s", GetAtomName(server.display, dnd_atom));
XConvertSelection(server.display,
dnd_selection,
dnd_atom,
dnd_selection,
dnd_target_window,
CurrentTime);
}
} else if (target == dnd_atom) {
// Dump the binary data
if (dnd_debug) {
fprintf(stderr, "DnD %s:%d: Data begins:\n", __FILE__, __LINE__);
fprintf(stderr, "--------\n");
for (int i = 0; i < prop.nitems * prop.format / 8; i++)
fprintf(stderr, "%c", ((char *)prop.data)[i]);
fprintf(stderr, "--------\n");
}
int cmd_length = 0;
cmd_length += 1; // (
cmd_length += strlen(dnd_launcher_exec) + 1; // exec + space
cmd_length += 1; // open double quotes
for (int i = 0; i < prop.nitems * prop.format / 8; i++) {
char c = ((char *)prop.data)[i];
if (c == '\n') {
if (i < prop.nitems * prop.format / 8 - 1) {
cmd_length += 3; // close double quotes, space, open double quotes
}
} else if (c == '\r') {
// Nothing to do
} else {
cmd_length += 1; // 1 character
if (c == '`' || c == '$' || c == '\\') {
cmd_length += 1; // escape with one backslash
}
}
}
cmd_length += 1; // close double quotes
cmd_length += 2; // &)
cmd_length += 1; // terminator
char *cmd = (char *)calloc(cmd_length, 1);
cmd[0] = '\0';
strcat(cmd, "(");
strcat(cmd, dnd_launcher_exec);
strcat(cmd, " \"");
for (int i = 0; i < prop.nitems * prop.format / 8; i++) {
char c = ((char *)prop.data)[i];
if (c == '\n') {
if (i < prop.nitems * prop.format / 8 - 1) {
strcat(cmd, "\" \"");
}
} else if (c == '\r') {
// Nothing to do
} else {
if (c == '`' || c == '$' || c == '\\') {
strcat(cmd, "\\");
}
char sc[2];
sc[0] = c;
sc[1] = '\0';
strcat(cmd, sc);
}
}
strcat(cmd, "\"");
strcat(cmd, "&)");
if (dnd_debug)
fprintf(stderr, "DnD %s:%d: Running command: %s\n", __FILE__, __LINE__, cmd);
tint_exec(cmd, NULL, NULL, e->time, NULL, 0, 0);
free(cmd);
// Reply OK.
XClientMessageEvent m;
memset(&m, 0, sizeof(m));
m.type = ClientMessage;
m.display = server.display;
m.window = dnd_source_window;
m.message_type = server.atom.XdndFinished;
m.format = 32;
m.data.l[0] = dnd_target_window;
m.data.l[1] = 1;
m.data.l[2] = server.atom.XdndActionCopy; // We only ever copy.
XSendEvent(server.display, dnd_source_window, False, NoEventMask, (XEvent *)&m);
XSync(server.display, False);
}
XFree(prop.data);
}
}

18
src/drag_and_drop.h Normal file
View file

@ -0,0 +1,18 @@
/**************************************************************************
* 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

287
src/mouse_actions.c Normal file
View file

@ -0,0 +1,287 @@
/**************************************************************************
* Copyright (C) 2017 tint2 authors
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "drag_and_drop.h"
#include "panel.h"
#include "server.h"
#include "task.h"
#include "window.h"
gboolean tint2_handles_click(Panel *panel, XButtonEvent *e)
{
Task *task = click_task(panel, e->x, e->y);
if (task) {
if ((e->button == 1 && mouse_left != 0) || (e->button == 2 && mouse_middle != 0) ||
(e->button == 3 && mouse_right != 0) || (e->button == 4 && mouse_scroll_up != 0) ||
(e->button == 5 && mouse_scroll_down != 0)) {
return TRUE;
} else
return FALSE;
}
LauncherIcon *icon = click_launcher_icon(panel, e->x, e->y);
if (icon) {
if (e->button == 1) {
return TRUE;
} else {
return FALSE;
}
}
// no launcher/task clicked --> check if taskbar clicked
Taskbar *taskbar = click_taskbar(panel, e->x, e->y);
if (taskbar && e->button == 1 && taskbar_mode == MULTI_DESKTOP)
return TRUE;
if (click_clock(panel, e->x, e->y)) {
if ((e->button == 1 && clock_lclick_command) || (e->button == 2 && clock_mclick_command) ||
(e->button == 3 && clock_rclick_command) || (e->button == 4 && clock_uwheel_command) ||
(e->button == 5 && clock_dwheel_command))
return TRUE;
else
return FALSE;
}
#ifdef ENABLE_BATTERY
if (click_battery(panel, e->x, e->y)) {
if ((e->button == 1 && battery_lclick_command) || (e->button == 2 && battery_mclick_command) ||
(e->button == 3 && battery_rclick_command) || (e->button == 4 && battery_uwheel_command) ||
(e->button == 5 && battery_dwheel_command))
return TRUE;
else
return FALSE;
}
#endif
if (click_execp(panel, e->x, e->y))
return TRUE;
if (click_button(panel, e->x, e->y))
return TRUE;
return FALSE;
}
void handle_mouse_press_event(XEvent *e)
{
Panel *panel = get_panel(e->xany.window);
if (!panel)
return;
if (wm_menu && !tint2_handles_click(panel, &e->xbutton)) {
forward_click(e);
return;
}
task_drag = click_task(panel, e->xbutton.x, e->xbutton.y);
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
}
void handle_mouse_move_event(XEvent *e)
{
Panel *panel = get_panel(e->xany.window);
if (!panel || !task_drag)
return;
// Find the taskbar on the event's location
Taskbar *event_taskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y);
if (event_taskbar == NULL)
return;
// Find the task on the event's location
Task *event_task = click_task(panel, e->xbutton.x, e->xbutton.y);
// If the event takes place on the same taskbar as the task being dragged
if (&event_taskbar->area == task_drag->area.parent) {
if (taskbar_sort_method != TASKBAR_NOSORT) {
sort_tasks(event_taskbar);
} else {
// Swap the task_drag with the task on the event's location (if they differ)
if (event_task && event_task != task_drag) {
GList *drag_iter = g_list_find(event_taskbar->area.children, task_drag);
GList *task_iter = g_list_find(event_taskbar->area.children, event_task);
if (drag_iter && task_iter) {
gpointer temp = task_iter->data;
task_iter->data = drag_iter->data;
drag_iter->data = temp;
event_taskbar->area.resize_needed = 1;
schedule_panel_redraw();
task_dragged = 1;
}
}
}
} else { // The event is on another taskbar than the task being dragged
if (task_drag->desktop == ALL_DESKTOPS || taskbar_mode != MULTI_DESKTOP)
return;
Taskbar *drag_taskbar = (Taskbar *)task_drag->area.parent;
remove_area((Area *)task_drag);
if (event_taskbar->area.posx > drag_taskbar->area.posx || event_taskbar->area.posy > drag_taskbar->area.posy) {
int i = (taskbarname_enabled) ? 1 : 0;
event_taskbar->area.children = g_list_insert(event_taskbar->area.children, task_drag, i);
} else
event_taskbar->area.children = g_list_append(event_taskbar->area.children, task_drag);
// Move task to other desktop (but avoid the 'Window desktop changed' code in 'event_property_notify')
task_drag->area.parent = &event_taskbar->area;
task_drag->desktop = event_taskbar->desktop;
change_window_desktop(task_drag->win, event_taskbar->desktop);
if (hide_task_diff_desktop)
change_desktop(event_taskbar->desktop);
if (taskbar_sort_method != TASKBAR_NOSORT) {
sort_tasks(event_taskbar);
}
event_taskbar->area.resize_needed = 1;
drag_taskbar->area.resize_needed = 1;
task_dragged = 1;
schedule_panel_redraw();
panel->area.resize_needed = 1;
}
}
void handle_mouse_release_event(XEvent *e)
{
Panel *panel = get_panel(e->xany.window);
if (!panel)
return;
if (wm_menu && !tint2_handles_click(panel, &e->xbutton)) {
forward_click(e);
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
task_drag = 0;
return;
}
MouseAction action = TOGGLE_ICONIFY;
switch (e->xbutton.button) {
case 1:
action = mouse_left;
break;
case 2:
action = mouse_middle;
break;
case 3:
action = mouse_right;
break;
case 4:
action = mouse_scroll_up;
break;
case 5:
action = mouse_scroll_down;
break;
case 6:
action = mouse_tilt_left;
break;
case 7:
action = mouse_tilt_right;
break;
}
Clock *clock = click_clock(panel, e->xbutton.x, e->xbutton.y);
if (clock) {
clock_action(clock, e->xbutton.button, e->xbutton.x - clock->area.posx, e->xbutton.y - clock->area.posy, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
task_drag = 0;
return;
}
#ifdef ENABLE_BATTERY
Battery *battery = click_battery(panel, e->xbutton.x, e->xbutton.y);
if (battery) {
battery_action(battery, e->xbutton.button, e->xbutton.x - battery->area.posx, e->xbutton.y - battery->area.posy, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
task_drag = 0;
return;
}
#endif
Execp *execp = click_execp(panel, e->xbutton.x, e->xbutton.y);
if (execp) {
execp_action(execp, e->xbutton.button, e->xbutton.x - execp->area.posx, e->xbutton.y - execp->area.posy, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
task_drag = 0;
return;
}
Button *button = click_button(panel, e->xbutton.x, e->xbutton.y);
if (button) {
button_action(button, e->xbutton.button, e->xbutton.x - button->area.posx, e->xbutton.y - button->area.posy, e->xbutton.time);
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
task_drag = 0;
return;
}
if (e->xbutton.button == 1 && click_launcher(panel, e->xbutton.x, e->xbutton.y)) {
LauncherIcon *icon = click_launcher_icon(panel, e->xbutton.x, e->xbutton.y);
if (icon) {
launcher_action(icon, e, e->xbutton.x - icon->area.posx, e->xbutton.y - icon->area.posy);
}
task_drag = 0;
return;
}
Taskbar *taskbar;
if (!(taskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y))) {
// TODO: check better solution to keep window below
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
task_drag = 0;
return;
}
// drag and drop task
if (task_dragged) {
task_drag = 0;
task_dragged = 0;
return;
}
// switch desktop
if (taskbar_mode == MULTI_DESKTOP) {
gboolean diff_desktop = FALSE;
if (taskbar->desktop != server.desktop && action != CLOSE && action != DESKTOP_LEFT &&
action != DESKTOP_RIGHT) {
diff_desktop = TRUE;
change_desktop(taskbar->desktop);
}
Task *task = click_task(panel, e->xbutton.x, e->xbutton.y);
if (task) {
if (diff_desktop) {
if (action == TOGGLE_ICONIFY) {
if (!window_is_active(task->win))
activate_window(task->win);
} else {
task_handle_mouse_event(task, action);
}
} else {
task_handle_mouse_event(task, action);
}
}
} else {
task_handle_mouse_event(click_task(panel, e->xbutton.x, e->xbutton.y), action);
}
// to keep window below
if (panel_layer == BOTTOM_LAYER)
XLowerWindow(server.display, panel->main_win);
}

12
src/mouse_actions.h Normal file
View file

@ -0,0 +1,12 @@
#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

View file

@ -18,11 +18,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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/Xrender.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "server.h" #include "server.h"
@ -118,6 +120,118 @@ void server_init_atoms()
server.atom.TARGETS = XInternAtom(server.display, "TARGETS", False); 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() void cleanup_server()
{ {
if (server.colormap) if (server.colormap)
@ -597,3 +711,25 @@ void server_init_visual()
server.visual = DefaultVisual(server.display, server.screen); 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);
}

View file

@ -93,6 +93,30 @@ typedef struct Global_atom {
Atom TARGETS; Atom TARGETS;
} Global_atom; } 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 { typedef struct Monitor {
int x; int x;
int y; int y;
@ -135,6 +159,8 @@ typedef struct Server {
Colormap colormap; Colormap colormap;
Colormap colormap32; Colormap colormap32;
Global_atom atom; Global_atom atom;
int xdamage_event_type;
int xdamage_event_error_type;
#ifdef HAVE_SN #ifdef HAVE_SN
SnDisplay *sn_display; SnDisplay *sn_display;
GTree *pids; GTree *pids;
@ -153,6 +179,7 @@ Atom server_get_atom(char *atom_name);
void server_catch_error(Display *d, XErrorEvent *ev); void server_catch_error(Display *d, XErrorEvent *ev);
void server_init_atoms(); void server_init_atoms();
void server_init_visual(); void server_init_visual();
void server_init_xdamage();
// detect root background // detect root background
void get_root_pixmap(); void get_root_pixmap();
@ -167,4 +194,7 @@ GSList *get_desktop_names();
int get_current_desktop(); int get_current_desktop();
void change_desktop(int desktop); void change_desktop(int desktop);
// Forward mouse click to the desktop window
void forward_click(XEvent *e);
#endif #endif

View file

@ -478,7 +478,7 @@ void start_net()
XSendEvent(server.display, server.root_win, False, StructureNotifyMask, (XEvent *)&ev); XSendEvent(server.display, server.root_win, False, StructureNotifyMask, (XEvent *)&ev);
} }
void net_message(XClientMessageEvent *e) void handle_systray_event(XClientMessageEvent *e)
{ {
if (systray_profile) if (systray_profile)
fprintf(stderr, "[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__); fprintf(stderr, "[%f] %s:%d\n", profiling_get_time(), __FUNCTION__, __LINE__);

View file

@ -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 // many tray icon doesn't manage stop/restart of the systray manager
void start_net(); void start_net();
void stop_net(); void stop_net();
void net_message(XClientMessageEvent *e); void handle_systray_event(XClientMessageEvent *e);
gboolean add_icon(Window id); gboolean add_icon(Window id);
gboolean reparent_icon(TrayWindow *traywin); gboolean reparent_icon(TrayWindow *traywin);

View file

@ -719,3 +719,66 @@ void del_urgent(Task *task)
urgent_timeout = NULL; 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);
}
}
}

View file

@ -10,6 +10,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <pango/pangocairo.h> #include <pango/pangocairo.h>
#include <Imlib2.h> #include <Imlib2.h>
#include "common.h" #include "common.h"
#include "timer.h" #include "timer.h"
@ -88,6 +89,7 @@ void task_update_icon(Task *task);
gboolean task_update_title(Task *task); gboolean task_update_title(Task *task);
void reset_active_task(); void reset_active_task();
void set_task_state(Task *task, TaskState state); 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), // 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. // returns a pointer to the Task for the active window on the same taskbar.

1041
src/tint.c

File diff suppressed because it is too large Load diff

View file

@ -630,7 +630,7 @@ void free_area(Area *a)
free_area_gradient_instances(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) if (mouse_over_area == area && !area)
return; return;

View file

@ -357,7 +357,7 @@ void free_area_gradient_instances(Area *area);
void area_dump_geometry(Area *area, int indent); 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 mouse_out();
void update_gradient(GradientInstance *gi); void update_gradient(GradientInstance *gi);

View file

@ -225,3 +225,7 @@ src/tint2rc.c
src/tint2rc.h src/tint2rc.h
src/button/button.c src/button/button.c
src/button/button.h src/button/button.h
src/drag_and_drop.c
src/drag_and_drop.h
src/mouse_actions.c
src/mouse_actions.h