From: Dana Jansens Date: Sun, 11 May 2003 05:15:43 +0000 (+0000) Subject: can drag slit-apps around in the slit X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=ed4f84ac33765eee594ad6771df38768afd842a4;p=chaz%2Fopenbox can drag slit-apps around in the slit --- diff --git a/openbox/event.c b/openbox/event.c index a9eb0fa5..f6090f67 100644 --- a/openbox/event.c +++ b/openbox/event.c @@ -928,6 +928,9 @@ static void event_handle_slit(Slit *s, XEvent *e) static void event_handle_slitapp(SlitApp *app, XEvent *e) { switch (e->type) { + case MotionNotify: + slit_app_drag(app, &e->xmotion); + break; case UnmapNotify: if (app->ignore_unmaps) { app->ignore_unmaps--; diff --git a/openbox/grab.c b/openbox/grab.c index 6af21eb2..656f6eb4 100644 --- a/openbox/grab.c +++ b/openbox/grab.c @@ -96,14 +96,19 @@ void grab_shutdown() while (grab_server(FALSE)); } -void grab_button(guint button, guint state, Window win, guint mask, - int pointer_mode) +void grab_button_full(guint button, guint state, Window win, guint mask, + int pointer_mode, Cursor cursor) { guint i; for (i = 0; i < MASK_LIST_SIZE; ++i) XGrabButton(ob_display, button, state | mask_list[i], win, FALSE, mask, - pointer_mode, GrabModeSync, None, None); + pointer_mode, GrabModeSync, None, cursor); +} + +void grab_button(guint button, guint state, Window win, guint mask) +{ + grab_button_full(button, state, win, mask, GrabModeAsync, None); } void ungrab_button(guint button, guint state, Window win) diff --git a/openbox/grab.h b/openbox/grab.h index 9e1c55d2..04fa690a 100644 --- a/openbox/grab.h +++ b/openbox/grab.h @@ -12,8 +12,9 @@ void grab_pointer(gboolean grab, Cursor cur); void grab_pointer_window(gboolean grab, Cursor cur, Window win); void grab_server(gboolean grab); -void grab_button(guint button, guint state, Window win, guint mask, - int pointer_mode); +void grab_button(guint button, guint state, Window win, guint mask); +void grab_button_full(guint button, guint state, Window win, guint mask, + int pointer_mode, Cursor cursor); void ungrab_button(guint button, guint state, Window win); void grab_key(guint keycode, guint state, int keyboard_mode); diff --git a/openbox/slit.c b/openbox/slit.c index a43edccf..45d14be2 100644 --- a/openbox/slit.c +++ b/openbox/slit.c @@ -1,5 +1,6 @@ #include "slit.h" #include "screen.h" +#include "grab.h" #include "timer.h" #include "openbox.h" #include "render/theme.h" @@ -37,6 +38,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() @@ -52,7 +55,7 @@ void slit_startup() for (i = 0; i < nslits; ++i) { slit[i].horz = FALSE; - slit[i].hide = TRUE; + slit[i].hide = FALSE; slit[i].hidden = TRUE; slit[i].pos = SlitPos_TopRight; @@ -119,7 +122,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); @@ -128,6 +130,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); @@ -144,6 +149,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); @@ -185,7 +191,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; } @@ -327,6 +333,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) @@ -336,6 +346,64 @@ void slit_app_configure(SlitApp *app, int w, int 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 */ @@ -349,7 +417,7 @@ static void hide_timeout(Slit *self) void slit_hide(Slit *self, gboolean hide) { - if (self->hidden == hide) + if (self->hidden == hide || !self->hide) return; if (!hide) { /* show */ @@ -363,7 +431,7 @@ void slit_hide(Slit *self, gboolean hide) } } else { g_assert(!self->hide_timer); - self->hide_timer = timer_start(3000000, + self->hide_timer = timer_start(slit_hide_timeout * 1000, (TimeoutHandler)hide_timeout, self); } } diff --git a/openbox/slit.h b/openbox/slit.h index ded94621..0d4ffa93 100644 --- a/openbox/slit.h +++ b/openbox/slit.h @@ -45,6 +45,7 @@ void slit_add(Window win, XWMHints *wmhints, XWindowAttributes *attrib); void slit_remove_all(); void slit_remove(SlitApp *app, gboolean reparent); +void slit_app_drag(SlitApp *app, XMotionEvent *e); void slit_app_configure(SlitApp *app, int w, int h); #endif diff --git a/plugins/mouse/mouse.c b/plugins/mouse/mouse.c index 8df8e2a0..0d0b8fd9 100644 --- a/plugins/mouse/mouse.c +++ b/plugins/mouse/mouse.c @@ -72,7 +72,7 @@ static void grab_for_client(Client *client, gboolean grab) } else continue; if (grab) - grab_button(b->button, b->state, win, mask, mode); + grab_button_full(b->button, b->state, win, mask, mode, None); else ungrab_button(b->button, b->state, win); }