+struct ObSkipPropertyChange {
+ Window window;
+ Atom prop;
+};
+
+static gboolean skip_property_change(XEvent *e, gpointer data)
+{
+ const struct ObSkipPropertyChange s = *(struct ObSkipPropertyChange*)data;
+
+ if (e->type == PropertyNotify && e->xproperty.window == s.window) {
+ const Atom a = e->xproperty.atom;
+ const Atom b = s.prop;
+
+ /* these are all updated together */
+ if ((a == OBT_PROP_ATOM(NET_WM_NAME) ||
+ a == OBT_PROP_ATOM(WM_NAME) ||
+ a == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
+ a == OBT_PROP_ATOM(WM_ICON_NAME))
+ &&
+ (b == OBT_PROP_ATOM(NET_WM_NAME) ||
+ b == OBT_PROP_ATOM(WM_NAME) ||
+ b == OBT_PROP_ATOM(NET_WM_ICON_NAME) ||
+ b == OBT_PROP_ATOM(WM_ICON_NAME)))
+ {
+ return TRUE;
+ }
+ else if (a == b && a == OBT_PROP_ATOM(NET_WM_ICON))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void event_handle_client(ObClient *client, XEvent *e)
+{
+ Atom msgtype;
+ ObFrameContext con;
+ gboolean *but;
+ static gint px = -1, py = -1;
+ static guint pb = 0;
+ static ObFrameContext pcon = OB_FRAME_CONTEXT_NONE;
+
+ switch (e->type) {
+ case ButtonPress:
+ /* save where the press occured for the first button pressed */
+ if (!pb) {
+ pb = e->xbutton.button;
+ px = e->xbutton.x;
+ py = e->xbutton.y;
+
+ pcon = frame_context(client, e->xbutton.window, px, py);
+ pcon = mouse_button_frame_context(pcon, e->xbutton.button,
+ e->xbutton.state);
+ }
+ case ButtonRelease:
+ /* Wheel buttons don't draw because they are an instant click, so it
+ is a waste of resources to go drawing it.
+ if the user is doing an interactive thing, or has a menu open then
+ the mouse is grabbed (possibly) and if we get these events we don't
+ want to deal with them
+ */
+ if (!(e->xbutton.button == 4 || e->xbutton.button == 5) &&
+ !grab_on_keyboard())
+ {
+ /* use where the press occured */
+ con = frame_context(client, e->xbutton.window, px, py);
+ con = mouse_button_frame_context(con, e->xbutton.button,
+ e->xbutton.state);
+
+ /* button presses on CLIENT_CONTEXTs are not accompanied by a
+ release because they are Replayed to the client */
+ if ((e->type == ButtonRelease || CLIENT_CONTEXT(con, client)) &&
+ e->xbutton.button == pb)
+ pb = 0, px = py = -1, pcon = OB_FRAME_CONTEXT_NONE;
+
+ but = context_to_button(client->frame, con, TRUE);
+ if (but) {
+ *but = (e->type == ButtonPress);
+ frame_adjust_state(client->frame);
+ }
+ }
+ break;
+ case MotionNotify:
+ /* when there is a grab on the pointer, we won't get enter/leave
+ notifies, but we still get motion events */
+ if (grab_on_pointer()) break;
+
+ con = frame_context(client, e->xmotion.window,
+ e->xmotion.x, e->xmotion.y);
+ switch (con) {
+ case OB_FRAME_CONTEXT_TITLEBAR:
+ case OB_FRAME_CONTEXT_TLCORNER:
+ case OB_FRAME_CONTEXT_TRCORNER:
+ /* we've left the button area inside the titlebar */
+ if (client->frame->max_hover || client->frame->desk_hover ||
+ client->frame->shade_hover || client->frame->iconify_hover ||
+ client->frame->close_hover)
+ {
+ client->frame->max_hover =
+ client->frame->desk_hover =
+ client->frame->shade_hover =
+ client->frame->iconify_hover =
+ client->frame->close_hover = FALSE;
+ frame_adjust_state(client->frame);
+ }
+ break;
+ default:
+ but = context_to_button(client->frame, con, FALSE);
+ if (but && !*but && !pb) {
+ *but = TRUE;
+ frame_adjust_state(client->frame);
+ }
+ break;
+ }
+ break;
+ case LeaveNotify:
+ con = frame_context(client, e->xcrossing.window,
+ e->xcrossing.x, e->xcrossing.y);
+ switch (con) {
+ case OB_FRAME_CONTEXT_TITLEBAR:
+ case OB_FRAME_CONTEXT_TLCORNER:
+ case OB_FRAME_CONTEXT_TRCORNER:
+ /* we've left the button area inside the titlebar */
+ client->frame->max_hover =
+ client->frame->desk_hover =
+ client->frame->shade_hover =
+ client->frame->iconify_hover =
+ client->frame->close_hover = FALSE;
+ if (e->xcrossing.mode == NotifyGrab) {
+ client->frame->max_press =
+ client->frame->desk_press =
+ client->frame->shade_press =
+ client->frame->iconify_press =
+ client->frame->close_press = FALSE;
+ }
+ break;
+ case OB_FRAME_CONTEXT_FRAME:
+ /* When the mouse leaves an animating window, don't use the
+ corresponding enter events. Pretend like the animating window
+ doesn't even exist..! */
+ if (frame_iconify_animating(client->frame))
+ event_end_ignore_all_enters(event_start_ignore_all_enters());
+
+ ob_debug_type(OB_DEBUG_FOCUS,
+ "%sNotify mode %d detail %d on %lx",
+ (e->type == EnterNotify ? "Enter" : "Leave"),
+ e->xcrossing.mode,
+ e->xcrossing.detail, (client?client->window:0));
+ if (grab_on_keyboard())
+ break;
+ if (config_focus_follow &&
+ /* leave inferior events can happen when the mouse goes onto
+ the window's border and then into the window before the
+ delay is up */
+ e->xcrossing.detail != NotifyInferior)
+ {
+ if (config_focus_delay && focus_delay_timeout_id)
+ g_source_remove(focus_delay_timeout_id);
+ if (config_unfocus_leave)
+ event_leave_client(client);
+ }
+ break;
+ default:
+ but = context_to_button(client->frame, con, FALSE);
+ if (but) {
+ *but = FALSE;
+ if (e->xcrossing.mode == NotifyGrab) {
+ but = context_to_button(client->frame, con, TRUE);
+ *but = FALSE;
+ }
+ frame_adjust_state(client->frame);
+ }
+ break;
+ }
+ break;
+ case EnterNotify:
+ {
+ con = frame_context(client, e->xcrossing.window,
+ e->xcrossing.x, e->xcrossing.y);
+ switch (con) {
+ case OB_FRAME_CONTEXT_FRAME:
+ if (grab_on_keyboard())
+ break;
+ if (e->xcrossing.mode == NotifyGrab ||
+ (e->xcrossing.mode == NotifyUngrab &&
+ /* ungrab enters are used when _under_ mouse is being used */
+ !(config_focus_follow && config_focus_under_mouse)) ||
+ /*ignore enters when we're already in the window */
+ e->xcrossing.detail == NotifyInferior)
+ {
+ ob_debug_type(OB_DEBUG_FOCUS,
+ "%sNotify mode %d detail %d serial %lu on %lx "
+ "IGNORED",
+ (e->type == EnterNotify ? "Enter" : "Leave"),
+ e->xcrossing.mode,
+ e->xcrossing.detail,
+ e->xcrossing.serial,
+ client?client->window:0);
+ }
+ else {
+ ob_debug_type(OB_DEBUG_FOCUS,
+ "%sNotify mode %d detail %d serial %lu on %lx, "
+ "focusing window",
+ (e->type == EnterNotify ? "Enter" : "Leave"),
+ e->xcrossing.mode,
+ e->xcrossing.detail,
+ e->xcrossing.serial,
+ (client?client->window:0));
+ if (config_focus_follow) {
+ if (config_focus_delay && unfocus_delay_timeout_id)
+ g_source_remove(unfocus_delay_timeout_id);
+ event_enter_client(client);
+ }
+ }
+ break;
+ default:
+ but = context_to_button(client->frame, con, FALSE);
+ if (but) {
+ *but = TRUE;
+ if (e->xcrossing.mode == NotifyUngrab) {
+ but = context_to_button(client->frame, con, TRUE);
+ *but = (con == pcon);
+ }
+ frame_adjust_state(client->frame);
+ }
+ break;
+ }
+ break;
+ }
+ case ConfigureRequest:
+ {
+ /* dont compress these unless you're going to watch for property
+ notifies in between (these can change what the configure would
+ do to the window).
+ also you can't compress stacking events
+ */
+
+ gint x, y, w, h;
+ gboolean move = FALSE;
+ gboolean resize = FALSE;
+
+ /* get the current area */
+ RECT_TO_DIMS(client->area, x, y, w, h);
+
+ ob_debug("ConfigureRequest for \"%s\" desktop %d wmstate %d "
+ "visible %d",
+ client->title,
+ screen_desktop, client->wmstate, client->frame->visible);
+ ob_debug(" x %d y %d w %d h %d b %d",
+ x, y, w, h, client->border_width);
+
+ if (e->xconfigurerequest.value_mask & CWBorderWidth)
+ if (client->border_width != e->xconfigurerequest.border_width) {
+ client->border_width = e->xconfigurerequest.border_width;
+
+ /* if the border width is changing then that is the same
+ as requesting a resize, but we don't actually change
+ the client's border, so it will change their root
+ coordinates (since they include the border width) and
+ we need to a notify then */
+ move = TRUE;
+ }
+
+ if (e->xconfigurerequest.value_mask & CWStackMode) {
+ ObClient *sibling = NULL;
+ gulong ignore_start;
+ gboolean ok = TRUE;
+
+ /* get the sibling */
+ if (e->xconfigurerequest.value_mask & CWSibling) {
+ ObWindow *win;
+ win = window_find(e->xconfigurerequest.above);
+ if (win && WINDOW_IS_CLIENT(win) &&
+ WINDOW_AS_CLIENT(win) != client)
+ {
+ sibling = WINDOW_AS_CLIENT(win);
+ }
+ else
+ /* an invalid sibling was specified so don't restack at
+ all, it won't make sense no matter what we do */
+ ok = FALSE;
+ }
+
+ if (ok) {
+ if (!config_focus_under_mouse)
+ ignore_start = event_start_ignore_all_enters();
+ stacking_restack_request(client, sibling,
+ e->xconfigurerequest.detail);
+ if (!config_focus_under_mouse)
+ event_end_ignore_all_enters(ignore_start);
+ }
+
+ /* a stacking change moves the window without resizing */
+ move = TRUE;
+ }
+
+ if ((e->xconfigurerequest.value_mask & CWX) ||
+ (e->xconfigurerequest.value_mask & CWY) ||
+ (e->xconfigurerequest.value_mask & CWWidth) ||
+ (e->xconfigurerequest.value_mask & CWHeight))
+ {
+ /* don't allow clients to move shaded windows (fvwm does this)
+ */
+ if (e->xconfigurerequest.value_mask & CWX) {
+ if (!client->shaded)
+ x = e->xconfigurerequest.x;
+ move = TRUE;
+ }
+ if (e->xconfigurerequest.value_mask & CWY) {
+ if (!client->shaded)
+ y = e->xconfigurerequest.y;
+ move = TRUE;
+ }
+
+ if (e->xconfigurerequest.value_mask & CWWidth) {
+ w = e->xconfigurerequest.width;
+ resize = TRUE;
+ }
+ if (e->xconfigurerequest.value_mask & CWHeight) {
+ h = e->xconfigurerequest.height;
+ resize = TRUE;
+ }
+ }
+
+ ob_debug("ConfigureRequest x(%d) %d y(%d) %d w(%d) %d h(%d) %d "
+ "move %d resize %d",
+ e->xconfigurerequest.value_mask & CWX, x,
+ e->xconfigurerequest.value_mask & CWY, y,
+ e->xconfigurerequest.value_mask & CWWidth, w,
+ e->xconfigurerequest.value_mask & CWHeight, h,
+ move, resize);
+
+ /* check for broken apps moving to their root position
+
+ XXX remove this some day...that would be nice. right now all
+ kde apps do this when they try activate themselves on another
+ desktop. eg. open amarok window on desktop 1, switch to desktop
+ 2, click amarok tray icon. it will move by its decoration size.
+ */
+ if (x != client->area.x &&
+ x == (client->frame->area.x + client->frame->size.left -
+ (gint)client->border_width) &&
+ y != client->area.y &&
+ y == (client->frame->area.y + client->frame->size.top -
+ (gint)client->border_width) &&
+ w == client->area.width &&
+ h == client->area.height)
+ {
+ ob_debug_type(OB_DEBUG_APP_BUGS,
+ "Application %s is trying to move via "
+ "ConfigureRequest to it's root window position "
+ "but it is not using StaticGravity",
+ client->title);
+ /* don't move it */
+ x = client->area.x;
+ y = client->area.y;
+
+ /* they still requested a move, so don't change whether a
+ notify is sent or not */
+ }
+
+ /* check for broken apps (java swing) moving to 0,0 when there is a
+ strut there.
+
+ XXX remove this some day...that would be nice. but really unexpected
+ from Sun Microsystems.
+ */
+ if (x == 0 && y == 0 && client->gravity == NorthWestGravity &&
+ client_normal(client))
+ {
+ const Rect to = { x, y, w, h };
+
+ /* oldschool fullscreen windows are allowed */
+ if (!client_is_oldfullscreen(client, &to)) {
+ Rect *r;
+
+ r = screen_area(client->desktop, SCREEN_AREA_ALL_MONITORS,
+ NULL);
+ if (r->x || r->y) {
+ /* move the window only to the corner outside struts */
+ x = r->x;
+ y = r->y;
+
+ ob_debug_type(OB_DEBUG_APP_BUGS,
+ "Application %s is trying to move via "
+ "ConfigureRequest to 0,0 using "
+ "NorthWestGravity, while there is a "
+ "strut there. "
+ "Moving buggy app from (0,0) to (%d,%d)",
+ client->title, r->x, r->y);
+ }
+
+ g_slice_free(Rect, r);
+
+ /* they still requested a move, so don't change whether a
+ notify is sent or not */
+ }
+ }
+
+ {
+ gint lw, lh;
+
+ client_try_configure(client, &x, &y, &w, &h, &lw, &lh, FALSE);
+
+ /* if x was not given, then use gravity to figure out the new
+ x. the reference point should not be moved */
+ if ((e->xconfigurerequest.value_mask & CWWidth &&
+ !(e->xconfigurerequest.value_mask & CWX)))
+ client_gravity_resize_w(client, &x, client->area.width, w);
+ /* same for y */
+ if ((e->xconfigurerequest.value_mask & CWHeight &&
+ !(e->xconfigurerequest.value_mask & CWY)))
+ client_gravity_resize_h(client, &y, client->area.height,h);
+
+ client_find_onscreen(client, &x, &y, w, h, FALSE);
+
+ ob_debug("Granting ConfigureRequest x %d y %d w %d h %d",
+ x, y, w, h);
+ client_configure(client, x, y, w, h, FALSE, TRUE, TRUE);
+ }
+ break;
+ }
+ case UnmapNotify:
+ ob_debug("UnmapNotify for window 0x%x eventwin 0x%x sendevent %d "
+ "ignores left %d",
+ client->window, e->xunmap.event, e->xunmap.from_configure,
+ client->ignore_unmaps);
+ if (client->ignore_unmaps) {
+ client->ignore_unmaps--;
+ break;
+ }
+ client_unmanage(client);
+ break;