]> Dogcows Code - chaz/openbox/blobdiff - openbox/slit.c
grab button events on the slit so they dont go through to root
[chaz/openbox] / openbox / slit.c
index 98eb010e8b4047072b5e5779a56070cb3228738a..a5d8be3b6666188845ef4fc0d8658f112b3f6502 100644 (file)
@@ -1,10 +1,13 @@
 #include "slit.h"
 #include "screen.h"
+#include "grab.h"
+#include "timer.h"
 #include "openbox.h"
 #include "render/theme.h"
 #include "render/render.h"
 
-#define SLIT_EVENT_MASK (EnterNotifyMask | LeaveNotifyMask)
+#define SLIT_EVENT_MASK (ButtonPressMask | ButtonReleaseMask | \
+                         EnterWindowMask | LeaveWindowMask)
 #define SLITAPP_EVENT_MASK (StructureNotifyMask)
 
 struct Slit {
@@ -25,6 +28,8 @@ struct Slit {
 
     Appearance *a_frame;
 
+    Timer *hide_timer;
+
     GList *slit_apps;
 };
 
@@ -34,6 +39,8 @@ GHashTable *slit_app_map = NULL;
 static Slit *slit;
 static int nslits;
 
+static guint slit_hide_timeout = 3000; /* XXX make a config option */
+
 static void slit_configure(Slit *self);
 
 void slit_startup()
@@ -49,14 +56,16 @@ void slit_startup()
 
     for (i = 0; i < nslits; ++i) {
         slit[i].horz = FALSE;
-        slit[i].hide = TRUE;
-        slit[i].hidden = FALSE;
+        slit[i].hide = FALSE;
+        slit[i].hidden = TRUE;
         slit[i].pos = SlitPos_TopRight;
 
+        attrib.event_mask = SLIT_EVENT_MASK;
         attrib.override_redirect = True;
         slit[i].frame = XCreateWindow(ob_display, ob_root, 0, 0, 1, 1, 0,
                                       render_depth, InputOutput, render_visual,
-                                      CWOverrideRedirect, &attrib);
+                                      CWOverrideRedirect | CWEventMask,
+                                      &attrib);
         slit[i].a_frame = appearance_copy(theme_a_unfocused_title);
         XSetWindowBorder(ob_display, slit[i].frame, theme_b_color->pixel);
         XSetWindowBorderWidth(ob_display, slit[i].frame, theme_bwidth);
@@ -78,10 +87,11 @@ void slit_shutdown()
     g_hash_table_destroy(slit_map);
 }
 
-void slit_add(Window win, XWMHints *wmhints, XWindowAttributes *attrib)
+void slit_add(Window win, XWMHints *wmhints)
 {
     Slit *s;
     SlitApp *app;
+    XWindowAttributes attrib;
 
     /* XXX pick a slit */
     s = &slit[0];
@@ -92,8 +102,12 @@ void slit_add(Window win, XWMHints *wmhints, XWindowAttributes *attrib)
     app->icon_win = (wmhints->flags & IconWindowHint) ?
         wmhints->icon_window : win;
     
-    app->w = attrib->width;
-    app->h = attrib->height;
+    if (XGetWindowAttributes(ob_display, app->icon_win, &attrib)) {
+        app->w = attrib.width;
+        app->h = attrib.height;
+    } else {
+        app->w = app->h = 64;
+    }
 
     s->slit_apps = g_list_append(s->slit_apps, app);
     slit_configure(s);
@@ -114,7 +128,6 @@ void slit_add(Window win, XWMHints *wmhints, XWindowAttributes *attrib)
         XMoveWindow(ob_display, app->win, -1000, -1000);
         XMapWindow(ob_display, app->win);
     }
-    g_message("   Slitting 0x%lx 0x%lx", app->icon_win, app->win);
     XMapWindow(ob_display, app->icon_win);
     XSync(ob_display, False);
 
@@ -123,6 +136,9 @@ void slit_add(Window win, XWMHints *wmhints, XWindowAttributes *attrib)
     XChangeSaveSet(ob_display, app->icon_win, SetModeInsert);
     XSelectInput(ob_display, app->icon_win, SLITAPP_EVENT_MASK);
 
