Skip to content

Commit

Permalink
adding the "greedy" desktop switch option
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Gallant (Ocelot) authored and Andrew Gallant (Ocelot) committed Aug 10, 2011
1 parent 1fd1ab6 commit b0cefe8
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 37 deletions.
2 changes: 1 addition & 1 deletion openbox/actions/desktop.c
Expand Up @@ -302,7 +302,7 @@ static gboolean run_func(ObActionsData *data, gpointer options)
}

if (go) {
screen_set_desktop(d, TRUE);
screen_set_desktop(d, TRUE, FALSE);
if (data->client)
client_bring_helper_windows(data->client);
}
Expand Down
2 changes: 1 addition & 1 deletion openbox/actions/moverelative.c
Expand Up @@ -76,7 +76,7 @@ static gboolean run_func(ObActionsData *data, gpointer options)
client_find_onscreen(c, &x, &y, w, h, FALSE);

actions_client_move(data, TRUE);
client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
client_configure(c, x, y, w, h, TRUE, TRUE, FALSE, FALSE);
actions_client_move(data, FALSE);
}

Expand Down
2 changes: 1 addition & 1 deletion openbox/actions/moveresizeto.c
Expand Up @@ -164,7 +164,7 @@ static gboolean run_func(ObActionsData *data, gpointer options)
client_find_onscreen(c, &x, &y, w, h, mon != cmon);

actions_client_move(data, TRUE);
client_configure(c, x, y, w, h, TRUE, TRUE, FALSE);
client_configure(c, x, y, w, h, TRUE, TRUE, FALSE, FALSE);
actions_client_move(data, FALSE);

g_slice_free(Rect, area);
Expand Down
24 changes: 13 additions & 11 deletions openbox/client.c
Expand Up @@ -2669,7 +2669,7 @@ gboolean client_show(ObClient *self)
gint cur_mon;

if ((cur_mon = g_slist_index(screen_visible_desktops, self->desktop)) > -1)
client_set_monitor(self, cur_mon);
client_set_monitor(self, cur_mon, FALSE);

if (client_should_show(self)) {
/* replay pending pointer event before showing the window, in case it
Expand Down Expand Up @@ -2825,7 +2825,7 @@ static void client_apply_startup_state(ObClient *self,
not, so this needs to be called even if we have fullscreened/maxed
*/
self->area = oldarea;
client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
client_configure(self, x, y, w, h, FALSE, TRUE, FALSE, FALSE);

/* nothing to do for the other states:
skip_taskbar
Expand Down Expand Up @@ -3079,7 +3079,8 @@ void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
}

void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
gboolean user, gboolean final, gboolean force_reply)
gboolean user, gboolean final, gboolean force_reply,
gboolean ignore_monitor)
{
Rect oldframe, oldclient;
gboolean send_resize_client;
Expand Down Expand Up @@ -3230,7 +3231,7 @@ void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
if (self->managed) {
guint oldm, newm, newdesk;

if(client_normal(self)) {
if(client_normal(self) && !ignore_monitor) {
oldm = screen_find_monitor(&oldframe);
newm = screen_find_monitor(&self->frame->area);

Expand Down Expand Up @@ -3455,12 +3456,12 @@ void client_maximize(ObClient *self, gboolean max, gint dir)
RECT_SET(*area, x, y, w, h);
desk_mon = g_slist_index(screen_visible_desktops, self->desktop);

ob_debug(OB_DEBUG_MULTIHEAD, "unmaximizing window %s", self->title);
ob_debug(OB_DEBUG_MULTIHEAD, "\tit wants to go to monitor %d",
ob_debug_type(OB_DEBUG_MULTIHEAD, "unmaximizing window %s", self->title);
ob_debug_type(OB_DEBUG_MULTIHEAD, "\tit wants to go to monitor %d",
screen_find_monitor(area));
ob_debug(OB_DEBUG_MULTIHEAD, "\tbut it should be on monitor %d",
ob_debug_type(OB_DEBUG_MULTIHEAD, "\tbut it should be on monitor %d",
desk_mon);
ob_debug(OB_DEBUG_MULTIHEAD, "\tmoreover, it claims it's on %d",
ob_debug_type(OB_DEBUG_MULTIHEAD, "\tmoreover, it claims it's on %d",
client_monitor(self));

if (screen_find_monitor(area) != desk_mon)
Expand Down Expand Up @@ -4050,7 +4051,7 @@ static void client_present(ObClient *self, gboolean here, gboolean raise,
if (here)
client_set_desktop(self, screen_desktop, FALSE, TRUE);
else {
screen_set_desktop(self->desktop, FALSE);
screen_set_desktop(self->desktop, FALSE, TRUE);
}
}
else if (!self->frame->visible)
Expand Down Expand Up @@ -4167,11 +4168,12 @@ guint client_monitor(ObClient *self)
return screen_find_monitor(&self->frame->area);
}

gboolean client_set_monitor(ObClient *self, guint new_mon)
gboolean client_set_monitor(ObClient *self, guint new_mon,
gboolean ignore_monitor)
{
guint x, y, w, h;
if(place_client_onscreen(self, new_mon, &x, &y, &w, &h)) {
client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
client_configure(self, x, y, w, h, FALSE, TRUE, FALSE, ignore_monitor);
return TRUE;
}

Expand Down
15 changes: 9 additions & 6 deletions openbox/client.h
Expand Up @@ -397,15 +397,16 @@ void client_convert_gravity_resize(ObClient *self, gint gravity,

#define client_move(self, x, y) \
client_configure(self, x, y, self->area.width, self->area.height, TRUE, TRUE,\
FALSE)
FALSE, FALSE)
#define client_resize(self, w, h) \
client_configure(self, self->area.x, self->area.y, w, h, TRUE, TRUE, FALSE)
client_configure(self, self->area.x, self->area.y, w, h, TRUE, TRUE, FALSE,\
FALSE)
#define client_move_resize(self, x, y, w, h) \
client_configure(self, x, y, w, h, TRUE, TRUE, FALSE)
client_configure(self, x, y, w, h, TRUE, TRUE, FALSE, FALSE)
#define client_reconfigure(self, force) \
client_configure(self, ((ObClient*)self)->area.x, ((ObClient*)self)->area.y, \
((ObClient*)self)->area.width, \
((ObClient*)self)->area.height, FALSE, TRUE, force)
((ObClient*)self)->area.height, FALSE, TRUE, force, FALSE)

/*! Figure out where a window will end up and what size it will be if you
told it to move/resize to these coordinates.
Expand Down Expand Up @@ -447,7 +448,8 @@ void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
the position/size changed.
*/
void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
gboolean user, gboolean final, gboolean force_reply);
gboolean user, gboolean final, gboolean force_reply,
gboolean ignore_monitor);

