finch/libgnt/gntws.c

Fri, 27 Apr 2007 12:56:59 +0000

author
Richard Nelson <wabz@pidgin.im>
date
Fri, 27 Apr 2007 12:56:59 +0000
branch
finch.workspaces
changeset 16520
18efc8fca905
child 16523
d774ca89d340
permissions
-rw-r--r--

Forgot these...

16520
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
1 #include <gmodule.h>
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
2
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
3 #include "gntbox.h"
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
4 #include "gntws.h"
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
5 #include "gntwm.h"
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
6 #include "gntwidget.h"
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
7
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
8 static void
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
9 widget_hide(gpointer data, gpointer nodes)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
10 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
11 GntWidget *widget = GNT_WIDGET(data);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
12 GntNode *node = g_hash_table_lookup(nodes, widget);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
13 hide_panel(node->panel);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
14 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
15
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
16 static void
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
17 widget_show(gpointer data, gpointer nodes)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
18 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
19 GntNode *node = g_hash_table_lookup(nodes, data);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
20 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(data), GNT_WIDGET_INVISIBLE);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
21 if (node) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
22 show_panel(node->panel);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
23 gnt_wm_copy_win(GNT_WIDGET(data), node);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
24 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
25 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
26
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
27 void
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
28 gnt_ws_draw_taskbar(GntWS *ws, gboolean reposition)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
29 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
30 static WINDOW *taskbar = NULL;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
31 GList *iter;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
32 int n, width = 0;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
33 int i;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
34
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
35 if (taskbar == NULL) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
36 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
37 } else if (reposition) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
38 int Y_MAX = getmaxy(stdscr) - 1;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
39 mvwin(taskbar, Y_MAX, 0);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
40 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
41
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
42 wbkgdset(taskbar, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
43 werase(taskbar);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
44
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
45 n = g_list_length(ws->list);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
46 if (n)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
47 width = getmaxx(stdscr) / n;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
48
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
49 for (i = 0, iter = ws->list; iter; iter = iter->next, i++) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
50 GntWidget *w = iter->data;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
51 int color;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
52 const char *title;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
53
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
54 if (w == ws->ordered->data) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
55 /* This is the current window in focus */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
56 color = GNT_COLOR_TITLE;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
57 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
58 /* This is a window with the URGENT hint set */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
59 color = GNT_COLOR_URGENT;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
60 } else {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
61 color = GNT_COLOR_NORMAL;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
62 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
63 wbkgdset(taskbar, '\0' | COLOR_PAIR(color));
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
64 if (iter->next)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
65 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
66 else
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
67 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), getmaxx(stdscr) - width * i);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
68 title = GNT_BOX(w)->title;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
69 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>");
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
70 if (i)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
71 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL));
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
72 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
73 wrefresh(taskbar);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
74 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
75
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
76 static void
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
77 gnt_ws_init(GTypeInstance *instance, gpointer class)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
78 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
79 GntWS *ws = GNT_WS(instance);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
80 ws->list = NULL;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
81 ws->ordered = NULL;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
82 ws->name = NULL;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
83 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
84
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
85 void gnt_ws_add_widget(GntWS *ws, GntWidget* wid)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
86 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
87 ws->list = g_list_append(ws->list, wid);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
88 ws->ordered = g_list_prepend(ws->ordered, wid);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
89 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
90
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
91 void gnt_ws_remove_widget(GntWS *ws, GntWidget* wid)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
92 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
93 ws->list = g_list_remove(ws->list, wid);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
94 ws->ordered = g_list_remove(ws->ordered, wid);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
95 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
96
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
97 void
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
98 gnt_ws_set_name(GntWS *ws, const gchar *name)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
99 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
100 g_free(ws->name);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
101 ws->name = g_strdup(name);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
102 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
103
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
104 void
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
105 gnt_ws_hide(GntWS *ws, GHashTable *nodes)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
106 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
107 g_list_foreach(ws->ordered, widget_hide, nodes);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
108 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
109
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
110 void gnt_ws_widget_hide(GntWidget *widget, GHashTable *nodes) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
111 widget_hide(widget, nodes);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
112 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
113
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
114 void gnt_ws_widget_show(GntWidget *widget, GHashTable *nodes) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
115 widget_show(widget, nodes);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
116 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
117
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
118 void
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
119 gnt_ws_show(GntWS *ws, GHashTable *nodes)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
120 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
121 GList *l;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
122 for (l = g_list_last(ws->ordered); l; l = g_list_previous(l))
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
123 widget_show(l->data, nodes);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
124 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
125
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
126 GType
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
127 gnt_ws_get_gtype(void)
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
128 {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
129 static GType type = 0;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
130
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
131 if(type == 0) {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
132 static const GTypeInfo info = {
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
133 sizeof(GntWSClass),
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
134 NULL, /* base_init */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
135 NULL, /* base_finalize */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
136 NULL,
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
137 /*(GClassInitFunc)gnt_ws_class_init,*/
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
138 NULL,
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
139 NULL, /* class_data */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
140 sizeof(GntWS),
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
141 0, /* n_preallocs */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
142 gnt_ws_init, /* instance_init */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
143 NULL /* value_table */
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
144 };
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
145
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
146 type = g_type_register_static(GNT_TYPE_BINDABLE,
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
147 "GntWS",
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
148 &info, 0);
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
149 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
150
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
151 return type;
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
152 }
18efc8fca905 Forgot these...
Richard Nelson <wabz@pidgin.im>
parents:
diff changeset
153

mercurial