]> icculus.org git repositories - dana/obconf.git/blob - src/preview_update.c
Add the Inactive OSD font, and the primaryMonitor options
[dana/obconf.git] / src / preview_update.c
1 #include "preview_update.h"
2 #include "main.h"
3
4 static gboolean restart_theme_preview_update = TRUE;
5
6 static GtkTreeView  *tree_view            = NULL;
7 static GtkListStore *list_store           = NULL;
8 static gchar        *title_layout         = NULL;
9 static RrFont       *active_window_font   = NULL;
10 static RrFont       *inactive_window_font = NULL;
11 static RrFont       *menu_title_font      = NULL;
12 static RrFont       *menu_item_font       = NULL;
13 static RrFont       *osd_active_font      = NULL;
14 static RrFont       *osd_inactive_font    = NULL;
15
16 static gboolean update_theme_preview_iterate(gpointer data);
17
18 void preview_update_all()
19 {
20     if (!list_store) return;
21     if (!RR_CHECK_VERSION(3,5,0)) return;
22
23     g_idle_remove_by_data(list_store);
24
25     if (!(title_layout && active_window_font && inactive_window_font &&
26           menu_title_font && menu_item_font &&
27           osd_active_font && osd_inactive_font))
28         return; /* not set up */
29
30     restart_theme_preview_update = TRUE;
31     g_idle_add_full(G_PRIORITY_LOW,
32                     update_theme_preview_iterate,
33                     list_store, NULL);
34 }
35
36 void preview_update_set_tree_view(GtkTreeView *tr, GtkListStore *ls)
37 {
38     g_assert(!!tr == !!ls);
39
40     if (list_store) g_idle_remove_by_data(list_store);
41
42     tree_view = tr;
43     list_store = ls;
44
45     if (list_store) preview_update_all();
46 }
47
48 void preview_update_set_active_font(RrFont *f)
49 {
50     RrFontClose(active_window_font);
51     active_window_font = f;
52     preview_update_all();
53 }
54
55 void preview_update_set_inactive_font(RrFont *f)
56 {
57     RrFontClose(inactive_window_font);
58     inactive_window_font = f;
59     preview_update_all();
60 }
61
62 void preview_update_set_menu_header_font(RrFont *f)
63 {
64     RrFontClose(menu_title_font);
65     menu_title_font = f;
66     preview_update_all();
67 }
68
69 void preview_update_set_menu_item_font(RrFont *f)
70 {
71     RrFontClose(menu_item_font);
72     menu_item_font = f;
73     preview_update_all();
74 }
75
76 void preview_update_set_osd_active_font(RrFont *f)
77 {
78     RrFontClose(osd_active_font);
79     osd_active_font = f;
80     preview_update_all();
81 }
82
83 void preview_update_set_osd_inactive_font(RrFont *f)
84 {
85     RrFontClose(osd_inactive_font);
86     osd_inactive_font = f;
87     preview_update_all();
88 }
89
90 void preview_update_set_title_layout(const gchar *layout)
91 {
92     g_free(title_layout);
93     title_layout = g_strdup(layout);
94     preview_update_all();
95 }
96
97 static gboolean update_theme_preview_iterate(gpointer data)
98 {
99     GtkListStore *ls = data;
100     static GtkTreeIter iter;
101     gchar *name;
102
103     if (restart_theme_preview_update) {
104         /* get the first iterator position if there is such a thing */
105         if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ls), &iter)) {
106             /* nothing to show */
107             obconf_show_main();
108             return FALSE;
109         }
110         restart_theme_preview_update = FALSE;
111     } else {
112         /* get the next iterator position if there is such a thing */
113         if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(ls), &iter)) {
114             GtkTreePath *path;
115
116             restart_theme_preview_update = TRUE;
117
118             gtk_tree_view_get_cursor(tree_view, &path, NULL);
119             if (path) {
120                 gtk_tree_view_scroll_to_cell(tree_view, path, NULL,
121                                              FALSE, 0, 0);
122                 gtk_tree_path_free(path);
123             }
124
125             obconf_show_main();
126
127             return FALSE;
128         }
129     }
130
131     gtk_tree_model_get(GTK_TREE_MODEL(ls), &iter, 0, &name, -1);
132
133     gtk_list_store_set(GTK_LIST_STORE(ls), &iter, 1,
134                        preview_theme(name, title_layout, active_window_font,
135                                      inactive_window_font, menu_title_font,
136                                      menu_item_font, osd_active_font,
137                                      osd_inactive_font),
138                        -1);
139
140     return TRUE;
141 }