2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <gfc@altern.org>
21 /*********************
23 *********************/
28 #include <stdlib.h> /* exit() */
29 #include <unistd.h> /* close(), dup(), dup2(), STDERR_FILENO */
30 #include <gtk/gtkgl.h>
33 options_struct
*options
;
34 gliv_image
*current_image
= NULL
;
39 * This is borrowed from gtk+-2, without the gtk_grab_notify() calls.
40 * They slow down things a lot when the images menus are built with many files.
42 GtkWindowGroup
*_gtk_window_get_group(GtkWindow
* window
)
44 if (window
&& window
->group
)
47 static GtkWindowGroup
*default_group
= NULL
;
50 default_group
= gtk_window_group_new();
56 static GtkWindowGroup
*gtk_main_get_window_group(GtkWidget
* widget
)
58 GtkWidget
*toplevel
= NULL
;
61 toplevel
= gtk_widget_get_toplevel(widget
);
63 if (toplevel
&& GTK_IS_WINDOW(toplevel
))
64 return _gtk_window_get_group(GTK_WINDOW(toplevel
));
66 return _gtk_window_get_group(NULL
);
69 void gtk_grab_add(GtkWidget
* widget
)
71 GtkWindowGroup
*group
;
73 g_return_if_fail(widget
!= NULL
);
75 if (!GTK_WIDGET_HAS_GRAB(widget
) && GTK_WIDGET_IS_SENSITIVE(widget
)) {
76 GTK_WIDGET_SET_FLAGS(widget
, GTK_HAS_GRAB
);
78 group
= gtk_main_get_window_group(widget
);
81 group
->grabs
= g_slist_prepend(group
->grabs
, widget
);
83 /* gtk_grab_notify (group, widget, FALSE); */
87 void gtk_grab_remove(GtkWidget
* widget
)
89 GtkWindowGroup
*group
;
91 g_return_if_fail(widget
!= NULL
);
93 if (GTK_WIDGET_HAS_GRAB(widget
)) {
94 GTK_WIDGET_UNSET_FLAGS(widget
, GTK_HAS_GRAB
);
96 group
= gtk_main_get_window_group(widget
);
97 group
->grabs
= g_slist_remove(group
->grabs
, widget
);
99 g_object_unref(widget
);
101 /* gtk_grab_notify (group, widget, TRUE); */
105 #define check_flag(given, flag, value) if (given) flag = value;
113 static void fill_flags(struct gengetopt_args_info
*ggo
)
117 { ggo
->zoom_pointer_given
, &options
->zoom_pointer
, ggo
->zoom_pointer_flag
},
118 { ggo
->dither_given
, &options
->dither
, ggo
->dither_flag
},
119 { ggo
->force_load_given
, &options
->force
, ggo
->force_load_flag
},
120 { ggo
->mipmap_given
, &options
->mipmap
, ggo
->mipmap_flag
},
121 { ggo
->build_menus_given
, &options
->build_menus
, ggo
->build_menus_flag
},
122 { ggo
->mnemonics_given
, &options
->mnemonics
, ggo
->mnemonics_flag
},
123 { ggo
->menu_given
, &options
->menu_bar
, ggo
->menu_flag
},
124 { ggo
->info_given
, &options
->status_bar
, ggo
->info_flag
},
125 { ggo
->scrollbars_given
, &options
->scrollbars
, ggo
->scrollbars_flag
},
126 { ggo
->alpha_checks_given
, &options
->alpha_checks
, ggo
->alpha_checks_flag
},
127 { ggo
->loop_given
, &options
->loop
, ggo
->loop_flag
},
128 { FALSE
, NULL
, FALSE
}
134 for (arg
= args
; arg
->flag
!= NULL
; arg
++)
135 check_flag(arg
->given
, *(arg
->flag
), arg
->value
);
138 static void init_args(gint argc
, gchar
** argv
)
140 struct gengetopt_args_info ggo
;
141 options_struct
*rc_file
;
143 /* Command line (only the glivrc flag). */
144 if (cmdline_parser(argc
, argv
, &ggo
) != 0)
147 /* Configuration file. */
148 rc_file
= load_rc(ggo
.glivrc_flag
);
149 options
= g_memdup(rc_file
, sizeof(options_struct
));
151 /* Command line (remaining options). */
153 if (ggo
.full_screen_given
|| ggo
.make_fit_given
||
154 ggo
.maximize_given
|| ggo
.scale_down_given
) {
156 options
->fullscreen
= ggo
.full_screen_flag
|| ggo
.make_fit_flag
||
157 ggo
.maximize_flag
|| ggo
.scale_down_flag
;
159 if (ggo
.make_fit_given
)
160 options
->maximize
= options
->scaledown
= ggo
.make_fit_flag
;
163 check_flag(ggo
.maximize_given
, options
->maximize
,
166 check_flag(ggo
.scale_down_given
, options
->scaledown
,
167 ggo
.scale_down_flag
);
170 } else if (options
->maximize
|| options
->scaledown
)
171 options
->fullscreen
= TRUE
;
173 if (ggo
.delay_given
&& ggo
.delay_arg
>= 0)
174 options
->delay
= ggo
.delay_arg
;
176 if (ggo
.history_given
&& ggo
.history_arg
>= -1)
177 options
->history_size
= ggo
.history_arg
;
179 if (ggo
.duration_given
&& ggo
.duration_arg
>= 0)
180 options
->duration
= ggo
.duration_arg
;
184 rt
= g_new(rt_struct
, 1);
186 rt
->cursor_hidden
= FALSE
;
188 rt
->alpha_checks_changed
= TRUE
;
189 rt
->scr_width
= gdk_screen_width();
190 rt
->scr_height
= gdk_screen_height();
192 if (ggo
.inputs_num
> 0) {
193 init_list(ggo
.inputs
, ggo
.inputs_num
,
194 ggo
.recursive_flag
, ggo
.shuffle_given
, ggo
.sort_given
);
196 if (ggo
.slide_show_flag
)
197 begin_with_slide_show();
204 * We call cmdline_parser() a first time to quickly exit if --help or --version
205 * was given. We do the real work after the next call in init_args(), after
206 * gtk_init() removed the gtk arguments.
208 * We temporarily close stderr because unknown and gtk arguments are handled
211 static void check_quick_exit(gint argc
, gchar
** argv
)
213 struct gengetopt_args_info ggo
;
216 fd
= dup(STDERR_FILENO
);
217 close(STDERR_FILENO
);
219 cmdline_parser(argc
, argv
, &ggo
);
221 dup2(fd
, STDERR_FILENO
);
225 G_GNUC_NORETURN
void quit(gint code
)
227 imagemagick_finish();
231 gint
main(gint argc
, gchar
** argv
)
237 bindtextdomain(PACKAGE
, LOCALEDIR
);
240 bind_textdomain_codeset(PACKAGE
, "UTF-8");
243 check_quick_exit(argc
, argv
);
245 gtk_init(&argc
, &argv
);
246 gtk_gl_init(&argc
, &argv
);
248 init_args(argc
, argv
);