/*! Finds coordinates to keep a client on the screen.
@param self The client
Expand Down Expand Up @@ -741,7 +743,8 @@ void client_set_layer(ObClient *self, gint layer);

guint client_monitor(ObClient *self);

gboolean client_set_monitor(ObClient *self, guint monitor);
gboolean client_set_monitor(ObClient *self, guint monitor,
gboolean ignore_monitor);

ObClient* client_under_pointer(void);

Expand Down
4 changes: 2 additions & 2 deletions openbox/client_list_combined_menu.c
Expand Up @@ -127,10 +127,10 @@ static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
/* if the window is omnipresent then we need to go to its
desktop */
if (!here && t->desktop == DESKTOP_ALL)
screen_set_desktop(self->id, FALSE);
screen_set_desktop(self->id, FALSE, FALSE);
}
else
screen_set_desktop(self->id, TRUE);
screen_set_desktop(self->id, TRUE, FALSE);
}
}

Expand Down
4 changes: 2 additions & 2 deletions openbox/client_list_menu.c
Expand Up @@ -106,10 +106,10 @@ static void desk_menu_execute(ObMenuEntry *self, ObMenuFrame *f,
/* if the window is omnipresent then we need to go to its
desktop */
if (!here && t->desktop == DESKTOP_ALL)
screen_set_desktop(self->id, FALSE);
screen_set_desktop(self->id, FALSE, FALSE);
}
else
screen_set_desktop(self->id, TRUE);
screen_set_desktop(self->id, TRUE, FALSE);
}

static void desk_menu_destroy(ObMenu *menu, gpointer data)
Expand Down
12 changes: 8 additions & 4 deletions openbox/config.c
Expand Up @@ -61,10 +61,11 @@ RrFont *config_font_menutitle;
RrFont *config_font_activeosd;
RrFont *config_font_inactiveosd;

guint config_desktops_num;
GSList *config_desktops_names;
guint config_screen_firstdesk;
guint config_desktop_popup_time;
guint config_desktops_num;
GSList *config_desktops_names;
guint config_screen_firstdesk;
guint config_desktop_popup_time;
gboolean config_desktop_greedy;

gboolean config_resize_redraw;
gint config_resize_popup_show;
Expand Down Expand Up @@ -741,6 +742,8 @@ static void parse_desktops(xmlNodePtr node, gpointer d)
}
if ((n = obt_xml_find_node(node, "popupTime")))
config_desktop_popup_time = obt_xml_node_int(n);
if ((n = obt_xml_find_node(node, "greedy")))
config_desktop_greedy = obt_xml_node_bool(n);
}

static void parse_resize(xmlNodePtr node, gpointer d)
Expand Down Expand Up @@ -1040,6 +1043,7 @@ void config_startup(ObtXmlInst *i)
config_screen_firstdesk = 1;
config_desktops_names = NULL;
config_desktop_popup_time = 875;
config_desktop_greedy = 0;

obt_xml_register(i, "desktops", parse_desktops, NULL);

