From 7d9516a83be86c52f51e35869f169d2184173de5 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Sat, 23 Feb 2008 20:15:34 +0100 Subject: [PATCH] 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. --- Makefile.am | 1 + openbox/actions.c | 7 +++++++ openbox/actions.h | 2 ++ openbox/actions/all.c | 1 + openbox/actions/all.h | 1 + openbox/actions/close.c | 3 ++- openbox/actions/decorations.c | 6 +++--- openbox/actions/desktop.c | 6 +++--- openbox/actions/growtoedge.c | 1 + openbox/actions/iconify.c | 2 +- openbox/actions/kill.c | 2 +- openbox/actions/layer.c | 2 +- openbox/actions/lock.c | 18 ++++++++++++++++++ openbox/actions/lower.c | 2 +- openbox/actions/maximize.c | 6 +++--- openbox/actions/move.c | 3 ++- openbox/actions/moverelative.c | 2 +- openbox/actions/moveresizeto.c | 2 +- openbox/actions/movetoedge.c | 2 +- openbox/actions/omnipresent.c | 2 +- openbox/actions/raise.c | 2 +- openbox/actions/raiselower.c | 2 +- openbox/actions/resize.c | 2 +- openbox/actions/resizerelative.c | 2 +- openbox/actions/shade.c | 6 +++--- openbox/client.h | 3 +++ openbox/client_menu.c | 9 +++++++++ 27 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 openbox/actions/lock.c diff --git a/Makefile.am b/Makefile.am index 24ed0a9a..e14fd8fb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -190,6 +190,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 8f72714e..8e84a82f 100644 --- a/openbox/actions.c +++ b/openbox/actions.c @@ -363,3 +363,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 7a09a665..0b2dd996 100644 --- a/openbox/actions.h +++ b/openbox/actions.h @@ -98,3 +98,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 f5d5d062..9b4284e3 100644 --- a/openbox/actions/all.c +++ b/openbox/actions/all.c @@ -40,4 +40,5 @@ void action_all_startup(void) action_if_startup(); action_focustobottom_startup(); action_sendkeyevent_startup(); + action_lock_startup(); } diff --git a/openbox/actions/all.h b/openbox/actions/all.h index 332e8d11..f444aae1 100644 --- a/openbox/actions/all.h +++ b/openbox/actions/all.h @@ -41,5 +41,6 @@ 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); #endif diff --git a/openbox/actions/close.c b/openbox/actions/close.c index ab75e05d..5996cc64 100644 --- a/openbox/actions/close.c +++ b/openbox/actions/close.c @@ -14,7 +14,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 e85fb8ef..9834d26d 100644 --- a/openbox/actions/decorations.c +++ b/openbox/actions/decorations.c @@ -16,7 +16,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); @@ -27,7 +27,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); @@ -38,7 +38,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 37268bba..5102eb34 100644 --- a/openbox/actions/desktop.c +++ b/openbox/actions/desktop.c @@ -118,8 +118,6 @@ static gboolean run_func(ObActionsData *data, gpointer options) Options *o = options; guint d; - - switch (o->type) { case LAST: d = screen_last_desktop; @@ -137,7 +135,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 a37e3a26..fda04778 100644 --- a/openbox/actions/growtoedge.c +++ b/openbox/actions/growtoedge.c @@ -95,6 +95,7 @@ static gboolean run_func(ObActionsData *data, gpointer options) gint half; if (!data->client || + actions_client_locked(data) || /* don't allow vertical resize if shaded */ ((o->dir == OB_DIRECTION_NORTH || o->dir == OB_DIRECTION_SOUTH) && data->client->shaded)) diff --git a/openbox/actions/iconify.c b/openbox/actions/iconify.c index 8a3091d2..9f4fd450 100644 --- a/openbox/actions/iconify.c +++ b/openbox/actions/iconify.c @@ -24,7 +24,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 68244407..ac0293bf 100644 --- a/openbox/actions/kill.c +++ b/openbox/actions/kill.c @@ -14,7 +14,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 bbfda572..18556d27 100644 --- a/openbox/actions/layer.c +++ b/openbox/actions/layer.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; actions_client_move(data, TRUE); diff --git a/openbox/actions/lock.c b/openbox/actions/lock.c new file mode 100644 index 00000000..bd139589 --- /dev/null +++ b/openbox/actions/lock.c @@ -0,0 +1,18 @@ +#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, + NULL, NULL); +} + +/* 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 d34e933b..ffe01333 100644 --- a/openbox/actions/lower.c +++ b/openbox/actions/lower.c @@ -15,7 +15,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 45e8b38e..fa419901 100644 --- a/openbox/actions/maximize.c +++ b/openbox/actions/maximize.c @@ -53,7 +53,7 @@ static gpointer setup_func(xmlNodePtr node) 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); @@ -65,7 +65,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); @@ -77,7 +77,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 ddd3f59a..70ecf66d 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" @@ -15,7 +16,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 && !(ObClient *)(data->client)->locked) { guint32 corner; corner = data->button != 0 ? diff --git a/openbox/actions/moverelative.c b/openbox/actions/moverelative.c index ccdff545..e9238583 100644 --- a/openbox/actions/moverelative.c +++ b/openbox/actions/moverelative.c @@ -37,7 +37,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 357c7315..6ea70682 100644 --- a/openbox/actions/moveresizeto.c +++ b/openbox/actions/moveresizeto.c @@ -98,7 +98,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; gint mon, cmon; diff --git a/openbox/actions/movetoedge.c b/openbox/actions/movetoedge.c index f360ddd0..ce975645 100644 --- a/openbox/actions/movetoedge.c +++ b/openbox/actions/movetoedge.c @@ -50,7 +50,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 030a0159..8b0fd918 100644 --- a/openbox/actions/omnipresent.c +++ b/openbox/actions/omnipresent.c @@ -13,7 +13,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 6837bce2..3ee21efa 100644 --- a/openbox/actions/raise.c +++ b/openbox/actions/raise.c @@ -15,7 +15,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 80fc917f..9fb3c299 100644 --- a/openbox/actions/raiselower.c +++ b/openbox/actions/raiselower.c @@ -14,7 +14,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 47f45f5b..0c224929 100644 --- a/openbox/actions/resize.c +++ b/openbox/actions/resize.c @@ -60,7 +60,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 5742e1fc..ca0a5daa 100644 --- a/openbox/actions/resizerelative.c +++ b/openbox/actions/resizerelative.c @@ -46,7 +46,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; diff --git a/openbox/actions/shade.c b/openbox/actions/shade.c index 2342067f..c394f4f6 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 6a396cf4..aadf9303 100644 --- a/openbox/client.h +++ b/openbox/client.h @@ -298,6 +298,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 04f50e85..addee731 100644 --- a/openbox/client_menu.c +++ b/openbox/client_menu.c @@ -111,6 +111,9 @@ static void client_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(); @@ -208,6 +211,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(); @@ -284,6 +290,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); /* the client won't even be on the screen anymore, so hide the menu */ if (f) -- 2.34.1