From: Mikael Magnusson Date: Sat, 23 Feb 2008 19:15:34 +0000 (+0100) Subject: Add Lock action. X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=c0777a9c88937cae212152ba81b68f5680492661;p=mikachu%2Fopenbox.git Add Lock action. Allows locking windows so you can't move/resize/close/etc them by mistake. It's probably better to check in client.c than the actions, just testing if I want it at all for now. --- diff --git a/Makefile.am b/Makefile.am index f7b09dd9..6005306c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -218,6 +218,7 @@ openbox_openbox_SOURCES = \ openbox/actions/if.c \ openbox/actions/kill.c \ openbox/actions/layer.c \ + openbox/actions/lock.c \ openbox/actions/lower.c \ openbox/actions/maximize.c \ openbox/actions/move.c \ diff --git a/openbox/actions.c b/openbox/actions.c index bf00c6c8..fa8ba24c 100644 --- a/openbox/actions.c +++ b/openbox/actions.c @@ -502,3 +502,10 @@ void actions_client_move(ObActionsData *data, gboolean start) event_end_ignore_all_enters(ignore_start); } } + +gboolean actions_client_locked(ObActionsData *data) +{ + ObClient *c = data->client; + + return c && c->locked; +} diff --git a/openbox/actions.h b/openbox/actions.h index f8e1ba83..031c67fe 100644 --- a/openbox/actions.h +++ b/openbox/actions.h @@ -121,3 +121,5 @@ gboolean actions_interactive_input_event(XEvent *e); /*! Function for actions to call when they are moving a client around */ void actions_client_move(ObActionsData *data, gboolean start); +/*! May we do something to this client? */ +gboolean actions_client_locked(ObActionsData *data); diff --git a/openbox/actions/all.c b/openbox/actions/all.c index d445706e..95bae445 100644 --- a/openbox/actions/all.c +++ b/openbox/actions/all.c @@ -42,6 +42,7 @@ void action_all_startup(void) action_if_startup(); action_focustobottom_startup(); action_sendkeyevent_startup(); + action_lock_startup(); /* 3.4-compatibility */ action_shadelowerraise_startup(); } diff --git a/openbox/actions/all.h b/openbox/actions/all.h index 2acff521..ce57207c 100644 --- a/openbox/actions/all.h +++ b/openbox/actions/all.h @@ -43,6 +43,7 @@ void action_growtoedge_startup(void); void action_if_startup(void); void action_focustobottom_startup(void); void action_sendkeyevent_startup(void); +void action_lock_startup(void); /* 3.4-compatibility */ void action_shadelowerraise_startup(void); diff --git a/openbox/actions/close.c b/openbox/actions/close.c index d2bc96c2..0032ac0c 100644 --- a/openbox/actions/close.c +++ b/openbox/actions/close.c @@ -13,7 +13,8 @@ void action_close_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - if (data->client) client_close(data->client); + if (!actions_client_locked(data)) + client_close(data->client); return FALSE; } diff --git a/openbox/actions/decorations.c b/openbox/actions/decorations.c index f6fd2cbe..5d6ea13f 100644 --- a/openbox/actions/decorations.c +++ b/openbox/actions/decorations.c @@ -15,7 +15,7 @@ void action_decorations_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func_on(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_set_undecorated(data->client, FALSE); actions_client_move(data, FALSE); @@ -26,7 +26,7 @@ static gboolean run_func_on(ObActionsData *data, gpointer options) /* Always return FALSE because its not interactive */ static gboolean run_func_off(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_set_undecorated(data->client, TRUE); actions_client_move(data, FALSE); @@ -37,7 +37,7 @@ static gboolean run_func_off(ObActionsData *data, gpointer options) /* Always return FALSE because its not interactive */ static gboolean run_func_toggle(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_set_undecorated(data->client, !data->client->undecorated); actions_client_move(data, FALSE); diff --git a/openbox/actions/desktop.c b/openbox/actions/desktop.c index 8dadf550..87871440 100644 --- a/openbox/actions/desktop.c +++ b/openbox/actions/desktop.c @@ -296,7 +296,9 @@ static gboolean run_func(ObActionsData *data, gpointer options) gboolean go = TRUE; actions_client_move(data, TRUE); - if (o->send && data->client && client_normal(data->client)) { + if (o->send && !actions_client_locked(data) && + client_normal(data->client)) + { client_set_desktop(data->client, d, o->follow, FALSE); go = o->follow; } diff --git a/openbox/actions/growtoedge.c b/openbox/actions/growtoedge.c index acfbcfab..3a9943e8 100644 --- a/openbox/actions/growtoedge.c +++ b/openbox/actions/growtoedge.c @@ -185,7 +185,8 @@ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; - if (!data->client) + if (!data->client || + actions_client_locked(data)) return FALSE; gboolean doing_vertical_resize = diff --git a/openbox/actions/iconify.c b/openbox/actions/iconify.c index d1b754a2..2d1ca751 100644 --- a/openbox/actions/iconify.c +++ b/openbox/actions/iconify.c @@ -25,7 +25,7 @@ static gpointer setup_func(xmlNodePtr node) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_iconify(data->client, !options, FALSE, FALSE); actions_client_move(data, FALSE); diff --git a/openbox/actions/kill.c b/openbox/actions/kill.c index b7d547b9..0e52f6ed 100644 --- a/openbox/actions/kill.c +++ b/openbox/actions/kill.c @@ -13,7 +13,7 @@ void action_kill_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - if (data->client) + if (!actions_client_locked(data)) client_kill(data->client); return FALSE; diff --git a/openbox/actions/layer.c b/openbox/actions/layer.c index ed1eeedc..7b53a6e6 100644 --- a/openbox/actions/layer.c +++ b/openbox/actions/layer.c @@ -83,7 +83,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { ObClient *c = data->client; actions_client_move(data, TRUE); diff --git a/openbox/actions/lock.c b/openbox/actions/lock.c new file mode 100644 index 00000000..1271cbc8 --- /dev/null +++ b/openbox/actions/lock.c @@ -0,0 +1,17 @@ +#include "openbox/actions.h" +#include "openbox/client.h" + +static gboolean run_func(ObActionsData *data, gpointer options); + +void action_lock_startup(void) +{ + actions_register("Lock", NULL, NULL, run_func); +} + +/* Always return FALSE because its not interactive */ +static gboolean run_func(ObActionsData *data, gpointer options) +{ + if (data->client) + data->client->locked = !data->client->locked; + return FALSE; +} diff --git a/openbox/actions/lower.c b/openbox/actions/lower.c index 80ca6b8b..0ad2bb0d 100644 --- a/openbox/actions/lower.c +++ b/openbox/actions/lower.c @@ -14,7 +14,7 @@ void action_lower_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); stacking_lower(CLIENT_AS_WINDOW(data->client)); actions_client_move(data, FALSE); diff --git a/openbox/actions/maximize.c b/openbox/actions/maximize.c index db7c36bb..61495ccf 100644 --- a/openbox/actions/maximize.c +++ b/openbox/actions/maximize.c @@ -79,7 +79,7 @@ static void free_func(gpointer o) static gboolean run_func_on(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_maximize(data->client, TRUE, o->dir); actions_client_move(data, FALSE); @@ -91,7 +91,7 @@ static gboolean run_func_on(ObActionsData *data, gpointer options) static gboolean run_func_off(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_maximize(data->client, FALSE, o->dir); actions_client_move(data, FALSE); @@ -103,7 +103,7 @@ static gboolean run_func_off(ObActionsData *data, gpointer options) static gboolean run_func_toggle(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { gboolean toggle; actions_client_move(data, TRUE); toggle = ((o->dir == HORZ && !data->client->max_horz) || diff --git a/openbox/actions/move.c b/openbox/actions/move.c index ba8372a5..fa13d015 100644 --- a/openbox/actions/move.c +++ b/openbox/actions/move.c @@ -1,4 +1,5 @@ #include "openbox/actions.h" +#include "openbox/client.h" #include "openbox/moveresize.h" #include "obt/prop.h" @@ -14,7 +15,7 @@ void action_move_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - if (data->client) { + if (data->client && !data->client->locked) { guint32 corner; corner = data->button != 0 ? diff --git a/openbox/actions/moverelative.c b/openbox/actions/moverelative.c index b67b5cf1..31b0a6d2 100644 --- a/openbox/actions/moverelative.c +++ b/openbox/actions/moverelative.c @@ -52,7 +52,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { ObClient *c; gint x, y, lw, lh, w, h; diff --git a/openbox/actions/moveresizeto.c b/openbox/actions/moveresizeto.c index 95de0e98..2dbddd54 100644 --- a/openbox/actions/moveresizeto.c +++ b/openbox/actions/moveresizeto.c @@ -99,7 +99,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { Rect *area, *carea; ObClient *c; guint mon, cmon; diff --git a/openbox/actions/movetoedge.c b/openbox/actions/movetoedge.c index ef5b6920..27855179 100644 --- a/openbox/actions/movetoedge.c +++ b/openbox/actions/movetoedge.c @@ -66,7 +66,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { gint x, y; client_find_move_directional(data->client, o->dir, &x, &y); diff --git a/openbox/actions/omnipresent.c b/openbox/actions/omnipresent.c index 4309acc6..20233161 100644 --- a/openbox/actions/omnipresent.c +++ b/openbox/actions/omnipresent.c @@ -12,7 +12,7 @@ void action_omnipresent_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func_toggle(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_set_desktop(data->client, data->client->desktop == DESKTOP_ALL ? diff --git a/openbox/actions/raise.c b/openbox/actions/raise.c index f6ac1452..04b86362 100644 --- a/openbox/actions/raise.c +++ b/openbox/actions/raise.c @@ -12,7 +12,7 @@ void action_raise_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); stacking_raise(CLIENT_AS_WINDOW(data->client)); actions_client_move(data, FALSE); diff --git a/openbox/actions/raiselower.c b/openbox/actions/raiselower.c index dbe41d85..6cc93797 100644 --- a/openbox/actions/raiselower.c +++ b/openbox/actions/raiselower.c @@ -11,7 +11,7 @@ void action_raiselower_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); stacking_restack_request(data->client, NULL, Opposite); actions_client_move(data, FALSE); diff --git a/openbox/actions/resize.c b/openbox/actions/resize.c index f6858d2d..260a422c 100644 --- a/openbox/actions/resize.c +++ b/openbox/actions/resize.c @@ -66,7 +66,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { ObClient *c = data->client; guint32 corner; diff --git a/openbox/actions/resizerelative.c b/openbox/actions/resizerelative.c index 74a3bd74..b5da1f73 100644 --- a/openbox/actions/resizerelative.c +++ b/openbox/actions/resizerelative.c @@ -64,7 +64,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) { Options *o = options; - if (data->client) { + if (!actions_client_locked(data)) { ObClient *c = data->client; gint x, y, ow, xoff, nw, oh, yoff, nh, lw, lh; gint left = o->left, right = o->right, top = o->top, bottom = o->bottom; diff --git a/openbox/actions/shade.c b/openbox/actions/shade.c index 502781dd..255d508f 100644 --- a/openbox/actions/shade.c +++ b/openbox/actions/shade.c @@ -15,7 +15,7 @@ void action_shade_startup(void) /* Always return FALSE because its not interactive */ static gboolean run_func_on(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_shade(data->client, TRUE); actions_client_move(data, FALSE); @@ -26,7 +26,7 @@ static gboolean run_func_on(ObActionsData *data, gpointer options) /* Always return FALSE because its not interactive */ static gboolean run_func_off(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_shade(data->client, FALSE); actions_client_move(data, FALSE); @@ -37,7 +37,7 @@ static gboolean run_func_off(ObActionsData *data, gpointer options) /* Always return FALSE because its not interactive */ static gboolean run_func_toggle(ObActionsData *data, gpointer options) { - if (data->client) { + if (!actions_client_locked(data)) { actions_client_move(data, TRUE); client_shade(data->client, !data->client->shaded); actions_client_move(data, FALSE); diff --git a/openbox/client.h b/openbox/client.h index 11a01400..d7e40408 100644 --- a/openbox/client.h +++ b/openbox/client.h @@ -308,6 +308,9 @@ struct _ObClient */ guint functions; + /*! Prevent window from being accidentally acted upon */ + gboolean locked; + /* The window's icon, in a variety of shapes and sizes */ RrImage *icon_set; diff --git a/openbox/client_menu.c b/openbox/client_menu.c index c6cdd635..f34c8ef3 100644 --- a/openbox/client_menu.c +++ b/openbox/client_menu.c @@ -121,6 +121,9 @@ static void client_menu_execute(ObMenuEntry *e, ObMenuFrame *f, if (!c) return; + if (c->locked) + return; + if (!config_focus_under_mouse) ignore_start = event_start_ignore_all_enters(); @@ -218,6 +221,9 @@ static void layer_menu_execute(ObMenuEntry *e, ObMenuFrame *f, g_assert(c); + if (c->locked) + return; + if (!config_focus_under_mouse) ignore_start = event_start_ignore_all_enters(); @@ -290,6 +296,9 @@ static void send_to_menu_execute(ObMenuEntry *e, ObMenuFrame *f, { g_assert(c); + if (c->locked) + return; + client_set_desktop(c, e->id, FALSE, FALSE); if (f && c->desktop != screen_desktop && c->desktop != DESKTOP_ALL) /* the client won't even be on the screen anymore, so hide the menu */