1 #include "kernel/openbox.h"
2 #include "kernel/menu.h"
3 #include "kernel/menuframe.h"
4 #include "kernel/action.h"
5 #include "kernel/screen.h"
6 #include "kernel/client.h"
7 #include "kernel/focus.h"
10 #include "render/theme.h"
14 #define MENU_NAME "client-list-menu"
17 /* how many desktop menus we've made */
25 void plugin_setup_config() { }
27 static void desk_menu_update(ObMenuFrame *frame, gpointer data)
29 ObMenu *menu = frame->menu;
30 DesktopData *d = data;
33 menu_clear_entries(menu->name);
35 for (it = focus_order[d->desktop]; it; it = g_list_next(it)) {
36 ObClient *c = it->data;
37 if (client_normal(c)) {
41 act = action_from_string("activate");
42 act->data.activate.c = c;
43 acts = g_slist_prepend(NULL, act);
44 menu_add_normal(menu->name, 0,
45 (c->iconic ? c->icon_title : c->title), acts);
51 /* executes it without changing the client in the actions, since we set that
52 when we make the actions! */
53 static void desk_menu_execute(ObMenuEntryFrame *self, gpointer data)
57 for (it = self->entry->data.normal.actions; it; it = g_slist_next(it))
59 ObAction *act = it->data;
60 act->func(&act->data);
64 static void desk_menu_destroy(ObMenu *menu, gpointer data)
66 DesktopData *d = data;
71 static void self_update(ObMenuFrame *frame, gpointer data)
76 menu_clear_entries(MENU_NAME);
78 for (i = 0; i < screen_num_desktops; ++i) {
79 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
80 DesktopData *data = g_new(DesktopData, 1);
83 menu_new(name, screen_desktop_names[i], data);
84 menu_set_update_func(name, desk_menu_update);
85 menu_set_execute_func(name, desk_menu_execute);
86 menu_set_destroy_func(name, desk_menu_destroy);
88 menu_add_submenu(MENU_NAME, 0, name);
93 d->desktops = MAX(d->desktops, screen_num_desktops);
96 static void self_destroy(ObMenu *menu, gpointer data)
101 for (i = 0; i < d->desktops; ++i) {
102 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
109 void plugin_startup()
113 data = g_new(MenuData, 1);
115 menu_new(MENU_NAME, _("Desktops"), data);
116 menu_set_update_func(MENU_NAME, self_update);
117 menu_set_destroy_func(MENU_NAME, self_destroy);
120 void plugin_shutdown()
122 menu_free(MENU_NAME);