Mercurial > pidgin
annotate finch/libgnt/gntws.c @ 18395:ed470f35ceab
We don't want to be using MAXPATHLEN except for backwards compatibility.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 01 Jul 2007 01:10:21 +0000 |
parents | 5023ad94ebc9 |
children | 93c5c785a811 |
rev | line source |
---|---|
17699 | 1 #include <gmodule.h> |
2 | |
3 #include "gntbox.h" | |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
4 #include "gntwidget.h" |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
5 #include "gntwindow.h" |
17699 | 6 #include "gntwm.h" |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
7 #include "gntws.h" |
17699 | 8 |
9 static void | |
10 widget_hide(gpointer data, gpointer nodes) | |
11 { | |
12 GntWidget *widget = GNT_WIDGET(data); | |
13 GntNode *node = g_hash_table_lookup(nodes, widget); | |
17707
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
14 if (GNT_IS_WINDOW(widget)) |
3c3fc1432a01
Let windows know when the workspace they are in is being hidden/shown
Richard Nelson <wabz@pidgin.im>
parents:
17702
diff
changeset
|
15 gnt_window_workspace_hiding(GNT_WINDOW(widget)); |
17699 | 16 hide_panel(node->panel); |
17 } | |
18 | |
19 static void | |
20 widget_show(gpointer data, gpointer nodes) | |
21 { | |
22 GntNode *node = g_hash_table_lookup(nodes, data); | |
23 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(data), GNT_WIDGET_INVISIBLE); | |
24 if (node) { | |
25 show_panel(node->panel); | |
26 gnt_wm_copy_win(GNT_WIDGET(data), node); | |
27 } | |
28 } | |
29 | |
30 void | |
31 gnt_ws_draw_taskbar(GntWS *ws, gboolean reposition) | |
32 { | |
33 static WINDOW *taskbar = NULL; | |
34 GList *iter; | |
35 int n, width = 0; | |
36 int i; | |
37 | |
38 if (taskbar == NULL) { | |
39 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); | |
40 } else if (reposition) { | |
41 int Y_MAX = getmaxy(stdscr) - 1; | |
42 mvwin(taskbar, Y_MAX, 0); | |
43 } | |
44 | |
45 wbkgdset(taskbar, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
46 werase(taskbar); | |
47 | |
48 n = g_list_length(ws->list); | |
49 if (n) | |
50 width = getmaxx(stdscr) / n; | |
51 | |
52 for (i = 0, iter = ws->list; iter; iter = iter->next, i++) { | |
53 GntWidget *w = iter->data; | |
54 int color; | |
55 const char *title; | |
56 | |
57 if (w == ws->ordered->data) { | |
58 /* This is the current window in focus */ | |
59 color = GNT_COLOR_TITLE; | |
60 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { | |
61 /* This is a window with the URGENT hint set */ | |
62 color = GNT_COLOR_URGENT; | |
63 } else { | |
64 color = GNT_COLOR_NORMAL; | |
65 } | |
66 wbkgdset(taskbar, '\0' | COLOR_PAIR(color)); | |
67 if (iter->next) | |
68 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width); | |
69 else | |
70 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), getmaxx(stdscr) - width * i); | |
71 title = GNT_BOX(w)->title; | |
72 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>"); | |
73 if (i) | |
74 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
75 } | |
76 wrefresh(taskbar); | |
77 } | |
78 | |
79 static void | |
80 gnt_ws_init(GTypeInstance *instance, gpointer class) | |
81 { | |
82 GntWS *ws = GNT_WS(instance); | |
83 ws->list = NULL; | |
84 ws->ordered = NULL; | |
85 ws->name = NULL; | |
86 } | |
87 | |
88 void gnt_ws_add_widget(GntWS *ws, GntWidget* wid) | |
89 { | |
18223
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
90 GntWidget *oldfocus; |
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
91 oldfocus = ws->ordered ? ws->ordered->data : NULL; |
17699 | 92 ws->list = g_list_append(ws->list, wid); |
93 ws->ordered = g_list_prepend(ws->ordered, wid); | |
18223
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
94 if (oldfocus) |
5023ad94ebc9
Notify a window when it loses focus because another window was moved to
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18075
diff
changeset
|
95 gnt_widget_set_focus(oldfocus, FALSE); |
17699 | 96 } |
97 | |
98 void gnt_ws_remove_widget(GntWS *ws, GntWidget* wid) | |
99 { | |
100 ws->list = g_list_remove(ws->list, wid); | |
101 ws->ordered = g_list_remove(ws->ordered, wid); | |
102 } | |
103 | |
104 void | |
105 gnt_ws_set_name(GntWS *ws, const gchar *name) | |
106 { | |
107 g_free(ws->name); | |
108 ws->name = g_strdup(name); | |
109 } | |
110 | |
111 void | |
112 gnt_ws_hide(GntWS *ws, GHashTable *nodes) | |
113 { | |
114 g_list_foreach(ws->ordered, widget_hide, nodes); | |
115 } | |
116 | |
117 void gnt_ws_widget_hide(GntWidget *widget, GHashTable *nodes) { | |
118 widget_hide(widget, nodes); | |
119 } | |
120 | |
121 void gnt_ws_widget_show(GntWidget *widget, GHashTable *nodes) { | |
122 widget_show(widget, nodes); | |
123 } | |
124 | |
125 void | |
126 gnt_ws_show(GntWS *ws, GHashTable *nodes) | |
127 { | |
128 GList *l; | |
129 for (l = g_list_last(ws->ordered); l; l = g_list_previous(l)) | |
130 widget_show(l->data, nodes); | |
131 } | |
132 | |
133 GType | |
134 gnt_ws_get_gtype(void) | |
135 { | |
136 static GType type = 0; | |
137 | |
138 if(type == 0) { | |
139 static const GTypeInfo info = { | |
140 sizeof(GntWSClass), | |
141 NULL, /* base_init */ | |
142 NULL, /* base_finalize */ | |
143 NULL, | |
144 /*(GClassInitFunc)gnt_ws_class_init,*/ | |
145 NULL, | |
146 NULL, /* class_data */ | |
147 sizeof(GntWS), | |
148 0, /* n_preallocs */ | |
149 gnt_ws_init, /* instance_init */ | |
150 NULL /* value_table */ | |
151 }; | |
152 | |
153 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
154 "GntWS", | |
155 &info, 0); | |
156 } | |
157 | |
158 return type; | |
159 } | |
160 | |
18075
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
161 GntWS *gnt_ws_new(const char *name) |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
162 { |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
163 GntWS *ws = GNT_WS(g_object_new(GNT_TYPE_WS, NULL)); |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
164 ws->name = g_strdup(name ? name : "(noname)"); |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
165 return ws; |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
166 } |
34e011c8ed2b
F9 to create a new workspace.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17707
diff
changeset
|
167 |
17702
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
168 const char * gnt_ws_get_name(GntWS *ws) |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
169 { |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
170 return ws->name; |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
171 } |
596c970076df
Alt+s to see the list of workspaces and windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17699
diff
changeset
|
172 |