X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fscreen.c;h=6c9042a99edb1b3b51d10a6cbb5ecbea60b9c95d;hb=c90da6da781932c2d178bfb7e39ec1d5003543b7;hp=b312aba9b73d443b3305187871b5e3c6a7f0d6ca;hpb=950516124f49000bd8df0481df0c54a14a05b7f9;p=chaz%2Fopenbox diff --git a/openbox/screen.c b/openbox/screen.c index b312aba9..6c9042a9 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -4,12 +4,14 @@ #include "xerror.h" #include "prop.h" #include "startup.h" +#include "grab.h" #include "timer.h" #include "config.h" #include "screen.h" #include "client.h" #include "frame.h" #include "focus.h" +#include "popup.h" #include "dispatch.h" #include "extensions.h" #include "render/render.h" @@ -24,6 +26,7 @@ # include # include #endif +#include /*! The event mask to grab on the root window */ #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \ @@ -43,6 +46,8 @@ Window screen_support_win; static Rect **area; /* array of desktop holding array of xinerama areas */ static Rect *monitor_area; +static Popup *desktop_cycle_popup; + #ifdef USE_LIBSN static SnMonitorContext *sn_context; static int sn_busy_cnt; @@ -274,6 +279,8 @@ void screen_startup() GSList *it; guint i; + desktop_cycle_popup = popup_new(FALSE); + /* get the initial size */ screen_resize(); @@ -313,6 +320,8 @@ void screen_shutdown() { Rect **r; + popup_free(desktop_cycle_popup); + XSelectInput(ob_display, RootWindow(ob_display, ob_screen), NoEventMask); /* we're not running here no more! */ @@ -353,8 +362,8 @@ void screen_resize() if (ob_state() == OB_STATE_STARTING) return; - dock_configure(); screen_update_areas(); + dock_configure(); for (it = client_list; it; it = it->next) client_move_onscreen(it->data, FALSE); @@ -463,6 +472,247 @@ void screen_set_desktop(guint num) dispatch_ob(Event_Ob_Desktop, num, old); } +static void get_row_col(guint d, guint *r, guint *c) +{ + switch (screen_desktop_layout.orientation) { + case OB_ORIENTATION_HORZ: + switch (screen_desktop_layout.start_corner) { + case OB_CORNER_TOPLEFT: + *r = d / screen_desktop_layout.columns; + *c = d % screen_desktop_layout.columns; + break; + case OB_CORNER_BOTTOMLEFT: + *r = screen_desktop_layout.rows - 1 - + d / screen_desktop_layout.columns; + *c = d % screen_desktop_layout.columns; + break; + case OB_CORNER_TOPRIGHT: + *r = d / screen_desktop_layout.columns; + *c = screen_desktop_layout.columns - 1 - + d % screen_desktop_layout.columns; + break; + case OB_CORNER_BOTTOMRIGHT: + *r = screen_desktop_layout.rows - 1 - + d / screen_desktop_layout.columns; + *c = screen_desktop_layout.columns - 1 - + d % screen_desktop_layout.columns; + break; + } + break; + case OB_ORIENTATION_VERT: + switch (screen_desktop_layout.start_corner) { + case OB_CORNER_TOPLEFT: + *r = d % screen_desktop_layout.rows; + *c = d / screen_desktop_layout.rows; + break; + case OB_CORNER_BOTTOMLEFT: + *r = screen_desktop_layout.rows - 1 - + d % screen_desktop_layout.rows; + *c = d / screen_desktop_layout.rows; + break; + case OB_CORNER_TOPRIGHT: + *r = d % screen_desktop_layout.rows; + *c = screen_desktop_layout.columns - 1 - + d / screen_desktop_layout.rows; + break; + case OB_CORNER_BOTTOMRIGHT: + *r = screen_desktop_layout.rows - 1 - + d % screen_desktop_layout.rows; + *c = screen_desktop_layout.columns - 1 - + d / screen_desktop_layout.rows; + break; + } + break; + } +} + +static guint translate_row_col(guint r, guint c) +{ + switch (screen_desktop_layout.orientation) { + case OB_ORIENTATION_HORZ: + switch (screen_desktop_layout.start_corner) { + case OB_CORNER_TOPLEFT: + return r % screen_desktop_layout.rows * + screen_desktop_layout.columns + + c % screen_desktop_layout.columns; + case OB_CORNER_BOTTOMLEFT: + return (screen_desktop_layout.rows - 1 - + r % screen_desktop_layout.rows) * + screen_desktop_layout.columns + + c % screen_desktop_layout.columns; + case OB_CORNER_TOPRIGHT: + return r % screen_desktop_layout.rows * + screen_desktop_layout.columns + + (screen_desktop_layout.columns - 1 - + c % screen_desktop_layout.columns); + case OB_CORNER_BOTTOMRIGHT: + return (screen_desktop_layout.rows - 1 - + r % screen_desktop_layout.rows) * + screen_desktop_layout.columns + + (screen_desktop_layout.columns - 1 - + c % screen_desktop_layout.columns); + } + case OB_ORIENTATION_VERT: + switch (screen_desktop_layout.start_corner) { + case OB_CORNER_TOPLEFT: + return c % screen_desktop_layout.columns * + screen_desktop_layout.rows + + r % screen_desktop_layout.rows; + case OB_CORNER_BOTTOMLEFT: + return c % screen_desktop_layout.columns * + screen_desktop_layout.rows + + (screen_desktop_layout.rows - 1 - + r % screen_desktop_layout.rows); + case OB_CORNER_TOPRIGHT: + return (screen_desktop_layout.columns - 1 - + c % screen_desktop_layout.columns) * + screen_desktop_layout.rows + + r % screen_desktop_layout.rows; + case OB_CORNER_BOTTOMRIGHT: + return (screen_desktop_layout.columns - 1 - + c % screen_desktop_layout.columns) * + screen_desktop_layout.rows + + (screen_desktop_layout.rows - 1 - + r % screen_desktop_layout.rows); + } + } + g_assert_not_reached(); + return 0; +} + +static void popup_cycle(guint d, gboolean show) +{ + Rect *a; + + if (!show) { + popup_hide(desktop_cycle_popup); + } else { + a = screen_physical_area_monitor(0); + popup_position(desktop_cycle_popup, CenterGravity, + a->x + a->width / 2, a->y + a->height / 2); + /* XXX the size and the font extents need to be related on some level + */ + popup_size(desktop_cycle_popup, POPUP_WIDTH, POPUP_HEIGHT); + + popup_set_text_align(desktop_cycle_popup, RR_JUSTIFY_CENTER); + + popup_show(desktop_cycle_popup, + screen_desktop_names[d], NULL); + } +} + +guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear, + gboolean done, gboolean cancel) +{ + static gboolean first = TRUE; + static gboolean lin; + static guint origd, d; + guint r, c; + + if (cancel) { + d = origd; + goto done_cycle; + } else if (done) { + screen_set_desktop(d); + goto done_cycle; + } + if (first) { + first = FALSE; + lin = linear; + d = origd = screen_desktop; + } + + get_row_col(d, &r, &c); + + if (lin) { + g_message("linear %d", d); + switch (dir) { + case OB_DIRECTION_EAST: + if (d < screen_num_desktops - 1) + ++d; + else if (wrap) + d = 0; + break; + case OB_DIRECTION_WEST: + if (d > 0) + --d; + else if (wrap) + d = screen_num_desktops - 1; + break; + default: + assert(0); + return screen_desktop; + } + g_message("linear %d done", d); + } else { + switch (dir) { + case OB_DIRECTION_EAST: + ++c; + if (c >= screen_desktop_layout.columns) { + if (!wrap) return d = screen_desktop; + c = 0; + } + d = translate_row_col(r, c); + if (d >= screen_num_desktops) { + if (!wrap) return d = screen_desktop; + ++c; + } + break; + case OB_DIRECTION_WEST: + --c; + if (c >= screen_desktop_layout.columns) { + if (!wrap) return d = screen_desktop; + c = screen_desktop_layout.columns - 1; + } + d = translate_row_col(r, c); + if (d >= screen_num_desktops) { + if (!wrap) return d = screen_desktop; + --c; + } + break; + case OB_DIRECTION_SOUTH: + ++r; + if (r >= screen_desktop_layout.rows) { + if (!wrap) return d = screen_desktop; + r = 0; + } + d = translate_row_col(r, c); + if (d >= screen_num_desktops) { + if (!wrap) return d = screen_desktop; + ++r; + } + break; + case OB_DIRECTION_NORTH: + --r; + if (r >= screen_desktop_layout.rows) { + if (!wrap) return d = screen_desktop; + r = screen_desktop_layout.rows - 1; + } + d = translate_row_col(r, c); + if (d >= screen_num_desktops) { + if (!wrap) return d = screen_desktop; + --r; + } + break; + default: + assert(0); + return d = screen_desktop; + } + + d = translate_row_col(r, c); + } + + popup_cycle(d, TRUE); + return d; + +done_cycle: + first = TRUE; + + popup_cycle(0, FALSE); + + return d = screen_desktop; +} + void screen_update_layout() { ObOrientation orient; @@ -487,7 +737,9 @@ void screen_update_layout() if (num < 4) corner = OB_CORNER_TOPLEFT; else { - if (data[3] == prop_atoms.net_wm_topright) + if (data[3] == prop_atoms.net_wm_topleft) + corner = OB_CORNER_TOPLEFT; + else if (data[3] == prop_atoms.net_wm_topright) corner = OB_CORNER_TOPRIGHT; else if (data[3] == prop_atoms.net_wm_bottomright) corner = OB_CORNER_BOTTOMRIGHT; @@ -637,8 +889,6 @@ void screen_update_areas() { guint i, x; guint32 *dims; - Rect **old_area = area; - Rect **rit; GList *it; g_free(monitor_area); @@ -657,7 +907,6 @@ void screen_update_areas() dims = g_new(guint32, 4 * screen_num_desktops); - rit = old_area; for (i = 0; i < screen_num_desktops + 1; ++i) { Strut s; int l, r, t, b; @@ -800,7 +1049,7 @@ void screen_update_areas() } } PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal, - dims, 4 * screen_num_desktops); + dims, 4 * screen_num_desktops); g_free(dims); } @@ -847,7 +1096,7 @@ static void set_root_cursor() } #ifdef USE_LIBSN -static void sn_timeout(void *data) +static void sn_timeout(ObTimer *t, void *data) { timer_stop(sn_timer); sn_timer = NULL;