Mercurial > pidgin.yaz
annotate finch/libgnt/gntwm.c @ 17723:c918d59d5936
Added the ability to change the key bindings on the active window.
Still looking for a way to create a more informative title to the binding list window.
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Tue, 12 Jun 2007 13:52:33 +0000 |
parents | 15988e2bd270 |
children | ac904659104f |
rev | line source |
---|---|
17718
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
1 /** |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
3 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
6 * source distribution. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
7 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
11 * (at your option) any later version. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
12 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
16 * GNU General Public License for more details. |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
17 * |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
21 */ |
8410511f4dbb
applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents:
17717
diff
changeset
|
22 |
15818 | 23 #define _GNU_SOURCE |
24 #if defined(__APPLE__) | |
25 #define _XOPEN_SOURCE_EXTENDED | |
26 #endif | |
27 | |
28 #include "config.h" | |
29 | |
30 #include <ctype.h> | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 #include <time.h> | |
34 | |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
35 #include "gntbutton.h" |
15818 | 36 #include "gntwm.h" |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
37 #include "gntentry.h" |
15818 | 38 #include "gntstyle.h" |
39 #include "gntmarshal.h" | |
40 #include "gnt.h" | |
41 #include "gntbox.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
42 #include "gntlabel.h" |
15818 | 43 #include "gntmenu.h" |
44 #include "gnttextview.h" | |
45 #include "gnttree.h" | |
46 #include "gntutils.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
47 #include "gntwindow.h" |
15818 | 48 |
49 #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */ | |
50 | |
51 enum | |
52 { | |
53 SIG_NEW_WIN, | |
54 SIG_DECORATE_WIN, | |
55 SIG_CLOSE_WIN, | |
56 SIG_CONFIRM_RESIZE, | |
57 SIG_RESIZED, | |
58 SIG_CONFIRM_MOVE, | |
59 SIG_MOVED, | |
60 SIG_UPDATE_WIN, | |
61 SIG_GIVE_FOCUS, | |
62 SIG_KEY_PRESS, | |
63 SIG_MOUSE_CLICK, | |
64 SIGS | |
65 }; | |
66 | |
67 static guint signals[SIGS] = { 0 }; | |
68 static void gnt_wm_new_window_real(GntWM *wm, GntWidget *widget); | |
69 static void gnt_wm_win_resized(GntWM *wm, GntNode *node); | |
70 static void gnt_wm_win_moved(GntWM *wm, GntNode *node); | |
71 static void gnt_wm_give_focus(GntWM *wm, GntWidget *widget); | |
72 static void update_window_in_list(GntWM *wm, GntWidget *wid); | |
73 static void shift_window(GntWM *wm, GntWidget *widget, int dir); | |
74 | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
75 #ifndef NO_WIDECHAR |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
76 static int widestringwidth(wchar_t *wide); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
77 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
78 |
15818 | 79 static gboolean write_already(gpointer data); |
80 static int write_timeout; | |
81 static time_t last_active_time; | |
82 static gboolean idle_update; | |
83 | |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
84 static gboolean ignore_keys = FALSE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
85 |
15818 | 86 static GList * |
87 g_list_bring_to_front(GList *list, gpointer data) | |
88 { | |
89 list = g_list_remove(list, data); | |
90 list = g_list_prepend(list, data); | |
91 return list; | |
92 } | |
93 | |
94 static void | |
95 free_node(gpointer data) | |
96 { | |
97 GntNode *node = data; | |
98 hide_panel(node->panel); | |
99 del_panel(node->panel); | |
100 g_free(node); | |
101 } | |
102 | |
103 static void | |
104 draw_taskbar(GntWM *wm, gboolean reposition) | |
105 { | |
106 static WINDOW *taskbar = NULL; | |
107 GList *iter; | |
108 int n, width = 0; | |
109 int i; | |
110 | |
111 if (taskbar == NULL) { | |
112 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); | |
113 } else if (reposition) { | |
114 int Y_MAX = getmaxy(stdscr) - 1; | |
115 mvwin(taskbar, Y_MAX, 0); | |
116 } | |
117 | |
118 wbkgdset(taskbar, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
119 werase(taskbar); | |
120 | |
121 n = g_list_length(wm->list); | |
122 if (n) | |
123 width = getmaxx(stdscr) / n; | |
124 | |
125 for (i = 0, iter = wm->list; iter; iter = iter->next, i++) | |
126 { | |
127 GntWidget *w = iter->data; | |
128 int color; | |
129 const char *title; | |
130 | |
131 if (w == wm->ordered->data) { | |
132 /* This is the current window in focus */ | |
133 color = GNT_COLOR_TITLE; | |
134 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { | |
135 /* This is a window with the URGENT hint set */ | |
136 color = GNT_COLOR_URGENT; | |
137 } else { | |
138 color = GNT_COLOR_NORMAL; | |
139 } | |
140 wbkgdset(taskbar, '\0' | COLOR_PAIR(color)); | |
141 if (iter->next) | |
142 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width); | |
143 else | |
144 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), getmaxx(stdscr) - width * i); | |
145 title = GNT_BOX(w)->title; | |
146 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>"); | |
147 if (i) | |
148 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
149 | |
150 update_window_in_list(wm, w); | |
151 } | |
152 | |
153 wrefresh(taskbar); | |
154 } | |
155 | |
156 static void | |
157 copy_win(GntWidget *widget, GntNode *node) | |
158 { | |
159 WINDOW *src, *dst; | |
160 int shadow; | |
161 if (!node) | |
162 return; | |
163 src = widget->window; | |
164 dst = node->window; | |
165 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
166 copywin(src, dst, node->scroll, 0, 0, 0, getmaxy(dst) - 1, getmaxx(dst) - 1, 0); | |
167 } | |
168 | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
169 /** |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
170 * The following is a workaround for a bug in most versions of ncursesw. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
171 * Read about it in: http://article.gmane.org/gmane.comp.lib.ncurses.bugs/2751 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
172 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
173 * In short, if a panel hides one cell of a multi-cell character, then the rest |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
174 * of the characters in that line get screwed. The workaround here is to erase |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
175 * any such character preemptively. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
176 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
177 * Caveat: If a wide character is erased, and the panel above it is moved enough |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
178 * to expose the entire character, it is not always redrawn. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
179 */ |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
180 static void |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
181 work_around_for_ncurses_bug() |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
182 { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
183 #ifndef NO_WIDECHAR |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
184 PANEL *panel = NULL; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
185 while ((panel = panel_below(panel)) != NULL) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
186 int sx, ex, sy, ey, w, y; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
187 cchar_t ch; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
188 PANEL *below = panel; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
189 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
190 sx = panel->win->_begx; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
191 ex = panel->win->_maxx + sx; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
192 sy = panel->win->_begy; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
193 ey = panel->win->_maxy + sy; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
194 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
195 while ((below = panel_below(below)) != NULL) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
196 if (sy > below->win->_begy + below->win->_maxy || |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
197 ey < below->win->_begy) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
198 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
199 if (sx > below->win->_begx + below->win->_maxx || |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
200 ex < below->win->_begx) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
201 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
202 for (y = MAX(sy, below->win->_begy); y <= MIN(ey, below->win->_begy + below->win->_maxy); y++) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
203 if (mvwin_wch(below->win, y - below->win->_begy, sx - 1 - below->win->_begx, &ch) != OK) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
204 goto right; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
205 w = widestringwidth(ch.chars); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
206 if (w > 1 && (ch.attr & 1)) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
207 ch.chars[0] = ' '; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
208 ch.attr &= ~ A_CHARTEXT; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
209 mvwadd_wch(below->win, y - below->win->_begy, sx - 1 - below->win->_begx, &ch); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
210 touchline(below->win, y - below->win->_begy, 1); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
211 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
212 right: |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
213 if (mvwin_wch(below->win, y - below->win->_begy, ex + 1 - below->win->_begx, &ch) != OK) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
214 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
215 w = widestringwidth(ch.chars); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
216 if (w > 1 && !(ch.attr & 1)) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
217 ch.chars[0] = ' '; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
218 ch.attr &= ~ A_CHARTEXT; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
219 mvwadd_wch(below->win, y - below->win->_begy, ex + 1 - below->win->_begx, &ch); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
220 touchline(below->win, y - below->win->_begy, 1); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
221 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
222 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
223 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
224 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
225 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
226 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
227 |
15818 | 228 static gboolean |
229 update_screen(GntWM *wm) | |
230 { | |
231 if (wm->menu) { | |
232 GntMenu *top = wm->menu; | |
233 while (top) { | |
234 GntNode *node = g_hash_table_lookup(wm->nodes, top); | |
235 if (node) | |
236 top_panel(node->panel); | |
237 top = top->submenu; | |
238 } | |
239 } | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
240 work_around_for_ncurses_bug(); |
15818 | 241 update_panels(); |
242 doupdate(); | |
243 return TRUE; | |
244 } | |
245 | |
246 static gboolean | |
247 sanitize_position(GntWidget *widget, int *x, int *y) | |
248 { | |
249 int X_MAX = getmaxx(stdscr); | |
250 int Y_MAX = getmaxy(stdscr) - 1; | |
251 int w, h; | |
252 int nx, ny; | |
253 gboolean changed = FALSE; | |
254 | |
255 gnt_widget_get_size(widget, &w, &h); | |
256 if (x) { | |
257 if (*x + w > X_MAX) { | |
258 nx = MAX(0, X_MAX - w); | |
259 if (nx != *x) { | |
260 *x = nx; | |
261 changed = TRUE; | |
262 } | |
263 } | |
264 } | |
265 if (y) { | |
266 if (*y + h > Y_MAX) { | |
267 ny = MAX(0, Y_MAX - h); | |
268 if (ny != *y) { | |
269 *y = ny; | |
270 changed = TRUE; | |
271 } | |
272 } | |
273 } | |
274 return changed; | |
275 } | |
276 | |
277 static void | |
278 refresh_node(GntWidget *widget, GntNode *node, gpointer null) | |
279 { | |
280 int x, y, w, h; | |
281 int nw, nh; | |
282 | |
283 int X_MAX = getmaxx(stdscr); | |
284 int Y_MAX = getmaxy(stdscr) - 1; | |
285 | |
286 gnt_widget_get_position(widget, &x, &y); | |
287 gnt_widget_get_size(widget, &w, &h); | |
288 | |
289 if (sanitize_position(widget, &x, &y)) | |
290 gnt_screen_move_widget(widget, x, y); | |
291 | |
292 nw = MIN(w, X_MAX); | |
293 nh = MIN(h, Y_MAX); | |
294 if (nw != w || nh != h) | |
295 gnt_screen_resize_widget(widget, nw, nh); | |
296 } | |
297 | |
298 static void | |
299 read_window_positions(GntWM *wm) | |
300 { | |
301 #if GLIB_CHECK_VERSION(2,6,0) | |
302 GKeyFile *gfile = g_key_file_new(); | |
303 char *filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
304 GError *error = NULL; | |
305 char **keys; | |
306 gsize nk; | |
307 | |
308 if (!g_key_file_load_from_file(gfile, filename, G_KEY_FILE_NONE, &error)) { | |
309 g_printerr("GntWM: %s\n", error->message); | |
310 g_error_free(error); | |
311 g_free(filename); | |
312 return; | |
313 } | |
314 | |
315 keys = g_key_file_get_keys(gfile, "positions", &nk, &error); | |
316 if (error) { | |
317 g_printerr("GntWM: %s\n", error->message); | |
318 g_error_free(error); | |
319 error = NULL; | |
320 } else { | |
321 while (nk--) { | |
322 char *title = keys[nk]; | |
323 gsize l; | |
324 char **coords = g_key_file_get_string_list(gfile, "positions", title, &l, NULL); | |
325 if (l == 2) { | |
326 int x = atoi(coords[0]); | |
327 int y = atoi(coords[1]); | |
328 GntPosition *p = g_new0(GntPosition, 1); | |
329 p->x = x; | |
330 p->y = y; | |
331 g_hash_table_replace(wm->positions, g_strdup(title + 1), p); | |
332 } else { | |
333 g_printerr("GntWM: Invalid number of arguments for positioing a window.\n"); | |
334 } | |
335 g_strfreev(coords); | |
336 } | |
337 g_strfreev(keys); | |
338 } | |
339 | |
340 g_free(filename); | |
15964 | 341 g_key_file_free(gfile); |
15818 | 342 #endif |
343 } | |
344 | |
345 static gboolean check_idle(gpointer n) | |
346 { | |
347 if (idle_update) { | |
348 time(&last_active_time); | |
349 idle_update = FALSE; | |
350 } | |
351 return TRUE; | |
352 } | |
353 | |
354 static void | |
355 gnt_wm_init(GTypeInstance *instance, gpointer class) | |
356 { | |
357 GntWM *wm = GNT_WM(instance); | |
358 wm->list = NULL; | |
359 wm->ordered = NULL; | |
360 wm->event_stack = FALSE; | |
361 wm->windows = NULL; | |
362 wm->actions = NULL; | |
363 wm->nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node); | |
364 wm->positions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
365 if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE)) | |
366 read_window_positions(wm); | |
367 g_timeout_add(IDLE_CHECK_INTERVAL * 1000, check_idle, NULL); | |
368 time(&last_active_time); | |
369 } | |
370 | |
371 static void | |
372 switch_window(GntWM *wm, int direction) | |
373 { | |
374 GntWidget *w = NULL, *wid = NULL; | |
375 int pos; | |
376 | |
377 if (wm->_list.window || wm->menu) | |
378 return; | |
379 | |
380 if (!wm->ordered || !wm->ordered->next) | |
381 return; | |
382 | |
383 w = wm->ordered->data; | |
384 pos = g_list_index(wm->list, w); | |
385 pos += direction; | |
386 | |
387 if (pos < 0) | |
388 wid = g_list_last(wm->list)->data; | |
389 else if (pos >= g_list_length(wm->list)) | |
390 wid = wm->list->data; | |
391 else if (pos >= 0) | |
392 wid = g_list_nth_data(wm->list, pos); | |
393 | |
394 wm->ordered = g_list_bring_to_front(wm->ordered, wid); | |
395 | |
396 gnt_wm_raise_window(wm, wm->ordered->data); | |
397 | |
398 if (w != wid) { | |
399 gnt_widget_set_focus(w, FALSE); | |
400 } | |
401 } | |
402 | |
403 static gboolean | |
404 window_next(GntBindable *bindable, GList *null) | |
405 { | |
406 GntWM *wm = GNT_WM(bindable); | |
407 switch_window(wm, 1); | |
408 return TRUE; | |
409 } | |
410 | |
411 static gboolean | |
412 window_prev(GntBindable *bindable, GList *null) | |
413 { | |
414 GntWM *wm = GNT_WM(bindable); | |
415 switch_window(wm, -1); | |
416 return TRUE; | |
417 } | |
418 | |
419 static gboolean | |
420 switch_window_n(GntBindable *bind, GList *list) | |
421 { | |
422 GntWM *wm = GNT_WM(bind); | |
423 GntWidget *w = NULL; | |
424 GList *l; | |
425 int n; | |
426 | |
427 if (!wm->ordered) | |
428 return TRUE; | |
429 | |
430 if (list) | |
431 n = GPOINTER_TO_INT(list->data); | |
432 else | |
433 n = 0; | |
434 | |
435 w = wm->ordered->data; | |
436 | |
437 if ((l = g_list_nth(wm->list, n)) != NULL) | |
438 { | |
439 gnt_wm_raise_window(wm, l->data); | |
440 } | |
441 | |
442 if (l && w != l->data) | |
443 { | |
444 gnt_widget_set_focus(w, FALSE); | |
445 } | |
446 return TRUE; | |
447 } | |
448 | |
449 static gboolean | |
450 window_scroll_up(GntBindable *bindable, GList *null) | |
451 { | |
452 GntWM *wm = GNT_WM(bindable); | |
453 GntWidget *window; | |
454 GntNode *node; | |
455 | |
456 if (!wm->ordered) | |
457 return TRUE; | |
458 | |
459 window = wm->ordered->data; | |
460 node = g_hash_table_lookup(wm->nodes, window); | |
461 if (!node) | |
462 return TRUE; | |
463 | |
464 if (node->scroll) { | |
465 node->scroll--; | |
466 copy_win(window, node); | |
467 update_screen(wm); | |
468 } | |
469 return TRUE; | |
470 } | |
471 | |
472 static gboolean | |
473 window_scroll_down(GntBindable *bindable, GList *null) | |
474 { | |
475 GntWM *wm = GNT_WM(bindable); | |
476 GntWidget *window; | |
477 GntNode *node; | |
478 int w, h; | |
479 | |
480 if (!wm->ordered) | |
481 return TRUE; | |
482 | |
483 window = wm->ordered->data; | |
484 node = g_hash_table_lookup(wm->nodes, window); | |
485 if (!node) | |
486 return TRUE; | |
487 | |
488 gnt_widget_get_size(window, &w, &h); | |
489 if (h - node->scroll > getmaxy(node->window)) { | |
490 node->scroll++; | |
491 copy_win(window, node); | |
492 update_screen(wm); | |
493 } | |
494 return TRUE; | |
495 } | |
496 | |
497 static gboolean | |
498 window_close(GntBindable *bindable, GList *null) | |
499 { | |
500 GntWM *wm = GNT_WM(bindable); | |
501 | |
502 if (wm->_list.window) | |
503 return TRUE; | |
504 | |
505 if (wm->ordered) { | |
506 gnt_widget_destroy(wm->ordered->data); | |
507 } | |
508 | |
509 return TRUE; | |
510 } | |
511 | |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
512 |
17714
1abacdef8205
Alt-\ allows to rebind keys to the wm
Eric Polino <aluink@pidgin.im>
parents:
17713
diff
changeset
|
513 |
15818 | 514 static void |
515 destroy__list(GntWidget *widget, GntWM *wm) | |
516 { | |
517 wm->_list.window = NULL; | |
518 wm->_list.tree = NULL; | |
519 wm->windows = NULL; | |
520 wm->actions = NULL; | |
521 update_screen(wm); | |
522 } | |
523 | |
524 static void | |
525 setup__list(GntWM *wm) | |
526 { | |
527 GntWidget *tree, *win; | |
528 win = wm->_list.window = gnt_box_new(FALSE, FALSE); | |
529 gnt_box_set_toplevel(GNT_BOX(win), TRUE); | |
530 gnt_box_set_pad(GNT_BOX(win), 0); | |
531 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_TRANSIENT); | |
532 | |
533 tree = wm->_list.tree = gnt_tree_new(); | |
534 gnt_box_add_widget(GNT_BOX(win), tree); | |
535 | |
536 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy__list), wm); | |
537 } | |
538 | |
539 static void | |
540 window_list_activate(GntTree *tree, GntWM *wm) | |
541 { | |
542 GntWidget *widget = gnt_tree_get_selection_data(GNT_TREE(tree)); | |
543 | |
544 if (!wm->ordered || !widget) | |
545 return; | |
546 | |
547 gnt_widget_destroy(wm->_list.window); | |
548 gnt_wm_raise_window(wm, widget); | |
549 } | |
550 | |
551 static void | |
552 populate_window_list(GntWM *wm) | |
553 { | |
554 GList *iter; | |
555 GntTree *tree = GNT_TREE(wm->windows->tree); | |
556 for (iter = wm->list; iter; iter = iter->next) { | |
557 GntBox *box = GNT_BOX(iter->data); | |
558 | |
559 gnt_tree_add_row_last(tree, box, | |
560 gnt_tree_create_row(tree, box->title), NULL); | |
561 update_window_in_list(wm, GNT_WIDGET(box)); | |
562 } | |
563 } | |
564 | |
565 static gboolean | |
566 window_list_key_pressed(GntWidget *widget, const char *text, GntWM *wm) | |
567 { | |
568 if (text[1] == 0 && wm->ordered) { | |
569 GntWidget *sel = gnt_tree_get_selection_data(GNT_TREE(widget)); | |
570 switch (text[0]) { | |
571 case '-': | |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
572 case ',': |
15818 | 573 shift_window(wm, sel, -1); |
574 break; | |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
575 case '=': |
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
576 case '.': |
15818 | 577 shift_window(wm, sel, 1); |
578 break; | |
579 default: | |
580 return FALSE; | |
581 } | |
582 gnt_tree_remove_all(GNT_TREE(widget)); | |
583 populate_window_list(wm); | |
584 gnt_tree_set_selected(GNT_TREE(widget), sel); | |
585 return TRUE; | |
586 } | |
587 return FALSE; | |
588 } | |
589 | |
590 static gboolean | |
591 window_list(GntBindable *bindable, GList *null) | |
592 { | |
593 GntWM *wm = GNT_WM(bindable); | |
594 GntWidget *tree, *win; | |
595 | |
596 if (wm->_list.window || wm->menu) | |
597 return TRUE; | |
598 | |
599 if (!wm->ordered) | |
600 return TRUE; | |
601 | |
602 setup__list(wm); | |
603 wm->windows = &wm->_list; | |
604 | |
605 win = wm->windows->window; | |
606 tree = wm->windows->tree; | |
607 | |
608 gnt_box_set_title(GNT_BOX(win), "Window List"); | |
609 | |
610 populate_window_list(wm); | |
611 | |
612 gnt_tree_set_selected(GNT_TREE(tree), wm->ordered->data); | |
613 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), wm); | |
614 g_signal_connect(G_OBJECT(tree), "key_pressed", G_CALLBACK(window_list_key_pressed), wm); | |
615 | |
616 gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); | |
617 gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); | |
618 gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); | |
619 | |
620 gnt_widget_show(win); | |
621 return TRUE; | |
622 } | |
623 | |
624 static gboolean | |
625 dump_screen(GntBindable *bindable, GList *null) | |
626 { | |
627 int x, y; | |
628 chtype old = 0, now = 0; | |
629 FILE *file = fopen("dump.html", "w"); | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
630 struct { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
631 char ascii; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
632 char *unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
633 } unis[] = { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
634 {'q', "─"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
635 {'t', "├"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
636 {'u', "┤"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
637 {'x', "│"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
638 {'-', "↑"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
639 {'.', "↓"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
640 {'l', "┌"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
641 {'k', "┐"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
642 {'m', "└"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
643 {'j', "┘"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
644 {'a', "▒"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
645 {'\0', NULL} |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
646 }; |
15818 | 647 |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
648 fprintf(file, "<head>\n <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n</head>\n<body>\n"); |
15818 | 649 fprintf(file, "<pre>"); |
650 for (y = 0; y < getmaxy(stdscr); y++) { | |
651 for (x = 0; x < getmaxx(stdscr); x++) { | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
652 char ch[2] = {0, 0}, *print; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
653 #ifdef NO_WIDECHAR |
15818 | 654 now = mvwinch(curscr, y, x); |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
655 ch[0] = now & A_CHARTEXT; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
656 now ^= ch[0]; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
657 #else |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
658 cchar_t wch; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
659 char unicode[12]; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
660 mvwin_wch(curscr, y, x, &wch); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
661 now = wch.attr; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
662 ch[0] = (char)(wch.chars[0] & 0xff); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
663 #endif |
15818 | 664 |
665 #define CHECK(attr, start, end) \ | |
666 do \ | |
667 { \ | |
668 if (now & attr) \ | |
669 { \ | |
670 if (!(old & attr)) \ | |
671 fprintf(file, "%s", start); \ | |
672 } \ | |
673 else if (old & attr) \ | |
674 { \ | |
675 fprintf(file, "%s", end); \ | |
676 } \ | |
677 } while (0) | |
678 | |
679 CHECK(A_BOLD, "<b>", "</b>"); | |
680 CHECK(A_UNDERLINE, "<u>", "</u>"); | |
681 CHECK(A_BLINK, "<blink>", "</blink>"); | |
682 | |
683 if ((now & A_COLOR) != (old & A_COLOR) || | |
684 (now & A_REVERSE) != (old & A_REVERSE)) | |
685 { | |
686 int ret; | |
687 short fgp, bgp, r, g, b; | |
688 struct | |
689 { | |
690 int r, g, b; | |
691 } fg, bg; | |
692 | |
693 ret = pair_content(PAIR_NUMBER(now & A_COLOR), &fgp, &bgp); | |
694 if (fgp == -1) | |
695 fgp = COLOR_BLACK; | |
696 if (bgp == -1) | |
697 bgp = COLOR_WHITE; | |
698 if (now & A_REVERSE) | |
17174
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
699 { |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
700 short tmp = fgp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
701 fgp = bgp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
702 bgp = tmp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
703 } |
15818 | 704 ret = color_content(fgp, &r, &g, &b); |
705 fg.r = r; fg.b = b; fg.g = g; | |
706 ret = color_content(bgp, &r, &g, &b); | |
707 bg.r = r; bg.b = b; bg.g = g; | |
708 #define ADJUST(x) (x = x * 255 / 1000) | |
709 ADJUST(fg.r); | |
710 ADJUST(fg.g); | |
711 ADJUST(fg.b); | |
712 ADJUST(bg.r); | |
713 ADJUST(bg.b); | |
714 ADJUST(bg.g); | |
715 | |
716 if (x) fprintf(file, "</span>"); | |
717 fprintf(file, "<span style=\"background:#%02x%02x%02x;color:#%02x%02x%02x\">", | |
718 bg.r, bg.g, bg.b, fg.r, fg.g, fg.b); | |
719 } | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
720 print = ch; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
721 #ifndef NO_WIDECHAR |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
722 if (wch.chars[0] > 255) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
723 snprintf(unicode, sizeof(unicode), "&#x%x;", wch.chars[0]); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
724 print = unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
725 } |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
726 #endif |
15818 | 727 if (now & A_ALTCHARSET) |
728 { | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
729 int u; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
730 for (u = 0; unis[u].ascii; u++) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
731 if (ch[0] == unis[u].ascii) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
732 print = unis[u].unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
733 break; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
734 } |
15818 | 735 } |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
736 if (!unis[u].ascii) |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
737 print = " "; |
15818 | 738 } |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
739 if (ch[0] == '&') |
15818 | 740 fprintf(file, "&"); |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
741 else if (ch[0] == '<') |
15818 | 742 fprintf(file, "<"); |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
743 else if (ch[0] == '>') |
15818 | 744 fprintf(file, ">"); |
745 else | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
746 fprintf(file, "%s", print); |
15818 | 747 old = now; |
748 } | |
749 fprintf(file, "</span>\n"); | |
750 old = 0; | |
751 } | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
752 fprintf(file, "</pre>\n</body>"); |
15818 | 753 fclose(file); |
754 return TRUE; | |
755 } | |
756 | |
757 static void | |
758 shift_window(GntWM *wm, GntWidget *widget, int dir) | |
759 { | |
760 GList *all = wm->list; | |
761 GList *list = g_list_find(all, widget); | |
762 int length, pos; | |
763 if (!list) | |
764 return; | |
765 | |
766 length = g_list_length(all); | |
767 pos = g_list_position(all, list); | |
768 | |
769 pos += dir; | |
770 if (dir > 0) | |
771 pos++; | |
772 | |
773 if (pos < 0) | |
774 pos = length; | |
775 else if (pos > length) | |
776 pos = 0; | |
777 | |
778 all = g_list_insert(all, widget, pos); | |
779 all = g_list_delete_link(all, list); | |
780 wm->list = all; | |
781 draw_taskbar(wm, FALSE); | |
782 } | |
783 | |
784 static gboolean | |
785 shift_left(GntBindable *bindable, GList *null) | |
786 { | |
787 GntWM *wm = GNT_WM(bindable); | |
788 if (wm->_list.window) | |
789 return TRUE; | |
790 | |
791 shift_window(wm, wm->ordered->data, -1); | |
792 return TRUE; | |
793 } | |
794 | |
795 static gboolean | |
796 shift_right(GntBindable *bindable, GList *null) | |
797 { | |
798 GntWM *wm = GNT_WM(bindable); | |
799 if (wm->_list.window) | |
800 return TRUE; | |
801 | |
802 shift_window(wm, wm->ordered->data, 1); | |
803 return TRUE; | |
804 } | |
805 | |
806 static void | |
807 action_list_activate(GntTree *tree, GntWM *wm) | |
808 { | |
809 GntAction *action = gnt_tree_get_selection_data(tree); | |
810 action->callback(); | |
811 gnt_widget_destroy(wm->_list.window); | |
812 } | |
813 | |
814 static int | |
815 compare_action(gconstpointer p1, gconstpointer p2) | |
816 { | |
817 const GntAction *a1 = p1; | |
818 const GntAction *a2 = p2; | |
819 | |
820 return g_utf8_collate(a1->label, a2->label); | |
821 } | |
822 | |
823 static gboolean | |
824 list_actions(GntBindable *bindable, GList *null) | |
825 { | |
826 GntWidget *tree, *win; | |
827 GList *iter; | |
828 GntWM *wm = GNT_WM(bindable); | |
829 if (wm->_list.window || wm->menu) | |
830 return TRUE; | |
831 | |
832 if (wm->acts == NULL) | |
833 return TRUE; | |
834 | |
835 setup__list(wm); | |
836 wm->actions = &wm->_list; | |
837 | |
838 win = wm->actions->window; | |
839 tree = wm->actions->tree; | |
840 | |
841 gnt_box_set_title(GNT_BOX(win), "Actions"); | |
842 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
843 /* XXX: Do we really want this? */ | |
844 gnt_tree_set_compare_func(GNT_TREE(tree), compare_action); | |
845 | |
846 for (iter = wm->acts; iter; iter = iter->next) { | |
847 GntAction *action = iter->data; | |
848 gnt_tree_add_row_last(GNT_TREE(tree), action, | |
849 gnt_tree_create_row(GNT_TREE(tree), action->label), NULL); | |
850 } | |
851 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), wm); | |
852 gnt_widget_set_size(tree, 0, g_list_length(wm->acts)); | |
853 gnt_widget_set_position(win, 0, getmaxy(stdscr) - 3 - g_list_length(wm->acts)); | |
854 | |
855 gnt_widget_show(win); | |
856 return TRUE; | |
857 } | |
858 | |
859 #ifndef NO_WIDECHAR | |
860 static int | |
861 widestringwidth(wchar_t *wide) | |
862 { | |
863 int len, ret; | |
864 char *string; | |
865 | |
866 len = wcstombs(NULL, wide, 0) + 1; | |
867 string = g_new0(char, len); | |
868 wcstombs(string, wide, len); | |
869 ret = gnt_util_onscreen_width(string, NULL); | |
870 g_free(string); | |
871 return ret; | |
872 } | |
873 #endif | |
874 | |
875 /* Returns the onscreen width of the character at the position */ | |
876 static int | |
877 reverse_char(WINDOW *d, int y, int x, gboolean set) | |
878 { | |
879 #define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) | |
880 | |
881 #ifdef NO_WIDECHAR | |
882 chtype ch; | |
883 ch = mvwinch(d, y, x); | |
884 mvwaddch(d, y, x, DECIDE(ch)); | |
885 return 1; | |
886 #else | |
887 cchar_t ch; | |
888 int wc = 1; | |
889 if (mvwin_wch(d, y, x, &ch) == OK) { | |
890 wc = widestringwidth(ch.chars); | |
891 ch.attr = DECIDE(ch.attr); | |
892 ch.attr &= WA_ATTRIBUTES; /* XXX: This is a workaround for a bug */ | |
893 mvwadd_wch(d, y, x, &ch); | |
894 } | |
895 | |
896 return wc; | |
897 #endif | |
898 } | |
899 | |
900 static void | |
901 window_reverse(GntWidget *win, gboolean set, GntWM *wm) | |
902 { | |
903 int i; | |
904 int w, h; | |
905 WINDOW *d; | |
906 | |
907 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER)) | |
908 return; | |
909 | |
910 d = win->window; | |
911 gnt_widget_get_size(win, &w, &h); | |
912 | |
913 if (gnt_widget_has_shadow(win)) { | |
914 --w; | |
915 --h; | |
916 } | |
917 | |
918 /* the top and bottom */ | |
919 for (i = 0; i < w; i += reverse_char(d, 0, i, set)); | |
920 for (i = 0; i < w; i += reverse_char(d, h-1, i, set)); | |
921 | |
922 /* the left and right */ | |
923 for (i = 0; i < h; i += reverse_char(d, i, 0, set)); | |
924 for (i = 0; i < h; i += reverse_char(d, i, w-1, set)); | |
925 | |
926 copy_win(win, g_hash_table_lookup(wm->nodes, win)); | |
927 update_screen(wm); | |
928 } | |
929 | |
930 static gboolean | |
931 start_move(GntBindable *bindable, GList *null) | |
932 { | |
933 GntWM *wm = GNT_WM(bindable); | |
934 if (wm->_list.window || wm->menu) | |
935 return TRUE; | |
936 if (!wm->ordered) | |
937 return TRUE; | |
938 | |
939 wm->mode = GNT_KP_MODE_MOVE; | |
940 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
941 | |
942 return TRUE; | |
943 } | |
944 | |
945 static gboolean | |
946 start_resize(GntBindable *bindable, GList *null) | |
947 { | |
948 GntWM *wm = GNT_WM(bindable); | |
949 if (wm->_list.window || wm->menu) | |
950 return TRUE; | |
951 if (!wm->ordered) | |
952 return TRUE; | |
953 | |
954 wm->mode = GNT_KP_MODE_RESIZE; | |
955 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
956 | |
957 return TRUE; | |
958 } | |
959 | |
960 static gboolean | |
961 wm_quit(GntBindable *bindable, GList *list) | |
962 { | |
963 GntWM *wm = GNT_WM(bindable); | |
964 if (write_timeout) | |
965 write_already(wm); | |
966 g_main_loop_quit(wm->loop); | |
967 return TRUE; | |
968 } | |
969 | |
970 static gboolean | |
971 return_true(GntWM *wm, GntWidget *w, int *a, int *b) | |
972 { | |
973 return TRUE; | |
974 } | |
975 | |
976 static gboolean | |
977 refresh_screen(GntBindable *bindable, GList *null) | |
978 { | |
979 GntWM *wm = GNT_WM(bindable); | |
980 | |
981 endwin(); | |
982 refresh(); | |
983 curs_set(0); /* endwin resets the cursor to normal */ | |
984 | |
985 g_hash_table_foreach(wm->nodes, (GHFunc)refresh_node, NULL); | |
986 update_screen(wm); | |
987 draw_taskbar(wm, TRUE); | |
988 | |
989 return FALSE; | |
990 } | |
991 | |
16526
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
992 static gboolean |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
993 toggle_clipboard(GntBindable *bindable, GList *n) |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
994 { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
995 static GntWidget *clip; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
996 gchar *text; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
997 int maxx, maxy; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
998 if (clip) { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
999 gnt_widget_destroy(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1000 clip = NULL; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1001 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1002 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1003 getmaxyx(stdscr, maxy, maxx); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1004 text = gnt_get_clipboard_string(); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1005 clip = gnt_hwindow_new(FALSE); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1006 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_TRANSIENT); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1007 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_NO_BORDER); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1008 gnt_box_set_pad(GNT_BOX(clip), 0); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1009 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" ")); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1010 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(text)); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1011 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" ")); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1012 gnt_widget_set_position(clip, 0, 0); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1013 gnt_widget_draw(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1014 g_free(text); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1015 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1016 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1017 |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1018 static gboolean |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1019 ignore_keys_start(GntBindable *bindable, GList *n) |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1020 { |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1021 GntWM *wm = GNT_WM(bindable); |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1022 |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1023 if(!wm->menu && !wm->_list.window && wm->mode == GNT_KP_MODE_NORMAL){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1024 ignore_keys = TRUE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1025 return TRUE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1026 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1027 return FALSE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1028 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1029 |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1030 static gboolean |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1031 ignore_keys_end(GntBindable *bindable, GList *n) |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1032 { |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1033 return ignore_keys ? !(ignore_keys = FALSE) : FALSE; |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1034 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1035 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1036 static gboolean |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1037 help_for_bindable(GntWM *wm, GntBindable *bindable) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1038 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1039 gboolean ret = TRUE; |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1040 GntBindableClass *klass = GNT_BINDABLE_GET_CLASS(bindable); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1041 |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1042 if (klass->help_window) { |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1043 gnt_wm_raise_window(wm, GNT_WIDGET(klass->help_window)); |
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1044 } else { |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1045 ret = gnt_bindable_build_help_window(bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1046 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1047 return ret; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1048 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1049 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1050 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1051 static gboolean |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1052 help_for_wm(GntBindable *bindable, GList *null) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1053 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1054 return help_for_bindable(GNT_WM(bindable),bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1055 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1056 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1057 static gboolean |
17723
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1058 help_for_window(GntBindable *bindable, GList *null) |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1059 { |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1060 GntWM *wm = GNT_WM(bindable); |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1061 GntWidget *widget = wm->ordered->data; |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1062 |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1063 return help_for_bindable(wm,GNT_BINDABLE(widget)); |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1064 } |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1065 |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1066 static gboolean |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1067 help_for_widget(GntBindable *bindable, GList *null) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1068 { |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1069 GntWM *wm = GNT_WM(bindable); |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1070 GntWidget *widget; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1071 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1072 if (!wm->ordered) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1073 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1074 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1075 widget = wm->ordered->data; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1076 if (!GNT_IS_BOX(widget)) |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1077 return TRUE; |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1078 |
17722
15988e2bd270
Mostly whitespace changes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17721
diff
changeset
|
1079 return help_for_bindable(wm, GNT_BINDABLE(GNT_BOX(widget)->active)); |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1080 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1081 } |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1082 |
15818 | 1083 static void |
1084 gnt_wm_class_init(GntWMClass *klass) | |
1085 { | |
1086 int i; | |
1087 | |
17721
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1088 |
3ee6ea8a66f8
Moved rebinding functionality into GntBindable.
Eric Polino <aluink@pidgin.im>
parents:
17720
diff
changeset
|
1089 |
15818 | 1090 klass->new_window = gnt_wm_new_window_real; |
1091 klass->decorate_window = NULL; | |
1092 klass->close_window = NULL; | |
1093 klass->window_resize_confirm = return_true; | |
1094 klass->window_resized = gnt_wm_win_resized; | |
1095 klass->window_move_confirm = return_true; | |
1096 klass->window_moved = gnt_wm_win_moved; | |
1097 klass->window_update = NULL; | |
1098 klass->key_pressed = NULL; | |
1099 klass->mouse_clicked = NULL; | |
1100 klass->give_focus = gnt_wm_give_focus; | |
1101 | |
1102 signals[SIG_NEW_WIN] = | |
1103 g_signal_new("new_win", | |
1104 G_TYPE_FROM_CLASS(klass), | |
1105 G_SIGNAL_RUN_LAST, | |
1106 G_STRUCT_OFFSET(GntWMClass, new_window), | |
1107 NULL, NULL, | |
1108 g_cclosure_marshal_VOID__POINTER, | |
1109 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1110 signals[SIG_DECORATE_WIN] = | |
1111 g_signal_new("decorate_win", | |
1112 G_TYPE_FROM_CLASS(klass), | |
1113 G_SIGNAL_RUN_LAST, | |
1114 G_STRUCT_OFFSET(GntWMClass, decorate_window), | |
1115 NULL, NULL, | |
1116 g_cclosure_marshal_VOID__POINTER, | |
1117 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1118 signals[SIG_CLOSE_WIN] = | |
1119 g_signal_new("close_win", | |
1120 G_TYPE_FROM_CLASS(klass), | |
1121 G_SIGNAL_RUN_LAST, | |
1122 G_STRUCT_OFFSET(GntWMClass, close_window), | |
1123 NULL, NULL, | |
1124 g_cclosure_marshal_VOID__POINTER, | |
1125 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1126 signals[SIG_CONFIRM_RESIZE] = | |
1127 g_signal_new("confirm_resize", | |
1128 G_TYPE_FROM_CLASS(klass), | |
1129 G_SIGNAL_RUN_LAST, | |
1130 G_STRUCT_OFFSET(GntWMClass, window_resize_confirm), | |
1131 gnt_boolean_handled_accumulator, NULL, | |
1132 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1133 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1134 | |
1135 signals[SIG_CONFIRM_MOVE] = | |
1136 g_signal_new("confirm_move", | |
1137 G_TYPE_FROM_CLASS(klass), | |
1138 G_SIGNAL_RUN_LAST, | |
1139 G_STRUCT_OFFSET(GntWMClass, window_move_confirm), | |
1140 gnt_boolean_handled_accumulator, NULL, | |
1141 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1142 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1143 | |
1144 signals[SIG_RESIZED] = | |
1145 g_signal_new("window_resized", | |
1146 G_TYPE_FROM_CLASS(klass), | |
1147 G_SIGNAL_RUN_LAST, | |
1148 G_STRUCT_OFFSET(GntWMClass, window_resized), | |
1149 NULL, NULL, | |
1150 g_cclosure_marshal_VOID__POINTER, | |
1151 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1152 signals[SIG_MOVED] = | |
1153 g_signal_new("window_moved", | |
1154 G_TYPE_FROM_CLASS(klass), | |
1155 G_SIGNAL_RUN_LAST, | |
1156 G_STRUCT_OFFSET(GntWMClass, window_moved), | |
1157 NULL, NULL, | |
1158 g_cclosure_marshal_VOID__POINTER, | |
1159 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1160 signals[SIG_UPDATE_WIN] = | |
1161 g_signal_new("window_update", | |
1162 G_TYPE_FROM_CLASS(klass), | |
1163 G_SIGNAL_RUN_LAST, | |
1164 G_STRUCT_OFFSET(GntWMClass, window_update), | |
1165 NULL, NULL, | |
1166 g_cclosure_marshal_VOID__POINTER, | |
1167 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1168 signals[SIG_GIVE_FOCUS] = | |
1169 g_signal_new("give_focus", | |
1170 G_TYPE_FROM_CLASS(klass), | |
1171 G_SIGNAL_RUN_LAST, | |
1172 G_STRUCT_OFFSET(GntWMClass, give_focus), | |
1173 NULL, NULL, | |
1174 g_cclosure_marshal_VOID__POINTER, | |
1175 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1176 | |
1177 signals[SIG_MOUSE_CLICK] = | |
1178 g_signal_new("mouse_clicked", | |
1179 G_TYPE_FROM_CLASS(klass), | |
1180 G_SIGNAL_RUN_LAST, | |
1181 G_STRUCT_OFFSET(GntWMClass, mouse_clicked), | |
1182 gnt_boolean_handled_accumulator, NULL, | |
1183 gnt_closure_marshal_BOOLEAN__INT_INT_INT_POINTER, | |
1184 G_TYPE_BOOLEAN, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_POINTER); | |
1185 | |
1186 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-next", window_next, | |
1187 "\033" "n", NULL); | |
1188 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-prev", window_prev, | |
1189 "\033" "p", NULL); | |
1190 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-close", window_close, | |
1191 "\033" "c", NULL); | |
1192 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-list", window_list, | |
1193 "\033" "w", NULL); | |
1194 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "dump-screen", dump_screen, | |
1195 "\033" "d", NULL); | |
1196 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-left", shift_left, | |
1197 "\033" ",", NULL); | |
1198 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-right", shift_right, | |
1199 "\033" ".", NULL); | |
1200 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "action-list", list_actions, | |
1201 "\033" "a", NULL); | |
1202 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-move", start_move, | |
1203 "\033" "m", NULL); | |
1204 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-resize", start_resize, | |
1205 "\033" "r", NULL); | |
1206 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "wm-quit", wm_quit, | |
1207 "\033" "q", NULL); | |
1208 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "refresh-screen", refresh_screen, | |
1209 "\033" "l", NULL); | |
1210 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "switch-window-n", switch_window_n, | |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1211 NULL, NULL); |
15818 | 1212 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-down", window_scroll_down, |
1213 "\033" GNT_KEY_CTRL_J, NULL); | |
1214 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-up", window_scroll_up, | |
1215 "\033" GNT_KEY_CTRL_K, NULL); | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1216 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-widget", help_for_widget, |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1217 "\033" "/", NULL); |
17714
1abacdef8205
Alt-\ allows to rebind keys to the wm
Eric Polino <aluink@pidgin.im>
parents:
17713
diff
changeset
|
1218 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-wm", help_for_wm, |
1abacdef8205
Alt-\ allows to rebind keys to the wm
Eric Polino <aluink@pidgin.im>
parents:
17713
diff
changeset
|
1219 "\033" "\\", NULL); |
17723
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1220 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-window", help_for_window, |
c918d59d5936
Added the ability to change the key bindings on the active window.
Eric Polino <aluink@pidgin.im>
parents:
17722
diff
changeset
|
1221 "\033" "|", NULL); |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1222 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-clipboard", toggle_clipboard, |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1223 "\033" "C", NULL); |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1224 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-start", ignore_keys_start, |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1225 GNT_KEY_CTRL_G, NULL); |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1226 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-end", ignore_keys_end, |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1227 "\033" GNT_KEY_CTRL_G, NULL); |
15818 | 1228 |
1229 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
1230 | |
1231 /* Make sure Alt+x are detected properly. */ | |
1232 for (i = '0'; i <= '9'; i++) { | |
1233 char str[] = "\033X"; | |
1234 str[1] = i; | |
1235 gnt_keys_add_combination(str); | |
1236 } | |
1237 | |
1238 GNTDEBUG; | |
1239 } | |
1240 | |
1241 /****************************************************************************** | |
1242 * GntWM API | |
1243 *****************************************************************************/ | |
1244 GType | |
1245 gnt_wm_get_gtype(void) | |
1246 { | |
1247 static GType type = 0; | |
1248 | |
1249 if(type == 0) { | |
1250 static const GTypeInfo info = { | |
1251 sizeof(GntWMClass), | |
1252 NULL, /* base_init */ | |
1253 NULL, /* base_finalize */ | |
1254 (GClassInitFunc)gnt_wm_class_init, | |
1255 NULL, | |
1256 NULL, /* class_data */ | |
1257 sizeof(GntWM), | |
1258 0, /* n_preallocs */ | |
1259 gnt_wm_init, /* instance_init */ | |
1260 NULL /* value_table */ | |
1261 }; | |
1262 | |
1263 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
1264 "GntWM", | |
1265 &info, 0); | |
1266 } | |
1267 | |
1268 return type; | |
1269 } | |
1270 static void | |
1271 update_window_in_list(GntWM *wm, GntWidget *wid) | |
1272 { | |
1273 GntTextFormatFlags flag = 0; | |
1274 | |
1275 if (wm->windows == NULL) | |
1276 return; | |
1277 | |
1278 if (wid == wm->ordered->data) | |
1279 flag |= GNT_TEXT_FLAG_DIM; | |
1280 else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT)) | |
1281 flag |= GNT_TEXT_FLAG_BOLD; | |
1282 | |
1283 gnt_tree_set_row_flags(GNT_TREE(wm->windows->tree), wid, flag); | |
1284 } | |
1285 | |
1286 static void | |
1287 gnt_wm_new_window_real(GntWM *wm, GntWidget *widget) | |
1288 { | |
1289 GntNode *node; | |
1290 gboolean transient = FALSE; | |
1291 | |
1292 if (widget->window == NULL) | |
1293 return; | |
1294 | |
1295 node = g_new0(GntNode, 1); | |
1296 node->me = widget; | |
1297 node->scroll = 0; | |
1298 | |
1299 g_hash_table_replace(wm->nodes, widget, node); | |
1300 | |
1301 refresh_node(widget, node, NULL); | |
1302 | |
1303 transient = !!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT); | |
1304 | |
1305 #if 1 | |
1306 { | |
1307 int x, y, w, h, maxx, maxy; | |
1308 gboolean shadow = TRUE; | |
1309 | |
1310 if (!gnt_widget_has_shadow(widget)) | |
1311 shadow = FALSE; | |
1312 x = widget->priv.x; | |
1313 y = widget->priv.y; | |
1314 w = widget->priv.width; | |
1315 h = widget->priv.height; | |
1316 | |
1317 getmaxyx(stdscr, maxy, maxx); | |
1318 maxy -= 1; /* room for the taskbar */ | |
1319 maxy -= shadow; | |
1320 maxx -= shadow; | |
1321 | |
1322 x = MAX(0, x); | |
1323 y = MAX(0, y); | |
1324 if (x + w >= maxx) | |
1325 x = MAX(0, maxx - w); | |
1326 if (y + h >= maxy) | |
1327 y = MAX(0, maxy - h); | |
1328 | |
1329 w = MIN(w, maxx); | |
1330 h = MIN(h, maxy); | |
1331 node->window = newwin(h + shadow, w + shadow, y, x); | |
1332 copy_win(widget, node); | |
1333 } | |
1334 #endif | |
1335 | |
1336 node->panel = new_panel(node->window); | |
1337 set_panel_userptr(node->panel, node); | |
1338 | |
1339 if (!transient) { | |
1340 if (node->me != wm->_list.window) { | |
1341 GntWidget *w = NULL; | |
1342 | |
1343 if (wm->ordered) | |
1344 w = wm->ordered->data; | |
1345 | |
1346 wm->list = g_list_append(wm->list, widget); | |
1347 | |
1348 if (wm->event_stack) | |
1349 wm->ordered = g_list_prepend(wm->ordered, widget); | |
1350 else | |
1351 wm->ordered = g_list_append(wm->ordered, widget); | |
1352 | |
1353 gnt_widget_set_focus(widget, TRUE); | |
1354 if (w) | |
1355 gnt_widget_set_focus(w, FALSE); | |
1356 } | |
1357 | |
1358 if (wm->event_stack || node->me == wm->_list.window) { | |
1359 gnt_wm_raise_window(wm, node->me); | |
1360 } else { | |
1361 bottom_panel(node->panel); /* New windows should not grab focus */ | |
1362 gnt_widget_set_urgent(node->me); | |
1363 } | |
1364 } | |
1365 } | |
1366 | |
1367 void gnt_wm_new_window(GntWM *wm, GntWidget *widget) | |
1368 { | |
1369 while (widget->parent) | |
1370 widget = widget->parent; | |
1371 | |
1372 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_INVISIBLE) || | |
1373 g_hash_table_lookup(wm->nodes, widget)) { | |
1374 update_screen(wm); | |
1375 return; | |
1376 } | |
1377 | |
1378 if (GNT_IS_BOX(widget)) { | |
1379 const char *title = GNT_BOX(widget)->title; | |
1380 GntPosition *p = NULL; | |
1381 if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) { | |
1382 sanitize_position(widget, &p->x, &p->y); | |
1383 gnt_widget_set_position(widget, p->x, p->y); | |
1384 mvwin(widget->window, p->y, p->x); | |
1385 } | |
1386 } | |
1387 | |
1388 g_signal_emit(wm, signals[SIG_NEW_WIN], 0, widget); | |
1389 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1390 | |
1391 if (wm->windows && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { | |
1392 if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && wm->_list.window != widget | |
1393 && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
1394 gnt_tree_add_row_last(GNT_TREE(wm->windows->tree), widget, | |
1395 gnt_tree_create_row(GNT_TREE(wm->windows->tree), GNT_BOX(widget)->title), | |
1396 NULL); | |
1397 update_window_in_list(wm, widget); | |
1398 } | |
1399 } | |
1400 | |
1401 update_screen(wm); | |
1402 draw_taskbar(wm, FALSE); | |
1403 } | |
1404 | |
1405 void gnt_wm_window_decorate(GntWM *wm, GntWidget *widget) | |
1406 { | |
1407 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1408 } | |
1409 | |
1410 void gnt_wm_window_close(GntWM *wm, GntWidget *widget) | |
1411 { | |
1412 GntNode *node; | |
1413 int pos; | |
1414 | |
1415 if ((node = g_hash_table_lookup(wm->nodes, widget)) == NULL) | |
1416 return; | |
1417 | |
1418 g_signal_emit(wm, signals[SIG_CLOSE_WIN], 0, widget); | |
1419 g_hash_table_remove(wm->nodes, widget); | |
1420 | |
1421 if (wm->windows) { | |
1422 gnt_tree_remove(GNT_TREE(wm->windows->tree), widget); | |
1423 } | |
1424 | |
1425 pos = g_list_index(wm->list, widget); | |
1426 | |
1427 if (pos != -1) { | |
1428 wm->list = g_list_remove(wm->list, widget); | |
1429 wm->ordered = g_list_remove(wm->ordered, widget); | |
1430 | |
1431 if (wm->ordered) | |
1432 gnt_wm_raise_window(wm, wm->ordered->data); | |
1433 } | |
1434 | |
1435 update_screen(wm); | |
1436 draw_taskbar(wm, FALSE); | |
1437 } | |
1438 | |
1439 time_t gnt_wm_get_idle_time() | |
1440 { | |
1441 return time(NULL) - last_active_time; | |
1442 } | |
1443 | |
1444 gboolean gnt_wm_process_input(GntWM *wm, const char *keys) | |
1445 { | |
1446 gboolean ret = FALSE; | |
1447 | |
1448 keys = gnt_bindable_remap_keys(GNT_BINDABLE(wm), keys); | |
1449 | |
1450 idle_update = TRUE; | |
1451 | |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1452 if(ignore_keys){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1453 if(keys && !strcmp(keys, "\033" GNT_KEY_CTRL_G)){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1454 if(gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1455 return TRUE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1456 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1457 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1458 return wm->ordered ? gnt_widget_key_pressed(GNT_WIDGET(wm->ordered->data), keys) : FALSE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1459 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1460 |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1461 if (gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)) { |
15818 | 1462 return TRUE; |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1463 } |
15818 | 1464 |
1465 /* Do some manual checking */ | |
1466 if (wm->ordered && wm->mode != GNT_KP_MODE_NORMAL) { | |
1467 int xmin = 0, ymin = 0, xmax = getmaxx(stdscr), ymax = getmaxy(stdscr) - 1; | |
1468 int x, y, w, h; | |
1469 GntWidget *widget = GNT_WIDGET(wm->ordered->data); | |
1470 int ox, oy, ow, oh; | |
1471 | |
1472 gnt_widget_get_position(widget, &x, &y); | |
1473 gnt_widget_get_size(widget, &w, &h); | |
1474 ox = x; oy = y; | |
1475 ow = w; oh = h; | |
1476 | |
1477 if (wm->mode == GNT_KP_MODE_MOVE) { | |
1478 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1479 if (x > xmin) | |
1480 x--; | |
1481 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1482 if (x + w < xmax) | |
1483 x++; | |
1484 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1485 if (y > ymin) | |
1486 y--; | |
1487 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1488 if (y + h < ymax) | |
1489 y++; | |
1490 } | |
1491 if (ox != x || oy != y) { | |
1492 gnt_screen_move_widget(widget, x, y); | |
1493 window_reverse(widget, TRUE, wm); | |
1494 return TRUE; | |
1495 } | |
1496 } else if (wm->mode == GNT_KP_MODE_RESIZE) { | |
1497 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1498 w--; | |
1499 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1500 if (x + w < xmax) | |
1501 w++; | |
1502 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1503 h--; | |
1504 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1505 if (y + h < ymax) | |
1506 h++; | |
1507 } | |
1508 if (oh != h || ow != w) { | |
1509 gnt_screen_resize_widget(widget, w, h); | |
1510 window_reverse(widget, TRUE, wm); | |
1511 return TRUE; | |
1512 } | |
1513 } | |
1514 if (strcmp(keys, "\r") == 0 || strcmp(keys, "\033") == 0) { | |
1515 window_reverse(widget, FALSE, wm); | |
1516 wm->mode = GNT_KP_MODE_NORMAL; | |
1517 } | |
1518 return TRUE; | |
1519 } | |
1520 | |
1521 /* Escape to close the window-list or action-list window */ | |
1522 if (strcmp(keys, "\033") == 0) { | |
1523 if (wm->_list.window) { | |
1524 gnt_widget_destroy(wm->_list.window); | |
1525 return TRUE; | |
1526 } | |
1527 } else if (keys[0] == '\033' && isdigit(keys[1]) && keys[2] == '\0') { | |
1528 /* Alt+x for quick switch */ | |
1529 int n = *(keys + 1) - '0'; | |
1530 GList *list = NULL; | |
1531 | |
1532 if (n == 0) | |
1533 n = 10; | |
1534 | |
1535 list = g_list_append(list, GINT_TO_POINTER(n - 1)); | |
1536 switch_window_n(GNT_BINDABLE(wm), list); | |
1537 g_list_free(list); | |
1538 return TRUE; | |
1539 } | |
1540 | |
1541 if (wm->menu) | |
1542 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->menu), keys); | |
1543 else if (wm->_list.window) | |
1544 ret = gnt_widget_key_pressed(wm->_list.window, keys); | |
1545 else if (wm->ordered) | |
1546 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->ordered->data), keys); | |
1547 return ret; | |
1548 } | |
1549 | |
1550 static void | |
1551 gnt_wm_win_resized(GntWM *wm, GntNode *node) | |
1552 { | |
1553 /*refresh_node(node->me, node, NULL);*/ | |
1554 } | |
1555 | |
1556 static void | |
1557 gnt_wm_win_moved(GntWM *wm, GntNode *node) | |
1558 { | |
1559 refresh_node(node->me, node, NULL); | |
1560 } | |
1561 | |
1562 void gnt_wm_resize_window(GntWM *wm, GntWidget *widget, int width, int height) | |
1563 { | |
1564 gboolean ret = TRUE; | |
1565 GntNode *node; | |
1566 int shadow; | |
1567 int maxx, maxy; | |
1568 | |
1569 while (widget->parent) | |
1570 widget = widget->parent; | |
1571 node = g_hash_table_lookup(wm->nodes, widget); | |
1572 if (!node) | |
1573 return; | |
1574 | |
1575 g_signal_emit(wm, signals[SIG_CONFIRM_RESIZE], 0, widget, &width, &height, &ret); | |
1576 if (!ret) | |
1577 return; /* resize is not permitted */ | |
1578 hide_panel(node->panel); | |
1579 gnt_widget_set_size(widget, width, height); | |
1580 gnt_widget_draw(widget); | |
1581 | |
1582 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
1583 maxx = getmaxx(stdscr) - shadow; | |
1584 maxy = getmaxy(stdscr) - 1 - shadow; | |
1585 height = MIN(height, maxy); | |
1586 width = MIN(width, maxx); | |
15978
2a82bc8d57f7
More fixes for resizing when shadow is turned on.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
1587 wresize(node->window, height, width); |
15818 | 1588 replace_panel(node->panel, node->window); |
1589 | |
1590 g_signal_emit(wm, signals[SIG_RESIZED], 0, node); | |
1591 | |
1592 show_panel(node->panel); | |
1593 update_screen(wm); | |
1594 } | |
1595 | |
1596 static void | |
1597 write_gdi(gpointer key, gpointer value, gpointer data) | |
1598 { | |
1599 GntPosition *p = value; | |
1600 fprintf(data, ".%s = %d;%d\n", (char *)key, p->x, p->y); | |
1601 } | |
1602 | |
1603 static gboolean | |
1604 write_already(gpointer data) | |
1605 { | |
1606 GntWM *wm = data; | |
1607 FILE *file; | |
1608 char *filename; | |
1609 | |
1610 filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
1611 | |
1612 file = fopen(filename, "wb"); | |
1613 if (file == NULL) { | |
1614 g_printerr("GntWM: error opening file to save positions\n"); | |
1615 } else { | |
1616 fprintf(file, "[positions]\n"); | |
1617 g_hash_table_foreach(wm->positions, write_gdi, file); | |
1618 fclose(file); | |
1619 } | |
1620 | |
1621 g_free(filename); | |
1622 g_source_remove(write_timeout); | |
1623 write_timeout = 0; | |
1624 return FALSE; | |
1625 } | |
1626 | |
1627 static void | |
1628 write_positions_to_file(GntWM *wm) | |
1629 { | |
1630 if (write_timeout) { | |
1631 g_source_remove(write_timeout); | |
1632 } | |
1633 write_timeout = g_timeout_add(10000, write_already, wm); | |
1634 } | |
1635 | |
1636 void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y) | |
1637 { | |
1638 gboolean ret = TRUE; | |
1639 GntNode *node; | |
1640 | |
1641 while (widget->parent) | |
1642 widget = widget->parent; | |
1643 node = g_hash_table_lookup(wm->nodes, widget); | |
1644 if (!node) | |
1645 return; | |
1646 | |
1647 g_signal_emit(wm, signals[SIG_CONFIRM_MOVE], 0, widget, &x, &y, &ret); | |
1648 if (!ret) | |
1649 return; /* resize is not permitted */ | |
1650 | |
1651 gnt_widget_set_position(widget, x, y); | |
1652 move_panel(node->panel, y, x); | |
1653 | |
1654 g_signal_emit(wm, signals[SIG_MOVED], 0, node); | |
15995
bc2dd3358d46
Don't remember the position of transient windows
Richard Nelson <wabz@pidgin.im>
parents:
15978
diff
changeset
|
1655 if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE) && GNT_IS_BOX(widget) && |
bc2dd3358d46
Don't remember the position of transient windows
Richard Nelson <wabz@pidgin.im>
parents:
15978
diff
changeset
|
1656 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { |
15818 | 1657 const char *title = GNT_BOX(widget)->title; |
1658 if (title) { | |
1659 GntPosition *p = g_new0(GntPosition, 1); | |
1660 GntWidget *wid = node->me; | |
1661 p->x = wid->priv.x; | |
1662 p->y = wid->priv.y; | |
1663 g_hash_table_replace(wm->positions, g_strdup(title), p); | |
1664 write_positions_to_file(wm); | |
1665 } | |
1666 } | |
1667 | |
1668 update_screen(wm); | |
1669 } | |
1670 | |
1671 static void | |
1672 gnt_wm_give_focus(GntWM *wm, GntWidget *widget) | |
1673 { | |
1674 GntNode *node = g_hash_table_lookup(wm->nodes, widget); | |
1675 | |
1676 if (!node) | |
1677 return; | |
1678 | |
1679 if (widget != wm->_list.window && !GNT_IS_MENU(widget) && | |
1680 wm->ordered->data != widget) { | |
1681 GntWidget *w = wm->ordered->data; | |
1682 wm->ordered = g_list_bring_to_front(wm->ordered, widget); | |
1683 gnt_widget_set_focus(w, FALSE); | |
1684 } | |
1685 | |
1686 gnt_widget_set_focus(widget, TRUE); | |
1687 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_URGENT); | |
1688 gnt_widget_draw(widget); | |
1689 top_panel(node->panel); | |
1690 | |
1691 if (wm->_list.window) { | |
1692 GntNode *nd = g_hash_table_lookup(wm->nodes, wm->_list.window); | |
1693 top_panel(nd->panel); | |
1694 } | |
1695 update_screen(wm); | |
1696 draw_taskbar(wm, FALSE); | |
1697 } | |
1698 | |
1699 void gnt_wm_update_window(GntWM *wm, GntWidget *widget) | |
1700 { | |
1701 GntNode *node; | |
1702 | |
1703 while (widget->parent) | |
1704 widget = widget->parent; | |
1705 if (!GNT_IS_MENU(widget)) | |
1706 gnt_box_sync_children(GNT_BOX(widget)); | |
1707 | |
1708 node = g_hash_table_lookup(wm->nodes, widget); | |
1709 if (node == NULL) { | |
1710 gnt_wm_new_window(wm, widget); | |
1711 } else | |
1712 g_signal_emit(wm, signals[SIG_UPDATE_WIN], 0, node); | |
1713 | |
1714 copy_win(widget, node); | |
1715 update_screen(wm); | |
1716 draw_taskbar(wm, FALSE); | |
1717 } | |
1718 | |
1719 gboolean gnt_wm_process_click(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget) | |
1720 { | |
1721 gboolean ret = TRUE; | |
1722 idle_update = TRUE; | |
1723 g_signal_emit(wm, signals[SIG_MOUSE_CLICK], 0, event, x, y, widget, &ret); | |
1724 return ret; | |
1725 } | |
1726 | |
1727 void gnt_wm_raise_window(GntWM *wm, GntWidget *widget) | |
1728 { | |
1729 g_signal_emit(wm, signals[SIG_GIVE_FOCUS], 0, widget); | |
1730 } | |
1731 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1732 void gnt_wm_set_event_stack(GntWM *wm, gboolean set) |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1733 { |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1734 wm->event_stack = set; |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1735 } |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1736 |