Expand Down
4 changes: 4 additions & 0 deletions openbox/config.h
Expand Up @@ -168,6 +168,10 @@ extern guint config_screen_firstdesk;
extern GSList *config_desktops_names;
/*! Amount of time to show the desktop switch dialog */
extern guint config_desktop_popup_time;
/*! Whether to replace the next desktop with the current one
* if the next desktop is already visible
*/
extern gboolean config_desktop_greedy;

/*! The keycode of the key combo which resets the keybaord chains */
extern guint config_keyboard_reset_keycode;
Expand Down
8 changes: 4 additions & 4 deletions openbox/event.c
Expand Up @@ -761,7 +761,7 @@ static void event_handle_root(XEvent *e)
"a timestamp");
else
event_sourcetime = e->xclient.data.l[1];
screen_set_desktop(d, TRUE);
screen_set_desktop(d, TRUE, FALSE);
}
} else if (msgtype == OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS)) {
guint d = e->xclient.data.l[0];
Expand Down Expand Up @@ -1337,7 +1337,7 @@ static void event_handle_client(ObClient *client, XEvent *e)

ob_debug("Granting ConfigureRequest x %d y %d w %d h %d",
x, y, w, h);
client_configure(client, x, y, w, h, FALSE, TRUE, TRUE);
client_configure(client, x, y, w, h, FALSE, TRUE, TRUE, FALSE);
}
break;
}
Expand Down Expand Up @@ -1534,7 +1534,7 @@ static void event_handle_client(ObClient *client, XEvent *e)

client_find_onscreen(client, &x, &y, w, h, FALSE);

client_configure(client, x, y, w, h, FALSE, TRUE, FALSE);
client_configure(client, x, y, w, h, FALSE, TRUE, FALSE, FALSE);

client->gravity = ograv;
} else if (msgtype == OBT_PROP_ATOM(NET_RESTACK_WINDOW)) {
Expand Down Expand Up @@ -1626,7 +1626,7 @@ static void event_handle_client(ObClient *client, XEvent *e)
make it reply with a configurenotify unless something changed.
emacs will update its normal hints every time it receives a
configurenotify */
client_configure(client, x, y, w, h, FALSE, TRUE, FALSE);
client_configure(client, x, y, w, h, FALSE, TRUE, FALSE, FALSE);
} else if (msgtype == OBT_PROP_ATOM(MOTIF_WM_HINTS)) {
client_get_mwm_hints(client);
/* This can override some mwm hints */
Expand Down
8 changes: 4 additions & 4 deletions openbox/moveresize.c
Expand Up @@ -335,7 +335,7 @@ void moveresize_end(gboolean cancel)
(cancel ? start_cy : cur_y),
(cancel ? start_cw : cur_w),
(cancel ? start_ch : cur_h),
TRUE, TRUE, FALSE);
TRUE, TRUE, FALSE, FALSE);

/* restore the client's maximized state. do this after putting the window
back in its original spot to minimize visible flicker */
Expand Down Expand Up @@ -377,7 +377,7 @@ static void do_move(gboolean keyboard, gint keydist)
resist_move_monitors(moveresize_client, resist, &cur_x, &cur_y);

client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
TRUE, FALSE, FALSE);
TRUE, FALSE, FALSE, FALSE);
if (config_resize_popup_show == 2) /* == "Always" */
popup_coords(moveresize_client, "%d x %d",
moveresize_client->frame->area.x,
Expand Down Expand Up @@ -444,7 +444,7 @@ static void do_resize(void)
/* force a ConfigureNotify, it is part of the spec for SYNC resizing
and MUST follow the sync counter notification */
client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
TRUE, FALSE, TRUE);
TRUE, FALSE, TRUE, FALSE);
}

/* this would be better with a fixed width font ... XXX can do it better
Expand Down Expand Up @@ -611,7 +611,7 @@ static gboolean edge_warp_delay_func(gpointer data)
d = screen_find_desktop(screen_desktop, edge_warp_dir, TRUE, FALSE);
if (d != screen_desktop) {
if (config_mouse_screenedgewarp) edge_warp_move_ptr();
screen_set_desktop(d, TRUE);
screen_set_desktop(d, TRUE, FALSE);
}
}
edge_warp_odd = !edge_warp_odd;
Expand Down
3 changes: 2 additions & 1 deletion openbox/screen.h
Expand Up @@ -70,7 +70,8 @@ void screen_set_num_desktops(guint num);
/*! Store the current desktop (and update _NET_CURRENT_DESKTOP) */
gboolean screen_store_desktop(guint num);
/*! Change the current desktop */
void screen_set_desktop(guint num, gboolean dofocus);
void screen_set_desktop(guint num, gboolean dofocus,
gboolean force_no_greedy);
/*! Add a new desktop either at the end or inserted at the current desktop */
void screen_add_desktop(gboolean current);
/*! Remove a desktop, either at the end or the current desktop */
Expand Down

0 comments on commit b0cefe8

Please sign in to comment.