]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/client_list_menu.c
make the default screen-edge resistance 20 (double what it is for windows)
[mikachu/openbox.git] / 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 static void desk_menu_update(ObMenuFrame *frame, gpointer data)
21 {
22     ObMenu *menu = frame->menu;
23     DesktopData *d = data;
24     GList *it;
25     gint i;
26     gboolean icons = FALSE;
27
28     menu_clear_entries(menu);
29
30     for (it = focus_order[d->desktop], i = 0; it; it = g_list_next(it), ++i) {
31         ObClient *c = it->data;
32         if (client_normal(c)) {
33             GSList *acts;
34             ObAction* act;
35             ObMenuEntry *e;
36             ObClientIcon *icon;
37
38             if (!icons && c->iconic) {
39                 icons = TRUE;
40                 menu_add_separator(menu, -1);
41             }
42
43             act = action_from_string("activate");
44             act->data.activate.any.c = c;
45             acts = g_slist_prepend(NULL, act);
46             e = menu_add_normal(menu, i,
47                                 (c->iconic ? c->icon_title : c->title), acts);
48
49             if ((icon = client_icon(c, 32, 32))) {
50                 e->data.normal.icon_width = icon->width;
51                 e->data.normal.icon_height = icon->height;
52                 e->data.normal.icon_data = icon->data;
53             }
54         }
55     }
56     
57 }
58
59 /* executes it without changing the client in the actions, since we set that
60    when we make the actions! */
61 static void desk_menu_execute(ObMenuEntry *self, gpointer data)
62 {
63     GSList *it;
64
65     for (it = self->data.normal.actions; it; it = g_slist_next(it))
66     {
67         ObAction *act = it->data;
68         act->func(&act->data);
69     }
70 }
71
72 static void desk_menu_destroy(ObMenu *menu, gpointer data)
73 {
74     DesktopData *d = data;
75
76     g_free(d);
77 }
78
79 static void self_update(ObMenuFrame *frame, gpointer data)
80 {
81     ObMenu *menu = frame->menu;
82     guint i;
83     GSList *it, *next;
84     
85     it = desktop_menus;
86     for (i = 0; i < screen_num_desktops; ++i) {
87         if (!it) {
88             ObMenu *submenu;
89             gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
90             DesktopData *data = g_new(DesktopData, 1);
91
92             data->desktop = i;
93             submenu = menu_new(name, screen_desktop_names[i], data);
94             menu_set_update_func(submenu, desk_menu_update);
95             menu_set_execute_func(submenu, desk_menu_execute);
96             menu_set_destroy_func(submenu, desk_menu_destroy);
97
98             menu_add_submenu(menu, i, name);
99
100             g_free(name);
101
102             desktop_menus = g_slist_append(desktop_menus, submenu);
103         } else
104             it = g_slist_next(it);
105     }
106     for (; it; it = next, ++i) {
107         next = g_slist_next(it);
108         menu_free(it->data);
109         desktop_menus = g_slist_delete_link(desktop_menus, it);
110         menu_entry_remove(menu_find_entry_id(menu, i));
111     }
112 }
113
114 void client_list_menu_startup()
115 {
116     ObMenu *menu;
117
118     menu = menu_new(MENU_NAME, _("Desktops"), NULL);
119     menu_set_update_func(menu, self_update);
120 }