+ if (event_curtime != CurrentTime)
+ screen_desktop_user_time = event_curtime;
+}
+
+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;
+}
+
+void screen_desktop_popup(guint d, gboolean show)
+{
+ Rect *a;
+
+ if (!show) {
+ pager_popup_hide(desktop_cycle_popup);
+ } else {
+ a = screen_physical_area_monitor(0);
+ pager_popup_position(desktop_cycle_popup, CenterGravity,
+ a->x + a->width / 2, a->y + a->height / 2);
+ pager_popup_icon_size_multiplier(desktop_cycle_popup,
+ (screen_desktop_layout.columns /
+ screen_desktop_layout.rows) / 2,
+ (screen_desktop_layout.rows/
+ screen_desktop_layout.columns) / 2);
+ pager_popup_max_width(desktop_cycle_popup,
+ MAX(a->width/3, POPUP_WIDTH));
+ pager_popup_show(desktop_cycle_popup, screen_desktop_names[d], d);
+ }
+}
+
+guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
+ gboolean dialog, gboolean done, gboolean cancel)
+{
+ guint r, c;
+ static guint d = (guint)-1;
+ guint ret, oldd;
+
+ if (d == (guint)-1)
+ d = screen_desktop;
+
+ if ((cancel || done) && dialog)
+ goto show_cycle_dialog;
+
+ oldd = d;
+ get_row_col(d, &r, &c);
+
+ if (linear) {
+ 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;
+ }
+ } else {
+ switch (dir) {
+ case OB_DIRECTION_EAST:
+ ++c;
+ if (c >= screen_desktop_layout.columns) {
+ if (wrap)
+ c = 0;
+ else
+ goto show_cycle_dialog;
+ }
+ d = translate_row_col(r, c);
+ if (d >= screen_num_desktops) {
+ if (wrap) {
+ ++c;
+ } else {
+ d = oldd;
+ goto show_cycle_dialog;
+ }
+ }
+ break;
+ case OB_DIRECTION_WEST:
+ --c;
+ if (c >= screen_desktop_layout.columns) {
+ if (wrap)
+ c = screen_desktop_layout.columns - 1;
+ else
+ goto show_cycle_dialog;
+ }
+ d = translate_row_col(r, c);
+ if (d >= screen_num_desktops) {
+ if (wrap) {
+ --c;
+ } else {
+ d = oldd;
+ goto show_cycle_dialog;
+ }
+ }
+ break;
+ case OB_DIRECTION_SOUTH:
+ ++r;
+ if (r >= screen_desktop_layout.rows) {
+ if (wrap)
+ r = 0;
+ else
+ goto show_cycle_dialog;
+ }
+ d = translate_row_col(r, c);
+ if (d >= screen_num_desktops) {
+ if (wrap) {
+ ++r;
+ } else {
+ d = oldd;
+ goto show_cycle_dialog;
+ }
+ }
+ break;
+ case OB_DIRECTION_NORTH:
+ --r;
+ if (r >= screen_desktop_layout.rows) {
+ if (wrap)
+ r = screen_desktop_layout.rows - 1;
+ else
+ goto show_cycle_dialog;
+ }
+ d = translate_row_col(r, c);
+ if (d >= screen_num_desktops) {
+ if (wrap) {
+ --r;
+ } else {
+ d = oldd;
+ goto show_cycle_dialog;
+ }
+ }
+ break;
+ default:
+ assert(0);
+ return d = screen_desktop;
+ }
+
+ d = translate_row_col(r, c);
+ }
+
+show_cycle_dialog:
+ if (dialog && !cancel && !done) {
+ screen_desktop_popup(d, TRUE);
+ } else
+ screen_desktop_popup(0, FALSE);
+ ret = d;
+
+ if (!dialog || cancel || done)
+ d = (guint)-1;
+
+ return ret;