+    grab_button_full(2, 0, app->icon_win, ButtonMotionMask, GrabModeAsync,
+                     ob_cursors.move);
+
     g_hash_table_insert(slit_app_map, &app->icon_win, app);
 
     g_message("Managed Slit App: 0x%lx", app->icon_win);
@@ -139,6 +155,7 @@ void slit_remove_all()
 
 void slit_remove(SlitApp *app, gboolean reparent)
 {
+    ungrab_button(2, 0, app->icon_win);
     XSelectInput(ob_display, app->icon_win, NoEventMask);
     /* remove the window from our save set */
     XChangeSaveSet(ob_display, app->icon_win, SetModeDelete);
@@ -180,7 +197,7 @@ static void slit_configure(Slit *self)
         } else {
             app->x = 0;
             app->y = spot;
-            self->w = MAX(self->h, app->w);
+            self->w = MAX(self->w, app->w);
             self->h += app->h;
             spot += app->h;
         }
@@ -322,6 +339,10 @@ static void slit_configure(Slit *self)
         XMapWindow(ob_display, self->frame);
     } else
         XUnmapWindow(ob_display, self->frame);
+
+    /* but they are useful outside of this function! */
+    self->w += theme_bwidth * 2;
+    self->h += theme_bwidth * 2;
 }
 
 void slit_app_configure(SlitApp *app, int w, int h)
@@ -330,3 +351,93 @@ void slit_app_configure(SlitApp *app, int w, int h)
     app->h = h;
     slit_configure(app->slit);
 }
+
+void slit_app_drag(SlitApp *app, XMotionEvent *e)
+{
+    Slit *src, *dest = NULL;
+    SlitApp *over = NULL;
+    GList *it;
+    int i;
+    int x, y;
+    gboolean after;
+
+    src = app->slit;
+    x = e->x_root;
+    y = e->y_root;
+
+    /* which slit are we on top of? */
+    for (i = 0; i < nslits; ++i)
+        if (x >= slit[i].x &&
+            y >= slit[i].y &&
+            x < slit[i].x + slit[i].w &&
+            y < slit[i].y + slit[i].h) {
+            dest = &slit[i];
+            break;
+        }
+    if (!dest) return;
+
+    x -= dest->x;
+    y -= dest->y;
+
+    /* which slit app are we on top of? */
+    for (it = dest->slit_apps; it; it = it->next) {
+        over = it->data;
+        if (dest->horz) {
+            if (x >= over->x && x < over->x + over->w)
+                break;
+        } else {
+            if (y >= over->y && y < over->y + over->h)
+                break;
+        }
+    }
+    if (!it || app == over) return;
+
+    x -= over->x;
+    y -= over->y;
+
+    if (dest->horz)
+        after = (x > over->w / 2);
+    else
+        after = (y > over->h / 2);
+
+    /* remove before doing the it->next! */
+    src->slit_apps = g_list_remove(src->slit_apps, app);
+    if (src != dest) slit_configure(src);
+
+    if (after) it = it->next;
+
+    dest->slit_apps = g_list_insert_before(dest->slit_apps, it, app);
+    slit_configure(dest);
+}
+
+static void hide_timeout(Slit *self)
+{
+    /* dont repeat */
+    timer_stop(self->hide_timer);
+    self->hide_timer = NULL;
+
+    /* hide */
+    self->hidden = TRUE;
+    slit_configure(self);
+}
+
+void slit_hide(Slit *self, gboolean hide)
+{
+    if (self->hidden == hide || !self->hide)
+        return;
+    if (!hide) {
+        /* show */
+        self->hidden = FALSE;
+        slit_configure(self);
+
+        /* if was hiding, stop it */
+        if (self->hide_timer) {
+            timer_stop(self->hide_timer);
+            self->hide_timer = NULL;
+        }
+    } else {
+        g_assert(!self->hide_timer);
+        self->hide_timer = timer_start(slit_hide_timeout * 1000,
+                                       (TimeoutHandler)hide_timeout, self);
+    }
+}
This page took 0.029797 seconds and 4 git commands to generate.