~3v1n0/indicator-appmenu/all-menus-mode

« back to all changes in this revision

Viewing changes to src/indicator-appmenu.c

  • Committer: Marco Trevisan (Treviño)
  • Date: 2015-01-29 14:28:24 UTC
  • Revision ID: mail@3v1n0.net-20150129142824-5q45vzzyovvknpqh
IndicatorAppmenu: always just initialize the mode after an idle, and so the indicator

So we don't have to initialize the stuff once and then change mode, nor we need to use
a function to get the actual mode.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
 
76
76
typedef enum _AppmenuMode AppmenuMode;
77
77
enum _AppmenuMode {
78
 
        MODE_UNSET,
79
78
        MODE_STANDARD,
80
79
        MODE_UNITY,
81
80
        MODE_UNITY_ALL_MENUS
137
136
/**********************
138
137
  Prototypes
139
138
 **********************/
 
139
static gboolean indicator_appmenu_delayed_init                       (IndicatorAppmenu * iapp);
140
140
static void indicator_appmenu_dispose                                (GObject *object);
141
141
static void indicator_appmenu_finalize                               (GObject *object);
142
142
static void build_window_menus                                       (IndicatorAppmenu * iapp);
262
262
        return;
263
263
}
264
264
 
 
265
/* Per instance Init */
 
266
static void
 
267
indicator_appmenu_init (IndicatorAppmenu *self)
 
268
{
 
269
        self->apps = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
 
270
        self->mode = MODE_STANDARD;
 
271
        self->active_stubs = STUBS_UNKNOWN;
 
272
 
 
273
        /* Setup the cache of windows with possible desktop entries */
 
274
        self->desktop_windows = g_hash_table_new(g_direct_hash, g_direct_equal);
 
275
 
 
276
        g_idle_add((GSourceFunc) indicator_appmenu_delayed_init, self);
 
277
}
 
278
 
265
279
/* Delayed Init, this is done so it can happen after that the mode has been set */
266
280
static gboolean
267
281
indicator_appmenu_delayed_init (IndicatorAppmenu *self)
268
282
{
 
283
        if (indicator_object_check_environment(INDICATOR_OBJECT(self), "unity-all-menus")) {
 
284
                self->mode = MODE_UNITY_ALL_MENUS;
 
285
        } else if (indicator_object_check_environment(INDICATOR_OBJECT(self), "unity")) {
 
286
                self->mode = MODE_UNITY;
 
287
        }
 
288
 
 
289
        if (self->mode != MODE_STANDARD)
 
290
                self->active_stubs = STUBS_HIDE;
 
291
 
269
292
        if (self->active_stubs != STUBS_HIDE)
270
293
                build_window_menus(self);
271
294
 
298
321
        return G_SOURCE_REMOVE;
299
322
}
300
323
 
301
 
/* Per instance Init */
302
 
static void
303
 
indicator_appmenu_init (IndicatorAppmenu *self)
304
 
{
305
 
        self->apps = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
306
 
        self->mode = MODE_UNSET;
307
 
        self->active_stubs = STUBS_UNKNOWN;
308
 
 
309
 
        /* Setup the cache of windows with possible desktop entries */
310
 
        self->desktop_windows = g_hash_table_new(g_direct_hash, g_direct_equal);
311
 
 
312
 
        g_idle_add((GSourceFunc) indicator_appmenu_delayed_init, self);
313
 
}
314
 
 
315
 
AppmenuMode
316
 
get_mode (IndicatorAppmenu * iapp)
317
 
{
318
 
        if (iapp->mode != MODE_UNSET) {
319
 
                return iapp->mode;
320
 
        }
321
 
 
322
 
        if (indicator_object_check_environment(INDICATOR_OBJECT(iapp), "unity-all-menus")) {
323
 
                iapp->mode = MODE_UNITY;
324
 
                switch_default_app(iapp, NULL, NULL);
325
 
                iapp->mode = MODE_UNITY_ALL_MENUS;
326
 
 
327
 
                gpointer value;
328
 
                GHashTableIter iter;
329
 
                g_hash_table_iter_init(&iter, iapp->apps);
330
 
                while (g_hash_table_iter_next (&iter, NULL, &value)) {
331
 
                        connect_to_menu_signals(iapp, WINDOW_MENU (value));
332
 
                }
333
 
 
334
 
                find_relevant_windows(iapp);
335
 
        } else if (indicator_object_check_environment(INDICATOR_OBJECT(iapp), "unity")) {
336
 
                iapp->mode = MODE_UNITY;
337
 
        } else {
338
 
                iapp->mode = MODE_STANDARD;
339
 
        }
340
 
 
341
 
        if (iapp->mode != MODE_STANDARD)
342
 
                iapp->active_stubs = STUBS_HIDE;
343
 
 
344
 
        return iapp->mode;
345
 
}
346
 
 
347
324
static void
348
325
on_bus_acquired (GDBusConnection * connection, const gchar * name,
349
326
                 gpointer user_data)
615
592
        IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data);
616
593
        guint32 xid = bamf_window_get_xid(window);
617
594
 
618
 
        if (get_mode(iapp) == MODE_UNITY_ALL_MENUS) {
 
595
        if (iapp->mode == MODE_UNITY_ALL_MENUS) {
619
596
                ensure_menus(iapp, window);
620
597
                return;
621
598
        }
712
689
        gpointer value;
713
690
        GList* entries = NULL;
714
691
 
715
 
        if (get_mode(iapp) == MODE_UNITY_ALL_MENUS) {
 
692
        if (iapp->mode == MODE_UNITY_ALL_MENUS) {
716
693
                g_hash_table_iter_init (&iter, iapp->apps);
717
694
                while (g_hash_table_iter_next (&iter, NULL, &value)) {
718
695
                        GList *app_entries = window_menu_get_entries (WINDOW_MENU (value));
892
869
static void
893
870
switch_active_window (IndicatorAppmenu * iapp, BamfWindow * active_window)
894
871
{
895
 
        if (iapp->active_window == active_window || get_mode(iapp) == MODE_UNITY_ALL_MENUS) {
 
872
        if (iapp->active_window == active_window || iapp->mode == MODE_UNITY_ALL_MENUS) {
896
873
                return;
897
874
        }
898
875
 
974
951
static void
975
952
switch_default_app (IndicatorAppmenu * iapp, WindowMenu * newdef, BamfWindow * active_window)
976
953
{
977
 
        if (get_mode(iapp) == MODE_UNITY_ALL_MENUS) {
 
954
        if (iapp->mode == MODE_UNITY_ALL_MENUS) {
978
955
                return;
979
956
        }
980
957
 
1036
1013
 
1037
1014
        g_hash_table_insert(iapp->apps, GUINT_TO_POINTER(xid), menus);
1038
1015
 
1039
 
        if (get_mode(iapp) == MODE_UNITY_ALL_MENUS) {
 
1016
        if (iapp->mode == MODE_UNITY_ALL_MENUS) {
1040
1017
                connect_to_menu_signals(iapp, menus);
1041
1018
        }
1042
1019
}