Mercurial > mplayer.hg
annotate gui/dialog/dialog.c @ 35636:840e473ba4c0
Restore GUI's X error handler after gtk_init().
GDK sets its own handler.
author | ib |
---|---|
date | Thu, 10 Jan 2013 15:40:43 +0000 |
parents | 365dc9336f0d |
children | 78d9cfd68b34 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
23077 | 18 |
19 #include <stdlib.h> | |
20 #include <stdio.h> | |
35361
3e8dcfa3ceef
Prevent unintended sign extension from int to long on 64-bit machines.
ib
parents:
34781
diff
changeset
|
21 #include <stdint.h> |
23077 | 22 |
23 #include <sys/types.h> | |
24 #include <sys/stat.h> | |
25 #include <sys/wait.h> | |
26 #include <unistd.h> | |
27 #include <string.h> | |
28 #include <signal.h> | |
29 | |
30 #include <gdk/gdkprivate.h> | |
31 #include <gdk/gdkkeysyms.h> | |
32 #include <gdk/gdkx.h> | |
33 #include <gdk/gdk.h> | |
34 #include <gtk/gtk.h> | |
35 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
36 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
38 #include "mp_msg.h" |
33542 | 39 #include "libavutil/intreadwrite.h" |
33465 | 40 #include "libvo/x11_common.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 |
35529 | 42 #include "dialog.h" |
35525 | 43 #include "gui/app/app.h" |
44 #include "gui/app/gui.h" | |
33466 | 45 #include "gui/interface.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
46 #include "gui/wm/ws.h" |
23077 | 47 |
35529 | 48 #include "gui/ui/actions.h" |
49 #include "fileselect.h" | |
23077 | 50 |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
51 static GtkWidget *PopUpMenu; |
23077 | 52 |
33538 | 53 GtkWidget *WarningPixmap; |
54 GtkWidget *ErrorPixmap; | |
23077 | 55 |
35624 | 56 int gtkPopupMenu; |
57 int gtkPopupMenuParam; | |
35623
46b3d0bb76e0
Make variables static that are only used inside the file.
ib
parents:
35529
diff
changeset
|
58 static int gtkInitialized; |
23077 | 59 |
35529 | 60 #include "skinbrowser.h" |
61 #include "playlist.h" | |
62 #include "msgbox.h" | |
63 #include "about.h" | |
64 #include "preferences.h" | |
65 #include "menu.h" | |
66 #include "url.h" | |
67 #include "equalizer.h" | |
23077 | 68 |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
69 static const char gui_icon_name[] = "mplayer"; |
23077 | 70 |
33542 | 71 #define THRESHOLD 128 // transparency values equal to or above this will become |
72 // opaque, all values below this will become transparent | |
73 | |
34684 | 74 /* init & close gtk */ |
23077 | 75 |
33529 | 76 guiIcon_t guiIcon; |
23077 | 77 |
34780 | 78 static int gtkLoadIcon(GtkIconTheme *theme, gint size, GdkPixmap **gdkIcon, GdkBitmap **gdkIconMask) |
34480 | 79 { |
80 GdkPixbuf *pixbuf; | |
81 guchar *data; | |
82 int csize, i; | |
83 | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
84 pixbuf = gtk_icon_theme_load_icon(theme, gui_icon_name, size, 0, NULL); |
34480 | 85 |
86 if (pixbuf) | |
87 gdk_pixbuf_render_pixmap_and_mask_for_colormap(pixbuf, gdk_colormap_get_system(), gdkIcon, gdkIconMask, THRESHOLD); | |
88 | |
89 if (pixbuf && | |
90 gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB && | |
91 gdk_pixbuf_get_n_channels(pixbuf) == 4 && | |
92 gdk_pixbuf_get_bits_per_sample(pixbuf) == 8) { | |
93 csize = guiIcon.collection_size; | |
94 guiIcon.collection_size += 2 + gdk_pixbuf_get_width(pixbuf) * gdk_pixbuf_get_height(pixbuf); | |
95 | |
96 guiIcon.collection = realloc(guiIcon.collection, guiIcon.collection_size * sizeof(*guiIcon.collection)); | |
97 | |
98 if (guiIcon.collection) { | |
99 guiIcon.collection[csize++] = gdk_pixbuf_get_width(pixbuf); | |
100 guiIcon.collection[csize++] = gdk_pixbuf_get_height(pixbuf); | |
101 | |
102 data = gdk_pixbuf_get_pixels(pixbuf); | |
103 | |
104 for (i = csize; i < guiIcon.collection_size; data += 4, i++) | |
35361
3e8dcfa3ceef
Prevent unintended sign extension from int to long on 64-bit machines.
ib
parents:
34781
diff
changeset
|
105 guiIcon.collection[i] = (uint32_t)(data[3] << 24) | AV_RB24(data); // RGBA -> ARGB |
34480 | 106 } |
107 | |
108 g_object_unref(pixbuf); | |
109 } else | |
34596
04feb00f91be
Prefer static const char arrays for string constants to #defines.
ib
parents:
34481
diff
changeset
|
110 mp_msg(MSGT_GPLAYER, MSGL_WARN, MSGTR_ICONERROR, gui_icon_name, size); |
34480 | 111 |
34684 | 112 /* start up GTK which realizes the pixmaps */ |
34480 | 113 gtk_main_iteration_do(FALSE); |
34780 | 114 |
115 return (pixbuf != NULL); | |
34480 | 116 } |
117 | |
35629 | 118 void gtkInit(char *display_name) |
23077 | 119 { |
34480 | 120 int argc = 0; |
33538 | 121 char *arg[3], **argv = arg; |
34480 | 122 GtkIconTheme *theme; |
33538 | 123 GdkPixmap *gdkIcon; |
124 GdkBitmap *gdkIconMask; | |
33465 | 125 |
33538 | 126 mp_msg(MSGT_GPLAYER, MSGL_V, "GTK init.\n"); |
33528 | 127 |
33538 | 128 arg[argc++] = GMPlayer; |
33465 | 129 |
35629 | 130 if (display_name) { // MPlayer option '-display' was given |
33538 | 131 arg[argc++] = "--display"; // Pass corresponding command line arguments to GTK, |
35629 | 132 arg[argc++] = display_name; // to open the requested display for the GUI, too. |
33538 | 133 } |
33465 | 134 |
27343 | 135 #ifdef CONFIG_GTK2 |
33538 | 136 gtk_disable_setlocale(); |
23077 | 137 #endif |
33528 | 138 |
33538 | 139 gtk_init(&argc, &argv); |
35636 | 140 wsSetErrorHandler(); // GDK has just set its own handler |
33538 | 141 |
34480 | 142 theme = gtk_icon_theme_get_default(); |
33542 | 143 |
34780 | 144 if (gtkLoadIcon(theme, 16, &gdkIcon, &gdkIconMask)) { |
34781 | 145 guiIcon.small = GDK_PIXMAP_XID(gdkIcon); |
146 guiIcon.small_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 147 } |
33542 | 148 |
34780 | 149 if (gtkLoadIcon(theme, 32, &gdkIcon, &gdkIconMask)) { |
34781 | 150 guiIcon.normal = GDK_PIXMAP_XID(gdkIcon); |
151 guiIcon.normal_mask = GDK_PIXMAP_XID(gdkIconMask); | |
34780 | 152 } |
23077 | 153 |
34480 | 154 gtkLoadIcon(theme, 48, &gdkIcon, &gdkIconMask); |
155 | |
35493 | 156 gtkInitialized = True; |
33538 | 157 } |
23077 | 158 |
33538 | 159 void gtkAddIcon(GtkWidget *window) |
160 { | |
161 wsSetIcon(gdk_display, GDK_WINDOW_XWINDOW(window->window), &guiIcon); | |
162 } | |
23077 | 163 |
33538 | 164 void gtkClearList(GtkWidget *list) |
165 { | |
166 gtk_clist_clear(GTK_CLIST(list)); | |
23077 | 167 } |
168 | |
33538 | 169 int gtkFindCList(GtkWidget *list, char *item) |
23077 | 170 { |
33538 | 171 gint j; |
172 gchar *tmpstr; | |
173 | |
174 for (j = 0; j < GTK_CLIST(list)->rows; j++) { | |
175 gtk_clist_get_text(GTK_CLIST(list), j, 0, &tmpstr); | |
176 | |
177 if (!strcmp(tmpstr, item)) | |
178 return j; | |
179 } | |
180 | |
181 return -1; | |
23077 | 182 } |
183 | |
33538 | 184 void gtkSetDefaultToCList(GtkWidget *list, char *item) |
23077 | 185 { |
33538 | 186 gint i; |
187 | |
188 if ((i = gtkFindCList(list, item)) > -1) | |
189 gtk_clist_select_row(GTK_CLIST(list), i, 0); | |
23077 | 190 } |
191 | |
33538 | 192 void gtkEventHandling(void) |
23077 | 193 { |
33538 | 194 int i; |
195 | |
196 for (i = 0; i < 25; i++) | |
197 gtk_main_iteration_do(0); | |
23077 | 198 } |
199 | |
34684 | 200 /* funcs */ |
23077 | 201 |
33538 | 202 void gtkMessageBox(int type, const gchar *str) |
23077 | 203 { |
33538 | 204 if (!gtkInitialized) |
205 return; | |
206 | |
207 ShowMessageBox(str); | |
208 gtk_label_set_text(GTK_LABEL(gtkMessageBoxText), str); | |
209 | |
210 /* enable linewrapping by alex */ | |
23077 | 211 // GTK_LABEL(gtkMessageBoxText)->max_width = 80; |
33538 | 212 if (strlen(str) > 80) |
213 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), TRUE); | |
214 else | |
215 gtk_label_set_line_wrap(GTK_LABEL(gtkMessageBoxText), FALSE); | |
216 | |
217 switch (type) { | |
23077 | 218 case GTK_MB_FATAL: |
33538 | 219 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_FatalError); |
220 gtk_widget_hide(WarningPixmap); | |
221 gtk_widget_show(ErrorPixmap); | |
222 break; | |
223 | |
23077 | 224 case GTK_MB_ERROR: |
33538 | 225 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Error); |
226 gtk_widget_hide(WarningPixmap); | |
227 gtk_widget_show(ErrorPixmap); | |
228 break; | |
229 | |
23077 | 230 case GTK_MB_WARNING: |
33538 | 231 gtk_window_set_title(GTK_WINDOW(MessageBox), MSGTR_MSGBOX_LABEL_Warning); |
232 gtk_widget_show(WarningPixmap); | |
233 gtk_widget_hide(ErrorPixmap); | |
234 break; | |
235 } | |
236 | |
237 gtk_widget_show(MessageBox); | |
238 gtkSetLayer(MessageBox); | |
239 | |
240 if (type == GTK_MB_FATAL) | |
241 while (MessageBox) | |
242 gtk_main_iteration_do(0); | |
23077 | 243 } |
244 | |
33538 | 245 void gtkSetLayer(GtkWidget *wdg) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27343
diff
changeset
|
246 { |
34697 | 247 wsSetLayer(gdk_display, GDK_WINDOW_XWINDOW(wdg->window), guiApp.videoWindow.isFullScreen); |
33538 | 248 gtkActive(wdg); |
249 } | |
250 | |
251 void gtkActive(GtkWidget *wdg) | |
252 { | |
33990
3a93b9227b01
Cosmetic: Rename wsMoveTopWindow() wsRaiseWindowTop().
ib
parents:
33572
diff
changeset
|
253 wsRaiseWindowTop(gdk_display, GDK_WINDOW_XWINDOW(wdg->window)); |
23077 | 254 } |
255 | |
33538 | 256 void gtkShow(int type, char *param) |
23077 | 257 { |
33538 | 258 switch (type) { |
259 case evEqualizer: | |
260 ShowEqualizer(); | |
261 gtkSetLayer(Equalizer); | |
262 break; | |
263 | |
264 case evSkinBrowser: | |
265 ShowSkinBrowser(); | |
266 | |
23077 | 267 // gtkClearList( SkinList ); |
33538 | 268 if (gtkFillSkinList(sbMPlayerPrefixDir) && |
269 gtkFillSkinList(sbMPlayerDirInHome)) { | |
270 gtkSetDefaultToCList(SkinList, param); | |
271 gtk_clist_sort(GTK_CLIST(SkinList)); | |
272 gtk_widget_show(SkinBrowser); | |
273 gtkSetLayer(SkinBrowser); | |
274 } else { | |
275 gtk_widget_destroy(SkinBrowser); | |
276 gtkMessageBox(GTK_MB_ERROR, "Skin dirs not found ... Please install skins."); | |
277 } | |
278 | |
23077 | 279 break; |
33538 | 280 |
281 case evPreferences: | |
23077 | 282 ShowPreferences(); |
283 break; | |
33538 | 284 |
34321
daebf766dea6
Cosmetic: Synchronize evPlaylist event and message names.
ib
parents:
33990
diff
changeset
|
285 case evPlaylist: |
23077 | 286 ShowPlayList(); |
33538 | 287 gtkSetLayer(PlayList); |
23077 | 288 break; |
33538 | 289 |
290 case evLoad: | |
291 ShowFileSelect(fsVideoSelector, 0); | |
292 gtkSetLayer(fsFileSelect); | |
23077 | 293 break; |
33538 | 294 |
295 case evLoadSubtitle: | |
296 ShowFileSelect(fsSubtitleSelector, 0); | |
297 gtkSetLayer(fsFileSelect); | |
23077 | 298 break; |
33538 | 299 |
300 case evLoadAudioFile: | |
301 ShowFileSelect(fsAudioSelector, 0); | |
302 gtkSetLayer(fsFileSelect); | |
303 break; | |
304 | |
305 case evAbout: | |
306 ShowAboutBox(); | |
307 gtkSetLayer(About); | |
23077 | 308 break; |
33538 | 309 |
34333 | 310 case ivShowPopUpMenu: |
33538 | 311 gtkPopupMenu = evNone; |
312 gtkPopupMenuParam = 0; | |
313 | |
314 if (PopUpMenu) { | |
315 gtk_widget_hide(PopUpMenu); | |
316 gtk_widget_destroy(PopUpMenu); | |
317 } | |
318 | |
319 PopUpMenu = create_PopUpMenu(); | |
320 gtk_menu_popup(GTK_MENU(PopUpMenu), NULL, NULL, NULL, NULL, 0, 0); | |
23077 | 321 break; |
33538 | 322 |
34333 | 323 case ivHidePopUpMenu: |
33538 | 324 |
325 if (PopUpMenu) { | |
326 gtk_widget_hide(PopUpMenu); | |
327 gtk_widget_destroy(PopUpMenu); | |
328 PopUpMenu = NULL; | |
329 } | |
330 | |
23077 | 331 break; |
33538 | 332 |
34329 | 333 case evLoadURL: |
33538 | 334 ShowURLDialogBox(); |
335 gtkSetLayer(URL); | |
336 break; | |
337 } | |
23077 | 338 } |