Newer
Older
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; You may only use version 2 of the License,
you have no option to use any other version.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
oroborus - (c) 2001 Ken Lynch
xfwm4 - (c) 2002 Olivier Fourdan
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "main.h"
#include "workspaces.h"
#include "settings.h"
#include "frame.h"
#include "client.h"
#include "menu.h"
#include "gtktoxevent.h"
#include "debug.h"
static guint raise_timeout = 0;
static gulong button_handler_id = 0;
static GdkAtom atom_rcfiles = GDK_NONE;
Olivier Fourdan
committed
static void menu_callback(Menu * menu, MenuOp op, Window client_xwindow, gpointer menu_data, gpointer item_data);
static gboolean show_popup_cb(GtkWidget * widget, GdkEventButton * ev, gpointer data);
static gboolean client_event_cb(GtkWidget * widget, GdkEventClient * ev);
Olivier Fourdan
committed
XFWM_BUTTON_UNDEFINED = 0,
Olivier Fourdan
committed
XFWM_BUTTON_CLICK_AND_DRAG = 3,
XFWM_BUTTON_DOUBLE_CLICK = 4
} XfwmButtonClickType;
Olivier Fourdan
committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
static inline XfwmButtonClickType typeOfClick(Window w, XEvent * ev)
{
int xcurrent, ycurrent, x, y, total = 0;
int g = GrabSuccess;
int clicks = 1;
Time t0;
g_return_val_if_fail(ev != NULL, XFWM_BUTTON_UNDEFINED);
g_return_val_if_fail(w != None, XFWM_BUTTON_UNDEFINED);
g = XGrabPointer(dpy, w, False, ButtonMotionMask | PointerMotionMask | PointerMotionHintMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, ev->xbutton.time);
if (g != GrabSuccess)
{
DBG("grab failed in typeOfClick\n");
gdk_beep();
return XFWM_BUTTON_UNDEFINED;
}
x = xcurrent = ev->xbutton.x_root;
y = ycurrent = ev->xbutton.y_root;
t0 = CurrentTime;
while ((ABS(x - xcurrent) < 1) && (ABS(y - ycurrent) < 1) && (total < 250) && ((CurrentTime - t0) < 250))
{
g_usleep (10);
total += 10;
if (XCheckMaskEvent (dpy, ButtonReleaseMask | ButtonPressMask, ev))
{
clicks++;
}
if (XCheckMaskEvent (dpy, ButtonMotionMask | PointerMotionMask | PointerMotionHintMask, ev))
{
xcurrent = ev->xmotion.x_root;
ycurrent = ev->xmotion.y_root;
}
if ((XfwmButtonClickType) clicks == XFWM_BUTTON_DOUBLE_CLICK)
{
break;
}
}
XUngrabPointer(dpy, ev->xbutton.time);
return (XfwmButtonClickType) clicks;
}
Olivier Fourdan
committed
static void clear_timeout(void)
Olivier Fourdan
committed
if(raise_timeout)
Olivier Fourdan
committed
gtk_timeout_remove(raise_timeout);
raise_timeout = 0;
Olivier Fourdan
committed
static gboolean raise_cb(gpointer data)
Olivier Fourdan
committed
clear_timeout();
c = clientGetFocus();
if(c)
{
clientRaise(c);
}
return (TRUE);
}
Olivier Fourdan
committed
static void reset_timeout(void)
Olivier Fourdan
committed
if(raise_timeout)
Olivier Fourdan
committed
gtk_timeout_remove(raise_timeout);
Olivier Fourdan
committed
raise_timeout = gtk_timeout_add(raise_delay, (GtkFunction) raise_cb, NULL);
static inline void handleKeyPress(XKeyEvent * ev)
{
Client *c;
int state, key;
XEvent e;
DBG("entering handleKeyEvent\n");
c = clientGetFocus();
state = ev->state & (ShiftMask | ControlMask | AltMask | MetaMask);
for(key = 0; key < KEY_COUNT; key++)
{
if((keys[key].keycode == ev->keycode) && (keys[key].modifier == state))
Olivier Fourdan
committed
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
if(c)
{
switch (key)
{
case KEY_MOVE_UP:
case KEY_MOVE_DOWN:
case KEY_MOVE_LEFT:
case KEY_MOVE_RIGHT:
Olivier Fourdan
committed
if((c->has_border) && !(c->fullscreen))
{
Olivier Fourdan
committed
clientMove(c, (XEvent *) ev);
Olivier Fourdan
committed
}
break;
case KEY_RESIZE_UP:
case KEY_RESIZE_DOWN:
case KEY_RESIZE_LEFT:
case KEY_RESIZE_RIGHT:
Olivier Fourdan
committed
clientResize(c, CORNER_BOTTOM_RIGHT, (XEvent *) ev);
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
break;
case KEY_CYCLE_WINDOWS:
clientCycle(c);
break;
case KEY_CLOSE_WINDOW:
clientClose(c);
break;
case KEY_HIDE_WINDOW:
clientHide(c, True);
break;
case KEY_MAXIMIZE_WINDOW:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED);
break;
case KEY_MAXIMIZE_VERT:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED_VERT);
break;
case KEY_MAXIMIZE_HORIZ:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED_HORIZ);
break;
case KEY_SHADE_WINDOW:
clientToggleShaded(c);
break;
case KEY_RAISE_WINDOW_LAYER:
clientSetLayer(c, c->win_layer + 1);
break;
case KEY_LOWER_WINDOW_LAYER:
clientSetLayer(c, c->win_layer - 1);
break;
case KEY_NEXT_WORKSPACE:
workspaceSwitch(workspace + 1, NULL);
break;
case KEY_PREV_WORKSPACE:
workspaceSwitch(workspace - 1, NULL);
break;
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
case KEY_ADD_WORKSPACE:
workspaceSetCount(workspace_count + 1);
break;
case KEY_DEL_WORKSPACE:
workspaceSetCount(workspace_count - 1);
break;
case KEY_STICK_WINDOW:
clientToggleSticky(c);
break;
case KEY_WORKSPACE_1:
workspaceSwitch(0, NULL);
break;
case KEY_WORKSPACE_2:
workspaceSwitch(1, NULL);
break;
case KEY_WORKSPACE_3:
workspaceSwitch(2, NULL);
break;
case KEY_WORKSPACE_4:
workspaceSwitch(3, NULL);
break;
case KEY_WORKSPACE_5:
workspaceSwitch(4, NULL);
break;
case KEY_WORKSPACE_6:
workspaceSwitch(5, NULL);
break;
case KEY_WORKSPACE_7:
workspaceSwitch(6, NULL);
break;
case KEY_WORKSPACE_8:
workspaceSwitch(7, NULL);
break;
case KEY_WORKSPACE_9:
workspaceSwitch(8, NULL);
break;
case KEY_MOVE_NEXT_WORKSPACE:
workspaceSwitch(workspace + 1, c);
break;
case KEY_MOVE_PREV_WORKSPACE:
workspaceSwitch(workspace - 1, c);
break;
case KEY_MOVE_WORKSPACE_1:
workspaceSwitch(0, c);
break;
case KEY_MOVE_WORKSPACE_2:
workspaceSwitch(1, c);
break;
case KEY_MOVE_WORKSPACE_3:
workspaceSwitch(2, c);
break;
case KEY_MOVE_WORKSPACE_4:
workspaceSwitch(3, c);
break;
case KEY_MOVE_WORKSPACE_5:
workspaceSwitch(4, c);
break;
case KEY_MOVE_WORKSPACE_6:
workspaceSwitch(5, c);
break;
case KEY_MOVE_WORKSPACE_7:
workspaceSwitch(6, c);
break;
case KEY_MOVE_WORKSPACE_8:
workspaceSwitch(7, c);
break;
case KEY_MOVE_WORKSPACE_9:
workspaceSwitch(8, c);
break;
}
}
else
{
switch (key)
{
case KEY_CYCLE_WINDOWS:
Olivier Fourdan
committed
if(clients)
{
Olivier Fourdan
committed
}
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
break;
case KEY_NEXT_WORKSPACE:
workspaceSwitch(workspace + 1, NULL);
break;
case KEY_PREV_WORKSPACE:
workspaceSwitch(workspace - 1, NULL);
break;
case KEY_ADD_WORKSPACE:
workspaceSetCount(workspace_count + 1);
break;
case KEY_DEL_WORKSPACE:
workspaceSetCount(workspace_count - 1);
break;
case KEY_WORKSPACE_1:
workspaceSwitch(0, NULL);
break;
case KEY_WORKSPACE_2:
workspaceSwitch(1, NULL);
break;
case KEY_WORKSPACE_3:
workspaceSwitch(2, NULL);
break;
case KEY_WORKSPACE_4:
workspaceSwitch(3, NULL);
break;
case KEY_WORKSPACE_5:
workspaceSwitch(4, NULL);
break;
case KEY_WORKSPACE_6:
workspaceSwitch(5, NULL);
break;
case KEY_WORKSPACE_7:
workspaceSwitch(6, NULL);
break;
case KEY_WORKSPACE_8:
workspaceSwitch(7, NULL);
break;
case KEY_WORKSPACE_9:
workspaceSwitch(8, NULL);
break;
}
}
while(XCheckTypedEvent(dpy, EnterNotify, &e));
}
static inline void handleButtonPress(XButtonEvent * ev)
{
Client *c;
Window win;
int state, replay = False;
DBG("entering handleButtonPress\n");
/* Clear timeout */
Olivier Fourdan
committed
clear_timeout();
Olivier Fourdan
committed
c = clientGetFromWindow(ev->window, ANY);
state = ev->state & (ShiftMask | ControlMask | AltMask | MetaMask);
win = ev->subwindow;
if((win == c->buttons[HIDE_BUTTON]) || (win == c->buttons[CLOSE_BUTTON]) || (win == c->buttons[MAXIMIZE_BUTTON]) || (win == c->buttons[SHADE_BUTTON]) || (win == c->buttons[STICK_BUTTON]))
Olivier Fourdan
committed
clientSetFocus(c, True);
clientRaise(c);
clientButtonPress(c, win, ev);
}
else if(((win == c->title) && (ev->button == Button3)) || ((win == c->buttons[MENU_BUTTON]) && (ev->button == Button1)))
{
/*
We need to copy the event to keep the original event untouched
for gtk to handle it (in case we open up the menu)
*/
XEvent copy_event = (XEvent) *ev;
XfwmButtonClickType tclick;
Olivier Fourdan
committed
if ((win == c->buttons[MENU_BUTTON]) && ((tclick = typeOfClick(c->frame, ©_event)) && (tclick == XFWM_BUTTON_DOUBLE_CLICK)))
{
clientClose(c);
}
else
{
clientSetFocus(c, True);
clientRaise(c);
ev->window = ev->root;
if(button_handler_id)
{
Olivier Fourdan
committed
g_signal_handler_disconnect(GTK_OBJECT(getDefaultGtkWidget()), button_handler_id);
}
button_handler_id = g_signal_connect(GTK_OBJECT(getDefaultGtkWidget()), "button_press_event", GTK_SIGNAL_FUNC(show_popup_cb), (gpointer) c);
/* Let GTK handle this for us. */
}
else if(((win == c->title) && ((ev->button == Button1) && (state == 0))) || ((ev->button == Button1) && (state == AltMask)))
Olivier Fourdan
committed
XEvent copy_event = (XEvent) *ev;
if (win == c->title)
{
clientSetFocus(c, True);
Olivier Fourdan
committed
clientRaise(c);
}
Olivier Fourdan
committed
tclick = typeOfClick(c->frame, ©_event);
Olivier Fourdan
committed
if((tclick == XFWM_BUTTON_DRAG) || (tclick == XFWM_BUTTON_CLICK_AND_DRAG))
{
if((c->has_border) && !(c->fullscreen))
{
Olivier Fourdan
committed
clientMove(c, (XEvent *) ev);
{
switch (double_click_action)
{
case ACTION_MAXIMIZE:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED);
break;
case ACTION_SHADE:
clientToggleShaded(c);
break;
case ACTION_HIDE:
clientHide(c, True);
break;
}
}
}
else if((win == c->corners[CORNER_TOP_LEFT]) && (ev->button == Button1) && (state == 0))
{
Olivier Fourdan
committed
clientSetFocus(c, True);
Olivier Fourdan
committed
clientResize(c, CORNER_TOP_LEFT, (XEvent *) ev);
}
else if((win == c->corners[CORNER_TOP_RIGHT]) && (ev->button == Button1) && (state == 0))
{
Olivier Fourdan
committed
clientSetFocus(c, True);
Olivier Fourdan
committed
clientResize(c, CORNER_TOP_RIGHT, (XEvent *) ev);
}
else if((win == c->corners[CORNER_BOTTOM_LEFT]) && (ev->button == Button1) && (state == 0))
{
Olivier Fourdan
committed
clientSetFocus(c, True);
Olivier Fourdan
committed
clientResize(c, CORNER_BOTTOM_LEFT, (XEvent *) ev);
}
else if((win == c->corners[CORNER_BOTTOM_RIGHT]) && (ev->button == Button1) && (state == 0))
{
Olivier Fourdan
committed
clientSetFocus(c, True);
Olivier Fourdan
committed
clientResize(c, CORNER_BOTTOM_RIGHT, (XEvent *) ev);
}
else if((win == c->sides[SIDE_BOTTOM]) && (ev->button == Button1) && (state == 0))
{
Olivier Fourdan
committed
clientSetFocus(c, True);
Olivier Fourdan
committed
clientResize(c, 4 + SIDE_BOTTOM, (XEvent *) ev);
}
else if((win == c->sides[SIDE_LEFT]) && (ev->button == Button1) && (state == 0))
{
Olivier Fourdan
committed
clientSetFocus(c, True);
Olivier Fourdan
committed
clientResize(c, 4 + SIDE_LEFT, (XEvent *) ev);
}
else if((win == c->sides[SIDE_RIGHT]) && (ev->button == Button1) && (state == 0))
{
Olivier Fourdan
committed
clientSetFocus(c, True);
Olivier Fourdan
committed
clientResize(c, 4 + SIDE_RIGHT, (XEvent *) ev);
else if(((ev->window != c->window) && (ev->button == Button2) && (state == 0)) || ((ev->button == Button2) && (state == (AltMask | ControlMask))))
Olivier Fourdan
committed
clientLower(c);
Olivier Fourdan
committed
else
if (ev->button == Button1)
{
clientSetFocus(c, True);
clientRaise(c);
Olivier Fourdan
committed
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
{
Olivier Fourdan
committed
XAllowEvents(dpy, ReplayPointer, ev->time);
Olivier Fourdan
committed
else
XAllowEvents(dpy, SyncPointer, ev->time);
}
}
else
{
XUngrabPointer(dpy, CurrentTime);
XSendEvent(dpy, gnome_win, False, SubstructureNotifyMask, (XEvent *) ev);
}
}
static inline void handleButtonRelease(XButtonEvent * ev)
{
DBG("entering handleButtonRelease\n");
XSendEvent(dpy, gnome_win, False, SubstructureNotifyMask, (XEvent *) ev);
}
static inline void handleDestroyNotify(XDestroyWindowEvent * ev)
{
Client *c;
DBG("entering handleDestroyNotify\n");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
Olivier Fourdan
committed
{
clientSetFocus(clientGetNext(clients->prev, 0), True);
}
Olivier Fourdan
committed
else
Olivier Fourdan
committed
clientSetFocus(NULL, True);
}
static inline void handleUnmapNotify(XUnmapEvent * ev)
{
Client *c;
DBG("entering handleUnmapNotify\n");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
if(c->ignore_unmap)
Olivier Fourdan
committed
{
Olivier Fourdan
committed
else
Olivier Fourdan
committed
{
clientSetFocus(clientGetNext(clients->prev, 0), True);
}
Olivier Fourdan
committed
else
{
Olivier Fourdan
committed
}
static inline void handleMapRequest(XMapRequestEvent * ev)
{
Client *c;
DBG("entering handleMapRequest\n");
Olivier Fourdan
committed
if(ev->window == None)
{
DBG("Mapping None ???\n");
return;
}
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
clientShow(c, True);
}
else
{
clientFrame(ev->window);
}
}
static inline void handleConfigureRequest(XConfigureRequestEvent * ev)
{
Client *c;
XWindowChanges wc;
DBG("entering handleConfigureRequest\n");
wc.x = ev->x;
wc.y = ev->y;
wc.width = ev->width;
wc.height = ev->height;
wc.sibling = ev->above;
wc.stack_mode = ev->detail;
wc.border_width = ev->border_width;
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
Olivier Fourdan
committed
if(c->type == WINDOW_DESKTOP)
{
/* Ignore stacking request for DESKTOP windows */
wc.stack_mode &= ~CWStackMode;
}
clientCoordGravitate(c, APPLY, &wc.x, &wc.y);
if ((ev->value_mask & (CWX | CWY | CWWidth | CWHeight)) && c->maximized)
{
clientRemoveMaximizeFlag(c);
}
clientConfigure(c, &wc, ev->value_mask);
}
else
{
XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
}
}
static inline void handleEnterNotify(XCrossingEvent * ev)
{
Client *c;
DBG("entering handleEnterNotify\n");
while(XCheckTypedEvent(dpy, EnterNotify, (XEvent *) ev));
DBG("EnterNotify window is (%#lx)\n", ev->window);
c = clientGetFromWindow(ev->window, FRAME);
Olivier Fourdan
committed
if(c && !(click_to_focus) && (clientAcceptFocus(c)))
{
DBG("EnterNotify window is \"%s\"\n", c->name);
if((c->type != WINDOW_DOCK) && (c->type != WINDOW_DESKTOP))
{
clientSetFocus(c, True);
static inline void handleFocusIn(XFocusChangeEvent * ev)
{
Client *c;
DBG("entering handleFocusIn\n");
DBG("FocusIn window is (%#lx)\n", ev->window);
Olivier Fourdan
committed
if(ev->window == gnome_win)
{
/* Don't get fooled by our own gtk window ! */
return;
}
Olivier Fourdan
committed
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
DBG("focus set to \"%s\" (%#lx)\n", c->name, c->window);
clientUpdateFocus(c);
frameDraw(c);
Olivier Fourdan
committed
{
reset_timeout();
}
}
else if(clients)
{
DBG("focus set to top window in list\n");
clientSetFocus(clientGetNext(clients->prev, 0), True);
}
else
{
DBG("focus set to default fallback window\n");
clientSetFocus(NULL, True);
}
}
static inline void handleFocusOut(XFocusChangeEvent * ev)
static inline void handlePropertyNotify(XPropertyEvent * ev)
{
Client *c;
long dummy;
DBG("entering handlePropertyNotify\n");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
if(ev->atom == XA_WM_NORMAL_HINTS)
{
DBG("client \"%s\" (%#lx) has received a XA_WM_NORMAL_HINTS notify\n", c->name, c->window);
Olivier Fourdan
committed
XGetWMNormalHints(dpy, c->window, c->size, &dummy);
Olivier Fourdan
committed
else if((ev->atom == XA_WM_NAME) || (ev->atom == net_wm_name))
{
DBG("client \"%s\" (%#lx) has received a XA_WM_NAME notify\n", c->name, c->window);
if(c->name)
Olivier Fourdan
committed
{
Olivier Fourdan
committed
getWindowName(dpy, c->window, &c->name);
frameDraw(c);
}
else if(ev->atom == win_hints)
{
DBG("client \"%s\" (%#lx) has received a win_hints notify\n", c->name, c->window);
Olivier Fourdan
committed
getGnomeHint(dpy, c->window, win_hints, &c->win_hints);
Olivier Fourdan
committed
else if(ev->atom == win_layer)
{
DBG("client \"%s\" (%#lx) has received a win_layer notify\n", c->name, c->window);
getGnomeHint(dpy, c->window, win_layer, &dummy);
clientSetLayer(c, dummy);
Olivier Fourdan
committed
clientSetNetState(c);
Olivier Fourdan
committed
else if(ev->atom == net_wm_window_type)
{
DBG("client \"%s\" (%#lx) has received a net_wm_window_type notify\n", c->name, c->window);
Olivier Fourdan
committed
clientGetNetWmType(c);
else if((ev->atom == win_workspace) && !(c->transient_for))
{
DBG("client \"%s\" (%#lx) has received a win_workspace notify\n", c->name, c->window);
getGnomeHint(dpy, c->window, win_workspace, &dummy);
clientSetWorkspace(c, dummy, TRUE);
Olivier Fourdan
committed
else if(ev->atom == net_wm_strut)
{
DBG("client \"%s\" (%#lx) has received a net_wm_strut notify\n", c->name, c->window);
Olivier Fourdan
committed
clientGetNetStruts(c);
Olivier Fourdan
committed
else if(ev->atom == wm_colormap_windows)
{
clientUpdateColormaps(c);
if(c == clientGetFocus())
{
clientInstallColormaps(c);
Olivier Fourdan
committed
}
}
}
else
{
if(ev->atom == win_workspace_count)
{
DBG("root has received a win_workspace_count notify\n");
getGnomeHint(dpy, root, win_workspace_count, &dummy);
workspaceSetCount(dummy);
}
else if(ev->atom == gnome_panel_desktop_area)
{
DBG("root has received a gnome_panel_desktop_area notify\n");
Olivier Fourdan
committed
getGnomeDesktopMargins(dpy, gnome_margins);
workspaceUpdateArea(margins, gnome_margins);
Olivier Fourdan
committed
}
static inline void handleClientMessage(XClientMessageEvent * ev)
{
Client *c;
DBG("entering handleClientMessage\n");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
if((ev->message_type == wm_change_state) && (ev->format == 32) && (ev->data.l[0] == IconicState))
Olivier Fourdan
committed
{
DBG("client \"%s\" (%#lx) has received a wm_change_state event\n", c->name, c->window);
clientHide(c, True);
}
else if((ev->message_type == win_state) && (ev->format == 32) && (ev->data.l[0] & WIN_STATE_SHADED))
Olivier Fourdan
committed
{
DBG("client \"%s\" (%#lx) has received a win_state/shaded event\n", c->name, c->window);
clientToggleShaded(c);
}
Olivier Fourdan
committed
else if((ev->message_type == win_state) && (ev->format == 32) && (ev->data.l[0] & WIN_STATE_STICKY))
{
DBG("client \"%s\" (%#lx) has received a win_state/stick event\n", c->name, c->window);
Olivier Fourdan
committed
clientToggleSticky(c);
Olivier Fourdan
committed
else if((ev->message_type == win_layer) && (ev->format == 32))
{
DBG("client \"%s\" (%#lx) has received a win_layer event\n", c->name, c->window);
clientSetLayer(c, ev->data.l[0]);
}
else if((ev->message_type == win_workspace) && (ev->format == 32) && !(c->transient_for))
Olivier Fourdan
committed
{
DBG("client \"%s\" (%#lx) has received a win_workspace event\n", c->name, c->window);
clientSetWorkspace(c, ev->data.l[0], TRUE);
Olivier Fourdan
committed
}
else if((ev->message_type == net_wm_desktop) && (ev->format == 32))
{
DBG("client \"%s\" (%#lx) has received a net_wm_desktop event\n", c->name, c->window);
Olivier Fourdan
committed
if((ev->data.l[0] == (int)0xFFFFFFFF))
{
clientStick(c);
}
else if (!(c->transient_for))
Olivier Fourdan
committed
{
clientSetWorkspace(c, ev->data.l[0], TRUE);
Olivier Fourdan
committed
}
}
else if((ev->message_type == net_close_window) && (ev->format == 32))
Olivier Fourdan
committed
{
DBG("client \"%s\" (%#lx) has received a net_close_window event\n", c->name, c->window);
Olivier Fourdan
committed
clientClose(c);
}
else if((ev->message_type == net_wm_state) && (ev->format == 32))
{
DBG("client \"%s\" (%#lx) has received a net_wm_state event\n", c->name, c->window);
Olivier Fourdan
committed
clientUpdateNetState(c, ev);
}
else if((ev->message_type == net_wm_moveresize) && (ev->format == 32))
{
DBG("client \"%s\" (%#lx) has received a net_wm_moveresize event\n", c->name, c->window);
Olivier Fourdan
committed
g_message("Operation not supported (yet)\n");
/* TBD */
}
else if((ev->message_type == net_active_window) && (ev->format == 32))
{
DBG("client \"%s\" (%#lx) has received a net_active_window event\n", c->name, c->window);
Olivier Fourdan
committed
workspaceSwitch(c->win_workspace, NULL);
clientShow(c, True);
clientRaise(c);
clientSetFocus(c, True);
}
}
else
{
if(((ev->message_type == win_workspace) || (ev->message_type == net_current_desktop)) && (ev->format == 32))
Olivier Fourdan
committed
{
DBG("root has received a win_workspace or a net_current_desktop event\n");
workspaceSwitch(ev->data.l[0], NULL);
}
Olivier Fourdan
committed
else if(((ev->message_type == win_workspace_count) || (ev->message_type == net_number_of_desktops)) && (ev->format == 32))
{
DBG("root has received a win_workspace_count event\n");
workspaceSetCount(ev->data.l[0]);
Olivier Fourdan
committed
}
static inline void handleShape(XShapeEvent * ev)
{
Client *c;
DBG("entering handleShape\n");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
frameDraw(c);
}
}
Olivier Fourdan
committed
static inline void handleColormapNotify(XColormapEvent * ev)
Olivier Fourdan
committed
DBG("entering handleColormapNotify\n");
Olivier Fourdan
committed
c = clientGetFromWindow(ev->window, WINDOW);
Olivier Fourdan
committed
if((c) && (ev->window == c->window) && (ev->new))
Olivier Fourdan
committed
if(c == clientGetFocus())
{
clientInstallColormaps(c);
}
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
void handleEvent(XEvent * ev)
{
DBG("entering handleEvent\n");
switch (ev->type)
{
case KeyPress:
handleKeyPress((XKeyEvent *) ev);
break;
case ButtonPress:
handleButtonPress((XButtonEvent *) ev);
break;
case ButtonRelease:
handleButtonRelease((XButtonEvent *) ev);
break;
case DestroyNotify:
handleDestroyNotify((XDestroyWindowEvent *) ev);
break;
case UnmapNotify:
handleUnmapNotify((XUnmapEvent *) ev);
break;
case MapRequest:
handleMapRequest((XMapRequestEvent *) ev);
break;
case ConfigureRequest:
handleConfigureRequest((XConfigureRequestEvent *) ev);
break;
case EnterNotify:
handleEnterNotify((XCrossingEvent *) ev);
break;
case FocusIn:
handleFocusIn((XFocusChangeEvent *) ev);
break;
case FocusOut:
handleFocusOut((XFocusChangeEvent *) ev);
break;
case PropertyNotify:
handlePropertyNotify((XPropertyEvent *) ev);
break;
case ClientMessage:
handleClientMessage((XClientMessageEvent *) ev);
break;
case ColormapNotify:
handleColormapNotify((XColormapEvent *) ev);
break;
Olivier Fourdan
committed
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
if(!gdk_events_pending() && !XPending(dpy))
Olivier Fourdan
committed
if(reload)
{
Olivier Fourdan
committed
}
else if(quit)
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
GtkToXEventFilterStatus xfwm4_event_filter(XEvent * xevent, gpointer data)
{
DBG("entering xfwm4_event_filter\n");
handleEvent(xevent);
DBG("leaving xfwm4_event_filter\n");
return XEV_FILTER_STOP;
}
/* GTK stuff (menu, etc...) */
Olivier Fourdan
committed
static void menu_callback(Menu * menu, MenuOp op, Window client_xwindow, gpointer menu_data, gpointer item_data)
Olivier Fourdan
committed
if (menu_event_window)
{
removeTmpEventWin (menu_event_window);
menu_event_window = None;
}
Olivier Fourdan
committed
if(menu_data)
Olivier Fourdan
committed
c = (Client *) menu_data;
c = clientGetFromWindow(c->window, WINDOW);
if(c)
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
Olivier Fourdan
committed
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
case MENU_OP_QUIT:
gtk_main_quit();
break;
case MENU_OP_MAXIMIZE:
case MENU_OP_UNMAXIMIZE:
if(c)
{
clientToggleMaximized(c, WIN_STATE_MAXIMIZED);
}
break;
case MENU_OP_MINIMIZE:
if(c)
{
clientHide(c, True);
}
break;
case MENU_OP_MINIMIZE_ALL:
clientHideAll(c);
break;
case MENU_OP_UNMINIMIZE:
if(c)
{
clientShow(c, True);
}
break;
case MENU_OP_SHADE:
case MENU_OP_UNSHADE:
if(c)
{
clientToggleShaded(c);
}
break;
case MENU_OP_STICK:
case MENU_OP_UNSTICK:
if(c)
{
clientToggleSticky(c);
frameDraw(c);
}
break;
case MENU_OP_DELETE:
if(c)
{
clientClose(c);
frameDraw(c);
}
break;
case MENU_OP_DESTROY:
if(c)
{
clientKill(c);
frameDraw(c);
}
break;
default:
if(c)
{
frameDraw(c);
}
break;
}
menu_free(menu);
Olivier Fourdan
committed
static gboolean show_popup_cb(GtkWidget * widget, GdkEventButton * ev, gpointer data)
Olivier Fourdan
committed
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
Menu *menu;
MenuOp ops;
MenuOp insensitive;
Client *c = NULL;
gint x = ev->x_root;
gint y = ev->y_root;
DBG("entering show_popup_cb\n");
if(((ev->button == 1) || (ev->button == 3)) && (c = (Client *) data))
{
c->button_pressed[MENU_BUTTON] = True;
frameDraw(c);
y = c->y;
ops = MENU_OP_DELETE | MENU_OP_DESTROY | MENU_OP_MINIMIZE_ALL;
insensitive = 0;
if(c->win_state & (WIN_STATE_MAXIMIZED | WIN_STATE_MAXIMIZED_HORIZ | WIN_STATE_MAXIMIZED_VERT))
{
ops |= MENU_OP_UNMAXIMIZE;
}
else
{
ops |= MENU_OP_MAXIMIZE;
}
Olivier Fourdan
committed
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
{
ops |= MENU_OP_UNMINIMIZE;
}
else
{
ops |= MENU_OP_MINIMIZE;
}
if(c->win_state & WIN_STATE_SHADED)
{
ops |= MENU_OP_UNSHADE;
}
else
{
ops |= MENU_OP_SHADE;
}
if(c->sticky)
{
ops |= MENU_OP_UNSTICK;
}
else
{
ops |= MENU_OP_STICK;
}
}
else
{
return (TRUE);
}
if(button_handler_id)
{
g_signal_handler_disconnect(GTK_OBJECT(getDefaultGtkWidget()), button_handler_id);
}
button_handler_id = g_signal_connect(GTK_OBJECT(getDefaultGtkWidget()), "button_press_event", GTK_SIGNAL_FUNC(show_popup_cb), (gpointer) NULL);
if (menu_event_window)
{
removeTmpEventWin (menu_event_window);
menu_event_window = None;
}
menu_event_window = setTmpEventWin(NoEventMask);
Olivier Fourdan
committed
menu = menu_default(ops, insensitive, menu_callback, c);
if(!menu_popup(menu, x, y, ev->button, ev->time))
Olivier Fourdan
committed
{
DBG("Cannot open menu\n");
gdk_beep();
c->button_pressed[MENU_BUTTON] = False;
Olivier Fourdan
committed
frameDraw(c);
removeTmpEventWin (menu_event_window);
menu_event_window = None;
Olivier Fourdan
committed
menu_free(menu);
}
Olivier Fourdan
committed
return (TRUE);
static gboolean set_reload(void)
{
DBG("setting reload flag so all prefs will be reread at next event loop\n");
reload = True;
return (TRUE);
}
Olivier Fourdan
committed
static gboolean client_event_cb(GtkWidget * widget, GdkEventClient * ev)
Olivier Fourdan
committed
DBG("entering client_event_cb\n");
if(!atom_rcfiles)
{
atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
}
if(ev->message_type == atom_rcfiles)
{
Olivier Fourdan
committed
}
return (FALSE);
Olivier Fourdan
committed
void initGtkCallbacks(void)
Olivier Fourdan
committed
Olivier Fourdan
committed
button_handler_id = g_signal_connect(GTK_OBJECT(getDefaultGtkWidget()), "button_press_event", GTK_SIGNAL_FUNC(show_popup_cb), (gpointer) NULL);
Olivier Fourdan
committed
g_signal_connect(GTK_OBJECT(getDefaultGtkWidget()), "client_event", GTK_SIGNAL_FUNC(client_event_cb), (gpointer) NULL);
settings = gtk_settings_get_default();
Olivier Fourdan
committed
if(settings)
Olivier Fourdan
committed
g_signal_connect(settings, "notify::gtk-theme-name", G_CALLBACK(set_reload), NULL);
g_signal_connect(settings, "notify::gtk-font-name", G_CALLBACK(set_reload), NULL);