From cbd0e4d308e6761740ca1561108ffe97453a054d Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Thu, 14 Aug 2003 06:01:39 +0000 Subject: [PATCH] add the client_list_menu plugin --- Makefile.am | 16 +++- openbox/plugin.c | 1 + plugins/menu/.cvsignore | 2 + plugins/menu/client_list_menu.c | 142 ++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 plugins/menu/client_list_menu.c diff --git a/Makefile.am b/Makefile.am index 0b485927..ae8cf62e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,8 @@ plugin_LTLIBRARIES = \ plugins/menu/timed_menu.la \ plugins/menu/fifo_menu.la \ plugins/menu/client_menu.la \ - plugins/menu/include_menu.la + plugins/menu/include_menu.la \ + plugins/menu/client_list_menu.la if OBCONF bin_PROGRAMS += \ @@ -265,6 +266,19 @@ plugins_menu_include_menu_la_LDFLAGS = \ plugins_menu_include_menu_la_SOURCES = \ plugins/menu/include_menu.c +plugins_menu_client_list_menu_la_CPPFLAGS = \ + $(XFT_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(LIBSN_CFLAGS) \ + $(XML_CFLAGS) \ + -DPLUGINDIR=\"$(plugindir)\" \ + -DG_LOG_DOMAIN=\"Plugin-Client-List-Menu\" +plugins_menu_client_list_menu_la_LDFLAGS = \ + -module \ + -avoid-version +plugins_menu_client_list_menu_la_SOURCES = \ + plugins/menu/client_list_menu.c + ## obconf ## diff --git a/openbox/plugin.c b/openbox/plugin.c index 18c55064..411eb6fb 100644 --- a/openbox/plugin.c +++ b/openbox/plugin.c @@ -161,6 +161,7 @@ void plugin_loadall(ObParseInst *i) /* XXX rm me when the parser loads me magically */ plugin_open("client_menu", i); + plugin_open("client_list_menu", i); } else { /* load the plugins in the rc file */ while (g_io_channel_read_line(io, &name, NULL, NULL, &err) == diff --git a/plugins/menu/.cvsignore b/plugins/menu/.cvsignore index c5ffa019..de4383e5 100644 --- a/plugins/menu/.cvsignore +++ b/plugins/menu/.cvsignore @@ -3,9 +3,11 @@ timed_menu.la fifo_menu.la client_menu.la +client_list_menu.la include_menu.la .dirstamp plugins_menu_client_menu_la-client_menu.lo +plugins_menu_client_list_menu_la-client_list_menu.lo plugins_menu_fifo_menu_la-fifo_menu.lo plugins_menu_timed_menu_la-timed_menu.lo plugins_menu_include_menu_la-include_menu.lo diff --git a/plugins/menu/client_list_menu.c b/plugins/menu/client_list_menu.c new file mode 100644 index 00000000..166ac71d --- /dev/null +++ b/plugins/menu/client_list_menu.c @@ -0,0 +1,142 @@ +#include "kernel/openbox.h" +#include "kernel/menu.h" +#include "kernel/action.h" +#include "kernel/screen.h" +#include "kernel/client.h" +#include "kernel/focus.h" + +#include "render/theme.h" + +#include + +static char *PLUGIN_NAME = "client_list_menu"; + +typedef struct { + GSList *submenus; +} Client_List_Menu_Data; + +typedef struct { + guint desktop; +} Client_List_Desktop_Menu_Data; + +#define CLIENT_LIST_MENU(m) ((ObMenu *)m) +#define CLIENT_LIST_MENU_DATA(m) ((Client_List_Menu_Data *)((ObMenu *)m)->plugin_data) + +#define CLIENT_LIST_DESKTOP_MENU(m) ((ObMenu *)m) +#define CLIENT_LIST_DESKTOP_MENU_DATA(m) ((Client_List_Desktop_Menu_Data *)((ObMenu *)m)->plugin_data) + +static void self_update(ObMenu *self); +static void self_destroy(ObMenu *self); + +void plugin_setup_config() { } +void plugin_shutdown() { } +void plugin_destroy (ObMenu *m) { } + +void *plugin_create() +{ + ObMenu *menu = menu_new_full("Desktops", "client-list-menu", NULL, + NULL, self_update, NULL, + NULL, NULL, self_destroy); + + menu->plugin = PLUGIN_NAME; + menu->plugin_data = g_new(Client_List_Menu_Data, 1); + CLIENT_LIST_MENU_DATA(menu)->submenus = NULL; + + return (void *)menu; +} + +void plugin_startup() +{ + plugin_create("client_list_menu"); +} + + +static void desk_update(ObMenu *self) +{ + GList *it; + guint desk; + + menu_clear(self); + + desk = CLIENT_LIST_DESKTOP_MENU_DATA(self)->desktop; + + for (it = focus_order[desk]; it; it = g_list_next(it)) { + ObClient *c = (ObClient *)it->data; + if (client_normal(c)) { + ObAction* a = action_from_string("activate"); + a->data.activate.c = c; + menu_add_entry(self, menu_entry_new((c->iconic ? + c->icon_title : + c->title), a)); + } + } + + menu_render(self); +} + +static void desk_selected(ObMenuEntry *entry, + unsigned int button, unsigned int x, unsigned int y) +{ + entry->action->data.activate.here = (button == 2); + entry->parent->client = entry->action->data.activate.c; + menu_entry_fire(entry, button, x, y); +} + +static void desk_destroy(ObMenu *self) +{ + g_free(self->plugin_data); +} + +static void self_update(ObMenu *self) +{ + guint i, n; + ObMenu *deskmenu; + gchar *s; + GList *eit, *enext; + GSList *sit, *snext; + + n = g_slist_length(CLIENT_LIST_MENU_DATA(self)->submenus); + + for (i = 0; i < screen_num_desktops; ++i) { + if (i >= n) { + s = g_strdup_printf("client-list-menu-desktop-%d", i); + deskmenu = menu_new_full(screen_desktop_names[i], s, self, + NULL, + desk_update, desk_selected, NULL, NULL, + desk_destroy); + g_free(s); + + deskmenu->plugin = PLUGIN_NAME; + deskmenu->plugin_data = g_new(Client_List_Desktop_Menu_Data, 1); + CLIENT_LIST_DESKTOP_MENU_DATA(deskmenu)->desktop = i; + + CLIENT_LIST_MENU_DATA(self)->submenus = + g_slist_append(CLIENT_LIST_MENU_DATA(self)->submenus, + deskmenu); + } + + menu_add_entry(self, menu_entry_new_submenu(screen_desktop_names[i], + deskmenu)); + } + + for (eit = g_list_nth(self->entries, i); eit; eit = enext) { + enext = g_list_next(eit); + menu_entry_free(eit->data); + self->entries = g_list_delete_link(self->entries, eit); + } + + for (sit = g_slist_nth(CLIENT_LIST_MENU_DATA(self)->submenus, i); + sit; sit = snext) { + snext = g_slist_next(sit); + menu_free(sit->data); + CLIENT_LIST_MENU_DATA(self)->submenus = + g_slist_delete_link(CLIENT_LIST_MENU_DATA(self)->submenus, sit); + } + + menu_render(self); +} + +static void self_destroy(ObMenu *self) +{ + g_free(self->plugin_data); +} -- 2.45.2