Merge branch 'backport' into work
[dana/openbox.git] / openbox / event.c
index 4fbb97c..2ccec27 100644 (file)
@@ -848,6 +848,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
     ObFrameContext con;
     static gint px = -1, py = -1;
     static guint pb = 0;
+    static ObFrameContext pcon = OB_FRAME_CONTEXT_NONE;
 
     switch (e->type) {
     case ButtonPress:
@@ -856,11 +857,15 @@ static void event_handle_client(ObClient *client, XEvent *e)
             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 intereactive thing, or has a menu open then
+           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
         */
@@ -872,8 +877,11 @@ static void event_handle_client(ObClient *client, XEvent *e)
             con = mouse_button_frame_context(con, e->xbutton.button,
                                              e->xbutton.state);
 
-            if (e->type == ButtonRelease && e->xbutton.button == pb)
-                pb = 0, px = py = -1;
+            /* 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;
 
             switch (con) {
             case OB_FRAME_CONTEXT_MAXIMIZE:
@@ -927,31 +935,31 @@ static void event_handle_client(ObClient *client, XEvent *e)
             }
             break;
         case OB_FRAME_CONTEXT_MAXIMIZE:
-            if (!client->frame->max_hover) {
+            if (!client->frame->max_hover && !pb) {
                 client->frame->max_hover = TRUE;
                 frame_adjust_state(client->frame);
             }
             break;
         case OB_FRAME_CONTEXT_ALLDESKTOPS:
-            if (!client->frame->desk_hover) {
+            if (!client->frame->desk_hover && !pb) {
                 client->frame->desk_hover = TRUE;
                 frame_adjust_state(client->frame);
             }
             break;
         case OB_FRAME_CONTEXT_SHADE:
-            if (!client->frame->shade_hover) {
+            if (!client->frame->shade_hover && !pb) {
                 client->frame->shade_hover = TRUE;
                 frame_adjust_state(client->frame);
             }
             break;
         case OB_FRAME_CONTEXT_ICONIFY:
-            if (!client->frame->iconify_hover) {
+            if (!client->frame->iconify_hover && !pb) {
                 client->frame->iconify_hover = TRUE;
                 frame_adjust_state(client->frame);
             }
             break;
         case OB_FRAME_CONTEXT_CLOSE:
-            if (!client->frame->close_hover) {
+            if (!client->frame->close_hover && !pb) {
                 client->frame->close_hover = TRUE;
                 frame_adjust_state(client->frame);
             }
@@ -968,36 +976,48 @@ static void event_handle_client(ObClient *client, XEvent *e)
         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 = FALSE;
-                client->frame->desk_hover = FALSE;
-                client->frame->shade_hover = FALSE;
-                client->frame->iconify_hover = FALSE;
-                client->frame->close_hover = FALSE;
-                frame_adjust_state(client->frame);
+            client->frame->max_hover = FALSE;
+            client->frame->desk_hover = FALSE;
+            client->frame->shade_hover = FALSE;
+            client->frame->iconify_hover = FALSE;
+            client->frame->close_hover = FALSE;
+            if (e->xcrossing.mode == NotifyGrab) {
+                client->frame->max_press = FALSE;
+                client->frame->desk_press = FALSE;
+                client->frame->shade_press = FALSE;
+                client->frame->iconify_press = FALSE;
+                client->frame->close_press = FALSE;
             }
+            frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_MAXIMIZE:
             client->frame->max_hover = FALSE;
+            if (e->xcrossing.mode == NotifyGrab)
+                client->frame->max_press = FALSE;
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_ALLDESKTOPS:
             client->frame->desk_hover = FALSE;
+            if (e->xcrossing.mode == NotifyGrab)
+                client->frame->desk_press = FALSE;
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_SHADE:
             client->frame->shade_hover = FALSE;
+            if (e->xcrossing.mode == NotifyGrab)
+                client->frame->shade_press = FALSE;
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_ICONIFY:
             client->frame->iconify_hover = FALSE;
+            if (e->xcrossing.mode == NotifyGrab)
+                client->frame->iconify_press = FALSE;
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_CLOSE:
             client->frame->close_hover = FALSE;
+            if (e->xcrossing.mode == NotifyGrab)
+                client->frame->close_press = FALSE;
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_FRAME:
@@ -1036,22 +1056,32 @@ static void event_handle_client(ObClient *client, XEvent *e)
         switch (con) {
         case OB_FRAME_CONTEXT_MAXIMIZE:
             client->frame->max_hover = TRUE;
+            if (e->xcrossing.mode == NotifyUngrab)
+                client->frame->max_press = (con == pcon);
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_ALLDESKTOPS:
             client->frame->desk_hover = TRUE;
+            if (e->xcrossing.mode == NotifyUngrab)
+                client->frame->desk_press = (con == pcon);
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_SHADE:
             client->frame->shade_hover = TRUE;
+            if (e->xcrossing.mode == NotifyUngrab)
+                client->frame->shade_press = (con == pcon);
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_ICONIFY:
             client->frame->iconify_hover = TRUE;
+            if (e->xcrossing.mode == NotifyUngrab)
+                client->frame->iconify_press = (con == pcon);
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_CLOSE:
             client->frame->close_hover = TRUE;
+            if (e->xcrossing.mode == NotifyUngrab)
+                client->frame->close_press = (con == pcon);
             frame_adjust_state(client->frame);
             break;
         case OB_FRAME_CONTEXT_FRAME:
@@ -1369,7 +1399,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
                 ob_debug_type(OB_DEBUG_APP_BUGS,
                               "_NET_ACTIVE_WINDOW message for window %s is "
                               "missing source indication");
-            client_activate(client, FALSE, TRUE, TRUE,
+            client_activate(client, TRUE, TRUE, TRUE,
                             (e->xclient.data.l[0] == 0 ||
                              e->xclient.data.l[0] == 2));
         } else if (msgtype == OBT_PROP_ATOM(NET_WM_MOVERESIZE)) {
@@ -1701,7 +1731,7 @@ static gboolean event_handle_menu_input(XEvent *ev)
 {
     gboolean ret = FALSE;
 
-    if (ev->type == ButtonRelease) {
+    if (ev->type == ButtonRelease || ev->type == ButtonPress) {
         ObMenuEntryFrame *e;
 
         if (menu_hide_delay_reached() &&
@@ -1710,10 +1740,13 @@ static gboolean event_handle_menu_input(XEvent *ev)
             if ((e = menu_entry_frame_under(ev->xbutton.x_root,
                                             ev->xbutton.y_root)))
             {
+                if (ev->type == ButtonPress && e->frame->child)
+                    menu_frame_select(e->frame->child, NULL, TRUE);
                 menu_frame_select(e->frame, e, TRUE);
-                menu_entry_frame_execute(e, ev->xbutton.state);
+                if (ev->type == ButtonRelease)
+                    menu_entry_frame_execute(e, ev->xbutton.state);
             }
-            else
+            else if (ev->type == ButtonRelease)
                 menu_frame_hide_all();
         }
         ret = TRUE;