]> Dogcows Code - chaz/openbox/blob - openbox/client_list_menu.c
make interactive actions a type and not special cases.
[chaz/openbox] / openbox / client_list_menu.c
1 #include "openbox.h"
2 #include "menu.h"
3 #include "menuframe.h"
4 #include "action.h"
5 #include "screen.h"
6 #include "client.h"
7 #include "focus.h"
8 #include "gettext.h"
9
10 #include <glib.h>
11
12 #define MENU_NAME "client-list-menu"
13
14 static GSList *desktop_menus;
15
16 typedef struct {
17 guint desktop;
18 } DesktopData;
19
20 void plugin_setup_config() { }
21
22 static void desk_menu_update(ObMenuFrame *frame, gpointer data)
23 {
24 ObMenu *menu = frame->menu;
25 DesktopData *d = data;
26 GList *it;
27 gint i;
28
29 menu_clear_entries(menu);
30
31 for (it = focus_order[d->desktop], i = 0; it; it = g_list_next(it), ++i) {
32 ObClient *c = it->data;
33 if (client_normal(c)) {
34 GSList *acts;
35 ObAction* act;
36 ObMenuEntry *e;
37 ObClientIcon *icon;
38
39 act = action_from_string("activate");
40 act->data.activate.any.c = c;
41 acts = g_slist_prepend(NULL, act);
42 e = menu_add_normal(menu, i,
43 (c->iconic ? c->icon_title : c->title), acts);
44
45 if ((icon = client_icon(c, 32, 32))) {
46 e->data.normal.icon_width = icon->width;
47 e->data.normal.icon_height = icon->height;
48 e->data.normal.icon_data = icon->data;
49 }
50 }
51 }
52
53 }
54
55 /* executes it without changing the client in the actions, since we set that
56 when we make the actions! */
57 static void desk_menu_execute(ObMenuEntry *self, gpointer data)
58 {
59 GSList *it;
60
61 for (it = self->data.normal.actions; it; it = g_slist_next(it))
62 {
63 ObAction *act = it->data;
64 act->func(&act->data);
65 }
66 }
67
68 static void desk_menu_destroy(ObMenu *menu, gpointer data)
69 {
70 DesktopData *d = data;
71
72 g_free(d);
73 }
74
75 static void self_update(ObMenuFrame *frame, gpointer data)
76 {
77 ObMenu *menu = frame->menu;
78 guint i;
79 GSList *it, *next;
80
81 it = desktop_menus;
82 for (i = 0; i < screen_num_desktops; ++i) {
83 if (!it) {
84 ObMenu *submenu;
85 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
86 DesktopData *data = g_new(DesktopData, 1);
87
88 data->desktop = i;
89 submenu = menu_new(name, screen_desktop_names[i], data);
90 menu_set_update_func(submenu, desk_menu_update);
91 menu_set_execute_func(submenu, desk_menu_execute);
92 menu_set_destroy_func(submenu, desk_menu_destroy);
93
94 menu_add_submenu(menu, i, name);
95
96 g_free(name);
97
98 desktop_menus = g_slist_append(desktop_menus, submenu);
99 } else
100 it = g_slist_next(it);
101 }
102 for (; it; it = next, ++i) {
103 next = g_slist_next(it);
104 menu_free(it->data);
105 desktop_menus = g_slist_delete_link(desktop_menus, it);
106 menu_entry_remove(menu_find_entry_id(menu, i));
107 }
108 }
109
110 void client_list_menu_startup()
111 {
112 ObMenu *menu;
113
114 menu = menu_new(MENU_NAME, _("Desktops"), NULL);
115 menu_set_update_func(menu, self_update);
116 }
This page took 0.038681 seconds and 5 git commands to generate.