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.
Olivier Fourdan
committed
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.
Olivier Fourdan
committed
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.
Olivier Fourdan
committed
xfwm4 - (c) 2002-2003 Olivier Fourdan
Olivier Fourdan
committed
#include <config.h>
#include <X11/Xatom.h>
#include <libxfce4util/debug.h>
#include <libxfce4util/i18n.h>
#include <libxfcegui4/libxfcegui4.h>
#include "hints.h"
#include "frame.h"
#include "client.h"
#include "menu.h"
#include "startup_notification.h"
Olivier Fourdan
committed
#define WIN_IS_BUTTON(win) ((win == MYWINDOW_XWINDOW(c->buttons[HIDE_BUTTON])) || \
(win == MYWINDOW_XWINDOW(c->buttons[CLOSE_BUTTON])) || \
(win == MYWINDOW_XWINDOW(c->buttons[MAXIMIZE_BUTTON])) || \
(win == MYWINDOW_XWINDOW(c->buttons[SHADE_BUTTON])) || \
(win == MYWINDOW_XWINDOW(c->buttons[STICK_BUTTON])))
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,
XFWM_BUTTON_DRAG = 1,
XFWM_BUTTON_CLICK = 2,
XFWM_BUTTON_CLICK_AND_DRAG = 3,
XFWM_BUTTON_DOUBLE_CLICK = 4
}
XfwmButtonClickType;
static inline XfwmButtonClickType typeOfClick(Window w, XEvent * ev, gboolean allow_double_click)
Olivier Fourdan
committed
{
Olivier Fourdan
committed
int xcurrent, ycurrent, x, y, total;
Olivier Fourdan
committed
int g = GrabSuccess;
Olivier Fourdan
committed
int clicks;
Time t0, t1;
Olivier Fourdan
committed
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);
Olivier Fourdan
committed
if(g != GrabSuccess)
Olivier Fourdan
committed
{
TRACE("grab failed in typeOfClick");
Olivier Fourdan
committed
gdk_beep();
return XFWM_BUTTON_UNDEFINED;
}
Olivier Fourdan
committed
Olivier Fourdan
committed
x = xcurrent = ev->xbutton.x_root;
y = ycurrent = ev->xbutton.y_root;
Olivier Fourdan
committed
t0 = ev->xbutton.time;
t1 = t0;
total = 0;
clicks = 1;
Olivier Fourdan
committed
while((ABS(x - xcurrent) < 1) && (ABS(y - ycurrent) < 1) && (total < params.dbl_click_time) && ((t1 - t0) < params.dbl_click_time))
Olivier Fourdan
committed
{
Olivier Fourdan
committed
g_usleep(10000);
Olivier Fourdan
committed
total += 10;
Olivier Fourdan
committed
if(XCheckMaskEvent(dpy, ButtonReleaseMask | ButtonPressMask, ev))
Olivier Fourdan
committed
{
Olivier Fourdan
committed
if(ev->xbutton.button == button)
{
clicks++;
}
t1 = ev->xbutton.time;
Olivier Fourdan
committed
}
Olivier Fourdan
committed
if(XCheckMaskEvent(dpy, ButtonMotionMask | PointerMotionMask | PointerMotionHintMask, ev))
Olivier Fourdan
committed
{
xcurrent = ev->xmotion.x_root;
ycurrent = ev->xmotion.y_root;
Olivier Fourdan
committed
t1 = ev->xmotion.time;
Olivier Fourdan
committed
}
if((XfwmButtonClickType) clicks == XFWM_BUTTON_DOUBLE_CLICK || (!allow_double_click && (XfwmButtonClickType) clicks == XFWM_BUTTON_CLICK))
Olivier Fourdan
committed
{
break;
}
}
XUngrabPointer(dpy, ev->xbutton.time);
return (XfwmButtonClickType) clicks;
}
Olivier Fourdan
committed
static void clear_timeout(void)
Olivier Fourdan
committed
if(raise_timeout)
g_source_remove(raise_timeout);
Olivier Fourdan
committed
raise_timeout = 0;
Olivier Fourdan
committed
static gboolean raise_cb(gpointer data)
TRACE("entering raise_cb");
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)
g_source_remove(raise_timeout);
raise_timeout = g_timeout_add_full(0, params.raise_delay, (GtkFunction) raise_cb, NULL, NULL);
static inline void moveRequest(Client * c, XEvent * ev)
if(CLIENT_FLAG_TEST_AND_NOT(c, CLIENT_FLAG_HAS_BORDER | CLIENT_FLAG_HAS_MOVE, CLIENT_FLAG_FULLSCREEN))
{
clientMove(c, ev);
}
}
static inline void resizeRequest(Client * c, int corner, XEvent * ev)
clientSetFocus(c, TRUE);
if(CLIENT_FLAG_TEST_ALL(c, CLIENT_FLAG_HAS_RESIZE | CLIENT_FLAG_IS_RESIZABLE))
Olivier Fourdan
committed
clientResize(c, corner, ev);
else if(CLIENT_FLAG_TEST_AND_NOT(c, CLIENT_FLAG_HAS_BORDER | CLIENT_FLAG_HAS_MOVE, CLIENT_FLAG_FULLSCREEN))
Olivier Fourdan
committed
clientMove(c, ev);
static inline void spawn_shortcut(int i)
{
GError *error = NULL;
if((i >= NB_KEY_SHORTCUTS) || (!params.shortcut_exec[i]) || !strlen(params.shortcut_exec[i]))
{
return;
}
if(!g_spawn_command_line_async(params.shortcut_exec[i], &error))
if(error)
{
g_warning("%s: %s", g_get_prgname(), error->message);
g_error_free(error);
}
static inline void handleKeyPress(XKeyEvent * ev)
{
Client *c;
int state, key;
XEvent e;
TRACE("entering handleKeyEvent");
state = ev->state & (ShiftMask | ControlMask | AltMask | MetaMask | SuperMask | HyperMask);
if((params.keys[key].keycode == ev->keycode) && (params.keys[key].modifier == state))
Olivier Fourdan
committed
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
Olivier Fourdan
committed
case KEY_MOVE_UP:
case KEY_MOVE_DOWN:
case KEY_MOVE_LEFT:
case KEY_MOVE_RIGHT:
moveRequest(c, (XEvent *) ev);
Olivier Fourdan
committed
case KEY_RESIZE_UP:
case KEY_RESIZE_DOWN:
case KEY_RESIZE_LEFT:
case KEY_RESIZE_RIGHT:
if(CLIENT_FLAG_TEST_ALL(c, CLIENT_FLAG_HAS_RESIZE | CLIENT_FLAG_IS_RESIZABLE))
{
clientResize(c, CORNER_BOTTOM_RIGHT, (XEvent *) ev);
}
Olivier Fourdan
committed
case KEY_CYCLE_WINDOWS:
clientCycle(c);
Olivier Fourdan
committed
case KEY_CLOSE_WINDOW:
clientClose(c);
Olivier Fourdan
committed
case KEY_HIDE_WINDOW:
clientHide(c, c->win_workspace, TRUE);
Olivier Fourdan
committed
case KEY_MAXIMIZE_WINDOW:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED);
Olivier Fourdan
committed
case KEY_MAXIMIZE_VERT:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED_VERT);
Olivier Fourdan
committed
case KEY_MAXIMIZE_HORIZ:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED_HORIZ);
Olivier Fourdan
committed
case KEY_SHADE_WINDOW:
clientToggleShaded(c);
Olivier Fourdan
committed
case KEY_STICK_WINDOW:
clientToggleSticky(c, TRUE);
Olivier Fourdan
committed
case KEY_MOVE_NEXT_WORKSPACE:
workspaceSwitch(workspace + 1, c);
Olivier Fourdan
committed
case KEY_MOVE_PREV_WORKSPACE:
workspaceSwitch(workspace - 1, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_1:
workspaceSwitch(0, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_2:
workspaceSwitch(1, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_3:
workspaceSwitch(2, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_4:
workspaceSwitch(3, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_5:
workspaceSwitch(4, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_6:
workspaceSwitch(5, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_7:
workspaceSwitch(6, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_8:
workspaceSwitch(7, c);
Olivier Fourdan
committed
case KEY_MOVE_WORKSPACE_9:
workspaceSwitch(8, c);
Olivier Fourdan
committed
default:
Olivier Fourdan
committed
}
}
else
{
switch (key)
{
case KEY_CYCLE_WINDOWS:
if(clients)
{
clientCycle(clients->prev);
}
break;
default:
Olivier Fourdan
committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
}
}
switch (key)
{
case KEY_NEXT_WORKSPACE:
workspaceSwitch(workspace + 1, NULL);
break;
case KEY_PREV_WORKSPACE:
workspaceSwitch(workspace - 1, NULL);
break;
case KEY_ADD_WORKSPACE:
workspaceSetCount(params.workspace_count + 1);
break;
case KEY_DEL_WORKSPACE:
workspaceSetCount(params.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;
case KEY_SHORTCUT_1:
spawn_shortcut(0);
break;
case KEY_SHORTCUT_2:
spawn_shortcut(1);
break;
case KEY_SHORTCUT_3:
spawn_shortcut(2);
break;
case KEY_SHORTCUT_4:
spawn_shortcut(3);
break;
case KEY_SHORTCUT_5:
spawn_shortcut(4);
break;
case KEY_SHORTCUT_6:
spawn_shortcut(5);
break;
case KEY_SHORTCUT_7:
spawn_shortcut(6);
break;
case KEY_SHORTCUT_8:
spawn_shortcut(7);
break;
case KEY_SHORTCUT_9:
spawn_shortcut(8);
break;
case KEY_SHORTCUT_10:
spawn_shortcut(9);
break;
default:
break;
Olivier Fourdan
committed
while(XCheckTypedEvent(dpy, EnterNotify, &e))
;
/* User has clicked on an edge or corner.
* Button 1 : Raise and resize
* Button 2 : Move
* Button 3 : Resize
*/
static inline void edgeButton(Client * c, int part, XButtonEvent * ev)
Olivier Fourdan
committed
XfwmButtonClickType tclick;
tclick = typeOfClick(c->frame, (XEvent *) ev, FALSE);
if(tclick == XFWM_BUTTON_CLICK)
{
clientLower(c);
}
else
{
moveRequest(c, (XEvent *) ev);
Olivier Fourdan
committed
}
Olivier Fourdan
committed
if(ev->button == Button1)
Olivier Fourdan
committed
clientRaise(c);
if((ev->button == Button1) || (ev->button == Button3))
resizeRequest(c, part, (XEvent *) ev);
static inline void button1Action(Client * c, XButtonEvent * ev)
{
XEvent copy_event = (XEvent) * ev;
XfwmButtonClickType tclick;
g_return_if_fail(c != NULL);
g_return_if_fail(ev != NULL);
clientSetFocus(c, TRUE);
clientRaise(c);
tclick = typeOfClick(c->frame, ©_event, TRUE);
if((tclick == XFWM_BUTTON_DRAG) || (tclick == XFWM_BUTTON_CLICK_AND_DRAG))
{
moveRequest(c, (XEvent *) ev);
}
else if(tclick == XFWM_BUTTON_DOUBLE_CLICK)
{
switch (params.double_click_action)
{
Olivier Fourdan
committed
case ACTION_MAXIMIZE:
clientToggleMaximized(c, WIN_STATE_MAXIMIZED);
Olivier Fourdan
committed
break;
case ACTION_SHADE:
clientToggleShaded(c);
break;
case ACTION_HIDE:
clientHide(c, c->win_workspace, TRUE);
Olivier Fourdan
committed
break;
static inline void titleButton(Client * c, int state, XButtonEvent * ev)
{
g_return_if_fail(c != NULL);
g_return_if_fail(ev != NULL);
if(ev->button == Button1)
{
button1Action(c, ev);
}
else if(ev->button == Button2)
{
clientLower(c);
}
else if(ev->button == Button3)
{
/*
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;
tclick = typeOfClick(c->frame, ©_event, FALSE);
if(tclick == XFWM_BUTTON_DRAG)
{
moveRequest(c, (XEvent *) ev);
}
else
{
clientSetFocus(c, TRUE);
if(params.raise_on_click)
{
clientRaise(c);
}
ev->window = ev->root;
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) c);
/* Let GTK handle this for us. */
}
}
else if(ev->button == Button4)
{
/* Mouse wheel scroll up */
if(!CLIENT_FLAG_TEST(c, CLIENT_FLAG_SHADED))
{
clientShade(c);
}
}
else if(ev->button == Button5)
{
/* Mouse wheel scroll down */
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_SHADED))
{
clientUnshade(c);
}
static inline void handleButtonPress(XButtonEvent * ev)
int state, replay = FALSE;
TRACE("entering handleButtonPress");
Olivier Fourdan
committed
clear_timeout();
Olivier Fourdan
committed
c = clientGetFromWindow(ev->window, ANY);
state = ev->state & (ShiftMask | ControlMask | AltMask | MetaMask | SuperMask | HyperMask);
Olivier Fourdan
committed
if((ev->button == Button1) && (state == AltMask))
{
Olivier Fourdan
committed
else if(WIN_IS_BUTTON(win))
Olivier Fourdan
committed
if (ev->button <= Button3)
Olivier Fourdan
committed
clientSetFocus(c, TRUE);
if(params.raise_on_click)
{
clientRaise(c);
}
clientButtonPress(c, win, ev);
else if(win == MYWINDOW_XWINDOW(c->title))
{
Olivier Fourdan
committed
else if(win == MYWINDOW_XWINDOW(c->buttons[MENU_BUTTON]))
Olivier Fourdan
committed
if (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)
*/
Olivier Fourdan
committed
XEvent copy_event = (XEvent) * ev;
XfwmButtonClickType tclick;
Olivier Fourdan
committed
Olivier Fourdan
committed
tclick = typeOfClick(c->frame, ©_event, TRUE);
Olivier Fourdan
committed
if(tclick == XFWM_BUTTON_DOUBLE_CLICK)
Olivier Fourdan
committed
clientClose(c);
Olivier Fourdan
committed
else
Olivier Fourdan
committed
clientSetFocus(c, TRUE);
if(params.raise_on_click)
{
clientRaise(c);
}
ev->window = ev->root;
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) c);
/* Let GTK handle this for us. */
else if(((ev->window != c->window) && (ev->button == Button2) && (state == 0)) || ((ev->button == Button2) && (state == (AltMask | ControlMask))))
{
clientLower(c);
}
else if((win == MYWINDOW_XWINDOW(c->corners[CORNER_TOP_LEFT])) && (state == 0))
edgeButton(c, CORNER_TOP_LEFT, ev);
else if((win == MYWINDOW_XWINDOW(c->corners[CORNER_TOP_RIGHT])) && (state == 0))
edgeButton(c, CORNER_TOP_RIGHT, ev);
else if((win == MYWINDOW_XWINDOW(c->corners[CORNER_BOTTOM_LEFT])) && (state == 0))
edgeButton(c, CORNER_BOTTOM_LEFT, ev);
else if((win == MYWINDOW_XWINDOW(c->corners[CORNER_BOTTOM_RIGHT])) && (state == 0))
edgeButton(c, CORNER_BOTTOM_RIGHT, ev);
else if((win == MYWINDOW_XWINDOW(c->sides[SIDE_BOTTOM])) && (state == 0))
edgeButton(c, 4 + SIDE_BOTTOM, ev);
else if((win == MYWINDOW_XWINDOW(c->sides[SIDE_LEFT])) && (state == 0))
edgeButton(c, 4 + SIDE_LEFT, ev);
else if((win == MYWINDOW_XWINDOW(c->sides[SIDE_RIGHT])) && (state == 0))
edgeButton(c, 4 + SIDE_RIGHT, ev);
Olivier Fourdan
committed
else
Olivier Fourdan
committed
if(ev->button == Button1)
clientSetFocus(c, TRUE);
if(params.raise_on_click)
Olivier Fourdan
committed
clientRaise(c);
Olivier Fourdan
committed
{
replay = TRUE;
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)
TRACE("entering handleButtonRelease");
XSendEvent(dpy, gnome_win, FALSE, SubstructureNotifyMask, (XEvent *) ev);
static inline void handleDestroyNotify(XDestroyWindowEvent * ev)
{
Client *c;
TRACE("entering handleDestroyNotify");
TRACE("destroyed window is (0x%lx)", ev->window);
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
TRACE("DestroyNotify for \"%s\" (0x%lx)", c->name, c->window);
clientPassFocus(c);
clientUnframe(c, FALSE);
}
}
static inline void handleUnmapNotify(XUnmapEvent * ev)
TRACE("entering handleUnmapNotify");
TRACE("unmapped window is (0x%lx)", ev->window);
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
TRACE("UnmapNotify for \"%s\" (0x%lx)", c->name, c->window);
/* Reparenting generates an unmapnotify, don't pass focus in that case */
if (CLIENT_FLAG_TEST(c, CLIENT_FLAG_REPARENTING))
{
CLIENT_FLAG_UNSET(c, CLIENT_FLAG_REPARENTING);
}
else
{
clientPassFocus(c);
}
Olivier Fourdan
committed
{
Olivier Fourdan
committed
else
clientUnframe(c, FALSE);
static inline void handleMapRequest(XMapRequestEvent * ev)
TRACE("entering handleMapRequest");
TRACE("mapped window is (0x%lx)", ev->window);
Olivier Fourdan
committed
if(ev->window == None)
TRACE("Mapping None ???");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
clientShow(c, TRUE);
clientFrame(ev->window, FALSE);
static inline void handleConfigureRequest(XConfigureRequestEvent * ev)
TRACE("entering handleConfigureRequest");
TRACE("configured window is (0x%lx)", ev->window);
while(XCheckTypedWindowEvent(dpy, ev->window, ConfigureRequest, &otherEvent))
if(otherEvent.xconfigurerequest.value_mask == ev->value_mask)
{
else
{
XPutBackEvent(dpy, &otherEvent);
break;
}
}
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);
{
/* Some app tend or try to manipulate the wm frame to achieve fullscreen mode */
c = clientGetFromWindow(ev->window, FRAME);
TRACE("client %s (0x%lx) is attempting to manipulate its frame!", c->name, c->window);
if(ev->value_mask & CWX)
{
}
if(ev->value_mask & CWY)
{
}
if(ev->value_mask & CWWidth)
{
wc.width -= frameLeft(c) + frameRight(c);
}
if(ev->value_mask & CWHeight)
{
wc.height -= frameTop(c) + frameBottom(c);
}
/* We don't allow changing stacking order by accessing the frame
window because that would break the layer management in xfwm4
*/
ev->value_mask &= ~(CWSibling | CWStackMode);
}
gboolean constrained = FALSE;
TRACE("handleConfigureRequest managed window \"%s\" (0x%lx)", c->name, c->window);
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_MOVING_RESIZING))
{
/* Sorry, but it's not the right time for configure request */
return;
}
Olivier Fourdan
committed
if(c->type == WINDOW_DESKTOP)
{
/* Ignore stacking request for DESKTOP windows */
ev->value_mask &= ~(CWSibling | CWStackMode);
Olivier Fourdan
committed
}
clientCoordGravitate(c, APPLY, &wc.x, &wc.y);
if(ev->value_mask & (CWX | CWY | CWWidth | CWHeight))
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_MAXIMIZED))
{
clientRemoveMaximizeFlag(c);
}
constrained = TRUE;
/* Let's say that if the client performs a XRaiseWindow, we show the window if hidden */
if((ev->value_mask & CWStackMode) && (wc.stack_mode == Above))
if (CLIENT_FLAG_TEST(c, CLIENT_FLAG_HIDDEN))
{
clientShow(c, TRUE);
}
clientConfigure(c, &wc, ev->value_mask, constrained);
TRACE("unmanaged configure request for win 0x%lx", ev->window);
XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
}
}
static inline void handleEnterNotify(XCrossingEvent * ev)
TRACE("entering handleEnterNotify");
if((ev->mode == NotifyGrab) || (ev->mode == NotifyUngrab) || (ev->detail > NotifyNonlinearVirtual))
{
/* We're not interested in such notifications */
return;
}
TRACE("entered window is (0x%lx)", ev->window);
if(c && !(params.click_to_focus) && (clientAcceptFocus(c)))
TRACE("EnterNotify window is \"%s\"", c->name);
if((c->type != WINDOW_DOCK) && (c->type != WINDOW_DESKTOP))
{
clientSetFocus(c, TRUE);
static inline void handleFocusIn(XFocusChangeEvent * ev)
TRACE("entering handleFocusIn");
if((ev->mode == NotifyGrab) || (ev->mode == NotifyUngrab) || (ev->detail > NotifyNonlinearVirtual))
{
/* We're not interested in such notifications */
return;
}
Olivier Fourdan
committed
if(ev->window == gnome_win)
{
/* Don't get fooled by our own gtk window ! */
return;
}
Olivier Fourdan
committed
while(XCheckTypedEvent(dpy, FocusIn, (XEvent *) ev))
{
if((ev->mode == NotifyGrab) || (ev->mode == NotifyUngrab) || (ev->detail > NotifyNonlinearVirtual))
{
continue;
}
c2 = clientGetFromWindow(ev->window, WINDOW);
if (c2)
{
c = c2;
}
TRACE("focused window is (0x%lx)", ev->window);
TRACE("focus set to \"%s\" (0x%lx)", c->name, c->window);
frameDraw(c, FALSE, FALSE);
if(params.raise_on_focus && !params.click_to_focus)
Olivier Fourdan
committed
{
reset_timeout();
}
static inline void handleFocusOut(XFocusChangeEvent * ev)
TRACE("entering handleFocusOut - Window (0x%lx)", w);
static inline void handlePropertyNotify(XPropertyEvent * ev)
TRACE("entering handlePropertyNotify");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
if(ev->atom == XA_WM_NORMAL_HINTS)
{
unsigned long previous_value;
Olivier Fourdan
committed
TRACE("client \"%s\" (0x%lx) has received a XA_WM_NORMAL_HINTS notify", c->name, c->window);
Olivier Fourdan
committed
XGetWMNormalHints(dpy, c->window, c->size, &dummy);
previous_value = CLIENT_FLAG_TEST(c, CLIENT_FLAG_IS_RESIZABLE);
CLIENT_FLAG_UNSET(c, CLIENT_FLAG_IS_RESIZABLE);
if(((c->size->flags & (PMinSize | PMaxSize)) != (PMinSize | PMaxSize)) || (((c->size->flags & (PMinSize | PMaxSize)) == (PMinSize | PMaxSize)) && ((c->size->min_width < c->size->max_width) || (c->size->min_height < c->size->max_height))))
{
CLIENT_FLAG_SET(c, CLIENT_FLAG_IS_RESIZABLE);
}
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_IS_RESIZABLE) != previous_value)
Olivier Fourdan
committed
{
frameDraw(c, TRUE, FALSE);
Olivier Fourdan
committed
}
Olivier Fourdan
committed
else if((ev->atom == XA_WM_NAME) || (ev->atom == net_wm_name))
TRACE("client \"%s\" (0x%lx) has received a XA_WM_NAME notify", c->name, c->window);
Olivier Fourdan
committed
{
Olivier Fourdan
committed
getWindowName(dpy, c->window, &c->name);
CLIENT_FLAG_SET(c, CLIENT_FLAG_NAME_CHANGED);
frameDraw(c, TRUE, FALSE);
else if(ev->atom == motif_wm_hints)
{
XWindowChanges wc;
Olivier Fourdan
committed
TRACE("client \"%s\" (0x%lx) has received a motif_wm_hints notify", c->name, c->window);
Olivier Fourdan
committed
wc.x = c->x;
wc.y = c->y;
wc.width = c->width;
wc.height = c->height;
clientConfigure(c, &wc, CWX | CWY | CWWidth | CWHeight, FALSE);
else if(ev->atom == XA_WM_HINTS)
{
TRACE("client \"%s\" (0x%lx) has received a XA_WM_HINTS notify\n", c->name, c->window);
c->wmhints = XGetWMHints(dpy, c->window);
if(c->wmhints)
{
c->group_leader = c->wmhints->window_group;
}
}
TRACE("client \"%s\" (0x%lx) has received a win_hints notify", c->name, c->window);
Olivier Fourdan
committed
getGnomeHint(dpy, c->window, win_hints, &c->win_hints);
Olivier Fourdan
committed
else if(ev->atom == net_wm_window_type)
TRACE("client \"%s\" (0x%lx) has received a net_wm_window_type notify", c->name, c->window);
Olivier Fourdan
committed
clientGetNetWmType(c);
frameDraw(c, TRUE, FALSE);
Olivier Fourdan
committed
else if(ev->atom == net_wm_strut)
TRACE("client \"%s\" (0x%lx) has received a net_wm_strut notify", 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
}
}
#ifdef HAVE_STARTUP_NOTIFICATION
else if(ev->atom == net_startup_id)
{
if(c->startup_id)
{
free(c->startup_id);
c->startup_id = NULL;
}
getWindowStartupId(dpy, c->window, &c->startup_id);
}
#endif
else if(ev->atom == gnome_panel_desktop_area)
TRACE("root has received a gnome_panel_desktop_area notify");
getGnomeDesktopMargins(dpy, screen, gnome_margins);
workspaceUpdateArea(margins, gnome_margins);
static inline void handleClientMessage(XClientMessageEvent * ev)
TRACE("entering handleClientMessage");
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
{
TRACE("client \"%s\" (0x%lx) has received a wm_change_state event", c->name, c->window);
if (!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HIDDEN))
{
clientHide(c, c->win_workspace, TRUE);
}
Olivier Fourdan
committed
}
Olivier Fourdan
committed
else if((ev->message_type == win_state) && (ev->format == 32))
Olivier Fourdan
committed
TRACE("client \"%s\" (0x%lx) has received a win_state event", c->name, c->window);
clientUpdateWinState(c, ev);
Olivier Fourdan
committed
else if((ev->message_type == win_layer) && (ev->format == 32))
{
TRACE("client \"%s\" (0x%lx) has received a win_layer event", c->name, c->window);
if (ev->data.l[0] != c->win_layer)
{
clientSetLayer(c, ev->data.l[0]);
clientSetNetState(c);
}
else if((ev->message_type == win_workspace) && (ev->format == 32) && !clientIsTransient(c))
Olivier Fourdan
committed
{
TRACE("client \"%s\" (0x%lx) has received a win_workspace event", c->name, c->window);
if (ev->data.l[0] != c->win_workspace)
{
clientSetWorkspace(c, ev->data.l[0], TRUE);
}
Olivier Fourdan
committed
}
else if((ev->message_type == net_wm_desktop) && (ev->format == 32))
{
TRACE("client \"%s\" (0x%lx) has received a net_wm_desktop event", c->name, c->window);
if((ev->data.l[0] == (int)0xFFFFFFFF) && CLIENT_FLAG_TEST(c, CLIENT_FLAG_HAS_STICK))
Olivier Fourdan
committed
{
Olivier Fourdan
committed
}
else if((ev->data.l[0] != c->win_workspace) && !clientIsTransient(c))
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
{
TRACE("client \"%s\" (0x%lx) has received a net_close_window event", c->name, c->window);
Olivier Fourdan
committed
clientClose(c);
}
else if((ev->message_type == net_wm_state) && (ev->format == 32))
{
TRACE("client \"%s\" (0x%lx) has received a net_wm_state event", c->name, c->window);
Olivier Fourdan
committed
clientUpdateNetState(c, ev);
}
else if((ev->message_type == net_wm_moveresize) && (ev->format == 32))
{
TRACE("client \"%s\" (0x%lx) has received a net_wm_moveresize event", c->name, c->window);
g_message(_("%s: Operation not supported (yet)\n"), g_get_prgname());
Olivier Fourdan
committed
/* TBD */
}
else if((ev->message_type == net_active_window) && (ev->format == 32))
{
TRACE("client \"%s\" (0x%lx) has received a net_active_window event", c->name, c->window);
Olivier Fourdan
committed
workspaceSwitch(c->win_workspace, NULL);
clientShow(c, TRUE);
Olivier Fourdan
committed
clientRaise(c);
clientSetFocus(c, TRUE);
Olivier Fourdan
committed
}
}
else
{
if(((ev->message_type == win_workspace) || (ev->message_type == net_current_desktop)) && (ev->format == 32))
Olivier Fourdan
committed
{
TRACE("root has received a win_workspace or a net_current_desktop event");
Olivier Fourdan
committed
if (workspace != ev->data.l[0])
{
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))
{
TRACE("root has received a win_workspace_count event");
if (params.workspace_count != ev->data.l[0])
{
workspaceSetCount(ev->data.l[0]);
}
Olivier Fourdan
committed
}
TRACE("unidentified client message for window 0x%lx", ev->window);
static inline void handleShape(XShapeEvent * ev)
TRACE("entering handleShape");
c = clientGetFromWindow(ev->window, WINDOW);
if(c)
{
frameDraw(c, FALSE, TRUE);
Olivier Fourdan
committed
static inline void handleColormapNotify(XColormapEvent * ev)
Olivier Fourdan
committed
TRACE("entering handleColormapNotify");
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);
}
TRACE("entering handleEvent");
sn_process_event(ev);
Olivier Fourdan
committed
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
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;
default:
if(shape && (ev->type == shape_event))
{
handleShape((XShapeEvent *) ev);
}
Olivier Fourdan
committed
if(!gdk_events_pending() && !XPending(dpy))
Olivier Fourdan
committed
if(reload)
{
reload = FALSE;
Olivier Fourdan
committed
}
else if(quit)
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
GtkToXEventFilterStatus xfwm4_event_filter(XEvent * xevent, gpointer data)
TRACE("entering xfwm4_event_filter");
TRACE("leaving xfwm4_event_filter");
/* GTK specific stuff */
Olivier Fourdan
committed
static void menu_callback(Menu * menu, MenuOp op, Window client_xwindow, gpointer menu_data, gpointer item_data)
Olivier Fourdan
committed
TRACE("entering menu_callback");
Olivier Fourdan
committed
if(menu_event_window)
Olivier Fourdan
committed
removeTmpEventWin(menu_event_window);
Olivier Fourdan
committed
if(menu_data)
Olivier Fourdan
committed
c = (Client *) menu_data;
c = clientGetFromWindow(c->window, WINDOW);
if (!c)
Olivier Fourdan
committed
{
menu_free(menu);
return;
Olivier Fourdan
committed
}
c->button_pressed[MENU_BUTTON] = FALSE;
Olivier Fourdan
committed
Olivier Fourdan
committed
case MENU_OP_QUIT:
gtk_main_quit();
break;
case MENU_OP_MAXIMIZE:
case MENU_OP_UNMAXIMIZE:
if(CLIENT_CAN_MAXIMIZE_WINDOW(c))
Olivier Fourdan
committed
{
clientToggleMaximized(c, WIN_STATE_MAXIMIZED);
}
break;
case MENU_OP_MINIMIZE:
if(CLIENT_CAN_HIDE_WINDOW(c))
Olivier Fourdan
committed
{
clientHide(c, c->win_workspace, TRUE);
Olivier Fourdan
committed
}
frameDraw(c, FALSE, FALSE);
Olivier Fourdan
committed
break;
case MENU_OP_MINIMIZE_ALL:
clientHideAll(c, c->win_workspace);
frameDraw(c, FALSE, FALSE);
Olivier Fourdan
committed
break;
case MENU_OP_UNMINIMIZE:
clientShow(c, TRUE);
Olivier Fourdan
committed
break;
case MENU_OP_SHADE:
case MENU_OP_UNSHADE:
clientToggleShaded(c);
Olivier Fourdan
committed
break;
case MENU_OP_STICK:
case MENU_OP_UNSTICK:
clientToggleSticky(c, TRUE);
frameDraw(c, FALSE, FALSE);
Olivier Fourdan
committed
break;
case MENU_OP_DELETE:
frameDraw(c, FALSE, FALSE);
clientClose(c);
Olivier Fourdan
committed
break;
default:
frameDraw(c, FALSE, FALSE);
Olivier Fourdan
committed
break;
Olivier Fourdan
committed
}
menu_free(menu);
Olivier Fourdan
committed
static gboolean show_popup_cb(GtkWidget * widget, GdkEventButton * ev, gpointer data)
Olivier Fourdan
committed
Menu *menu;
MenuOp ops;
MenuOp insensitive;
Client *c = NULL;
gint x = ev->x_root;
gint y = ev->y_root;
TRACE("entering show_popup_cb");
Olivier Fourdan
committed
if(((ev->button == 1) || (ev->button == 3)) && (c = (Client *) data))
{
c->button_pressed[MENU_BUTTON] = TRUE;
frameDraw(c, FALSE, FALSE);
Olivier Fourdan
committed
y = c->y;
ops = MENU_OP_DELETE | MENU_OP_MINIMIZE_ALL;
Olivier Fourdan
committed
insensitive = 0;
if(!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HAS_CLOSE))
Olivier Fourdan
committed
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_MAXIMIZED))
Olivier Fourdan
committed
{
ops |= MENU_OP_UNMAXIMIZE;
if(!CLIENT_CAN_MAXIMIZE_WINDOW(c))
Olivier Fourdan
committed
{
insensitive |= MENU_OP_UNMAXIMIZE;
}
Olivier Fourdan
committed
}
Olivier Fourdan
committed
else
Olivier Fourdan
committed
{
ops |= MENU_OP_MAXIMIZE;
if(!CLIENT_CAN_MAXIMIZE_WINDOW(c))
Olivier Fourdan
committed
{
insensitive |= MENU_OP_MAXIMIZE;
}
Olivier Fourdan
committed
}
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_HIDDEN))
Olivier Fourdan
committed
{
ops |= MENU_OP_UNMINIMIZE;
if(!CLIENT_CAN_HIDE_WINDOW(c))
Olivier Fourdan
committed
{
insensitive |= MENU_OP_UNMINIMIZE;
}
Olivier Fourdan
committed
}
Olivier Fourdan
committed
{
ops |= MENU_OP_MINIMIZE;
if(!CLIENT_CAN_HIDE_WINDOW(c))
Olivier Fourdan
committed
{
insensitive |= MENU_OP_MINIMIZE;
}
Olivier Fourdan
committed
}
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_SHADED))
Olivier Fourdan
committed
{
ops |= MENU_OP_UNSHADE;
}
Olivier Fourdan
committed
{
ops |= MENU_OP_SHADE;
}
if(CLIENT_FLAG_TEST(c, CLIENT_FLAG_STICKY))
Olivier Fourdan
committed
{
ops |= MENU_OP_UNSTICK;
Olivier Fourdan
committed
if(!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HAS_STICK))
Olivier Fourdan
committed
{
insensitive |= MENU_OP_UNSTICK;
Olivier Fourdan
committed
}
Olivier Fourdan
committed
}
Olivier Fourdan
committed
{
ops |= MENU_OP_STICK;
Olivier Fourdan
committed
if(!CLIENT_FLAG_TEST(c, CLIENT_FLAG_HAS_STICK))
Olivier Fourdan
committed
{
Olivier Fourdan
committed
}
Olivier Fourdan
committed
}
}
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);
Olivier Fourdan
committed
if(menu_event_window)
Olivier Fourdan
committed
removeTmpEventWin(menu_event_window);
/*
Since all button press/release events are catched by the windows frames, there is some
side effect with GTK menu. When a menu is opened, any click on the window frame is not
detected as a click outside the menu, and the menu doesn't close.
To avoid this (painless but annoying) behaviour, we just setup a no event window that
"hides" the events to regular windows.
That might look tricky, but it's very efficient and save plenty of lines of complicated
Don't forget to delete that window once the menu is closed, though, or we'll get in
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
{
TRACE("Cannot open menu");
gdk_beep();
c->button_pressed[MENU_BUTTON] = FALSE;
frameDraw(c, FALSE, FALSE);
Olivier Fourdan
committed
removeTmpEventWin(menu_event_window);
Olivier Fourdan
committed
menu_free(menu);
}
Olivier Fourdan
committed
return (TRUE);
TRACE("setting reload flag so all prefs will be reread at next event loop");
reload = TRUE;
static gboolean dbl_click_time(void)
Olivier Fourdan
committed
TRACE("setting dbl_click_time");
Olivier Fourdan
committed
g_value_init(&tmp_val, G_TYPE_INT);
if(gdk_setting_get("gtk-double-click-time", &tmp_val))
params.dbl_click_time = abs(g_value_get_int(&tmp_val));
}
return (TRUE);
}
Olivier Fourdan
committed
static gboolean client_event_cb(GtkWidget * widget, GdkEventClient * ev)
TRACE("entering client_event_cb");
Olivier Fourdan
committed
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);
g_signal_connect(settings, "notify::gtk-double-click-time", G_CALLBACK(dbl_click_time), NULL);