]> www.fi.muni.cz Git - evince.git/blob - shell/ev-dualscreen.c
[shell] dualscreen yay alpha works
[evince.git] / shell / ev-dualscreen.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  *
5  * Evince is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Evince is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <glib/gi18n.h>
25 #include <gtk/gtk.h>
26
27 #include "ev-dualscreen.h"
28 #include "ev-window.h"
29 #include "ev-view.h"
30 #include "ev-utils.h"
31
32 struct _EvDSCWindowPrivate {
33         GtkWidget *main_box;
34         GtkWidget *menubar;
35         GtkWidget *overview;
36         GtkWidget *notesview;
37         EvDocumentModel *model;
38         EvDocument * notesdocument;
39
40         GtkWidget *overview_scrolled_window;
41         GtkWidget *notesview_scrolled_window;
42
43         EvWindow *presentation_window;
44         EvDocument * presentation_document;
45         gint moveback_monitor;
46 };
47
48 #define EV_DSCWINDOW_GET_PRIVATE(object) \
49         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate))
50 #define PAGE_CACHE_SIZE 52428800 /* 50MB */
51
52 /*static gpointer parent_class = NULL;*/
53
54 G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW)
55
56 /**
57  * ev_dscwindow_switch_monitors: Bring the presentation window and the control window each on the other monitor.
58  *
59  * @widget: Callback widget
60  * @self: EvDSCWindow
61  **/
62 static gboolean
63 ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *self)
64 {
65 /*
66 +       if (!EV_IS_DSCWINDOW (self))
67 +               return FALSE;
68 +
69 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
70 +
71 +       gint num_monitors = get_num_monitors (GTK_WINDOW (self));
72 +
73 +       if (num_monitors == 2) {
74 +               GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
75 +               GdkScreen * screen = gtk_window_get_screen (presentation_window);
76 +
77 +               gint monitor_1 = gdk_screen_get_monitor_at_window (screen,
78 +                       GTK_WIDGET (presentation_window)->window);
79 +
80 +               gint monitor_2 = (monitor_1 + 1) % 2;
81 +
82 +               GdkRectangle coords;
83 +               gdk_screen_get_monitor_geometry (screen, monitor_2, &coords);
84 +               ev_window_stop_presentation (priv->presentation_window);
85 +               gtk_window_move (presentation_window, coords.x, coords.y);
86 +               ev_window_run_presentation (priv->presentation_window);
87 +               priv->moveback_monitor = monitor_1;
88 +
89 +               gdk_screen_get_monitor_geometry (screen, monitor_1, &coords);
90 +               gtk_window_unmaximize (GTK_WINDOW (self));
91 +               gtk_window_move (GTK_WINDOW (self), coords.x, coords.y);
92 +               gtk_window_maximize (GTK_WINDOW (self));
93 +       }*/
94         return TRUE;
95 }
96
97 /**
98  * ev_dscwindow_notes_interaction: User wants to load a different file as notes.
99  **/
100 static gboolean
101 ev_dscwindow_notes_interaction (GtkContainer *container, EvDSCWindow *self)
102 {
103 /*
104 +       EvDSCWindowPrivate *priv = EV_DSCWINDOW_GET_PRIVATE (self);
105 +       GtkWidget *dialog;
106 +
107 +       dialog = gtk_file_chooser_dialog_new (
108 +               _("Open Document"),
109 +               GTK_WINDOW (self),
110 +               GTK_FILE_CHOOSER_ACTION_OPEN,
111 +               GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
112 +               GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
113 +               NULL);
114 +
115 +       ev_document_factory_add_filters (dialog, NULL);
116 +       gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
117 +       gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
118 +
119 +       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
120 +       {
121 +               char * uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
122 +               GError * error = NULL;
123 +               ev_view_set_loading (EV_VIEW (priv->notesview), TRUE);
124 +
125 +               if (priv->notesdocument) {
126 +                       ev_document_load (priv->notesdocument, uri, &error);
127 +               } else {
128 +                       priv->notesdocument = ev_document_factory_get_document (uri,
129 +                               &error);
130 +               }
131 +               g_free (uri);
132 +               if (error == NULL){
133 +                       ev_view_set_document (EV_VIEW (priv->notesview),
134 +                               priv->notesdocument);
135 +                       /* TODO: go to the same page that is open at the moment, or
136 +                        * move the presentation to the beginning. *//*
137 +               }
138 +       }
139 +       gtk_widget_destroy (dialog);
140 */
141         return TRUE;
142 }
143
144 /**
145  * ev_dscwindow_get_control: Get the control instance.
146  *
147  * If there is none, create one.
148  *
149  * Returns: control instance
150  **/
151 EvDSCWindow *
152 ev_dscwindow_get_control (void)
153 {
154         static EvDSCWindow * control = NULL;
155
156         if (!control || !EV_IS_DSCWINDOW (control)) {
157                 control = EV_DSCWINDOW (g_object_new (EV_TYPE_DSCWINDOW, NULL));
158         }
159
160         return control;
161 }
162
163 /*TODO: Fix me!*/
164 static void
165 ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow)
166 {
167         gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow));
168         if (num_monitors == 2) {
169                 GtkWindow * presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window);
170                 GdkScreen * screen = gtk_window_get_screen (presentation_window);
171
172                 gint work_monitor = gdk_screen_get_monitor_at_window (screen,
173                         gtk_widget_get_window (GTK_WIDGET (presentation_window)));
174
175                 gint presentation_monitor = (work_monitor + 1) % 2;
176
177                 GdkRectangle coords;
178                 gdk_screen_get_monitor_geometry (screen, presentation_monitor,
179                         &coords);
180
181                 gtk_window_move (presentation_window, coords.x, coords.y);
182                 ev_window_run_presentation (ev_dscwindow->priv->presentation_window);
183                 ev_dscwindow->priv->moveback_monitor = work_monitor;
184
185                 gtk_window_maximize (GTK_WINDOW (ev_dscwindow));
186         }
187 }
188
189
190 /**
191  * ev_dscwindow_set_presentation: Set presentation document
192  * @presentation_window: Main window we can reuse for presentation
193  **/
194 void
195 ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow,
196         EvWindow *presentation_window, EvDocument *document)
197 {
198         if (!EV_IS_WINDOW (presentation_window))
199                 return;
200
201         ev_dscwindow->priv->presentation_window = presentation_window;
202         ev_dscwindow->priv->presentation_document = document;
203
204         ev_document_model_set_document(ev_dscwindow->priv->model,
205                 document);
206 /*      ev_view_set_document (EV_VIEW (priv->notesview),
207                 priv->presentation_document);*/
208         ev_dscwindow_window_placement (ev_dscwindow);
209         /*ev_dscwindow_handle_resized (NULL, NULL, self);
210         */
211 }
212
213 /**
214  * ev_dscwindow_end: Stop presentation mode.
215  */
216 static gboolean
217 ev_dscwindow_end (GtkWidget *widget, GdkEvent *event)
218 {
219         gtk_widget_destroy (GTK_WIDGET (ev_dscwindow_get_control ()));
220         return TRUE;
221 }
222
223 /**
224 * ev_dscwindow_init: Initialize multihead presentation
225 *
226 * @self: EvDSCWindow.
227 *
228 * ev_dscwindow_set_presentation has to be called afterwards for loading in a document. TBD
229 **/
230 static void
231 ev_dscwindow_init (EvDSCWindow *ev_dscwindow)
232 {
233         ev_dscwindow->priv = EV_DSCWINDOW_GET_PRIVATE (ev_dscwindow);
234         ev_dscwindow->priv->moveback_monitor = -1;
235         ev_dscwindow->priv->notesdocument = NULL;
236
237         gtk_window_set_title (GTK_WINDOW (ev_dscwindow), _("Presentation Control"));
238
239         GtkWidget *h = gtk_hpaned_new ();
240         GtkWidget *v = gtk_vbox_new (FALSE, 0);
241
242         ev_dscwindow->priv->overview_scrolled_window = GTK_WIDGET (g_object_new (
243                         GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
244         gtk_box_pack_start (GTK_BOX (v), ev_dscwindow->priv->overview_scrolled_window, TRUE, TRUE, 0);
245
246         ev_dscwindow->priv->model = ev_document_model_new ();
247         ev_dscwindow->priv->overview = ev_view_new ();
248         ev_view_set_page_cache_size (EV_VIEW (ev_dscwindow->priv->overview), PAGE_CACHE_SIZE);
249         ev_view_set_model (EV_VIEW (ev_dscwindow->priv->overview), ev_dscwindow->priv->model);
250         ev_document_model_set_continuous (ev_dscwindow->priv->model, TRUE);
251         ev_document_model_set_dual_page (ev_dscwindow->priv->model, FALSE);
252         ev_document_model_set_sizing_mode (ev_dscwindow->priv->model, EV_SIZING_BEST_FIT);
253
254
255         gtk_container_add (GTK_CONTAINER (ev_dscwindow->priv->overview_scrolled_window),
256                                    ev_dscwindow->priv->overview);
257
258
259         GtkWidget *e = gtk_expander_new (_("Expensive features"));
260         gtk_expander_set_expanded (GTK_EXPANDER (e), TRUE);
261
262         GtkWidget *t = gtk_toolbar_new ();
263
264         GtkToolItem* b_switch = gtk_tool_button_new (NULL, _("Switch monitors"));
265         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal");
266         gtk_toolbar_insert (GTK_TOOLBAR (t), b_switch, -1);
267         g_signal_connect (b_switch, "clicked",
268                 G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow);
269
270         GtkToolItem* b_notes = gtk_tool_button_new (NULL, _("Load notes ..."));
271         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_notes), "object-flip-horizontal");
272         gtk_toolbar_insert (GTK_TOOLBAR (t), b_notes, -1);
273         g_signal_connect (b_notes, "clicked",
274                 G_CALLBACK (ev_dscwindow_notes_interaction), ev_dscwindow);
275
276         GtkToolItem* b_close = gtk_tool_button_new (NULL, _("End presentation"));
277         gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_close), "view-restore");
278         gtk_toolbar_insert (GTK_TOOLBAR (t), b_close, -1);
279         g_signal_connect (b_close, "clicked",
280                 G_CALLBACK (ev_dscwindow_end), NULL);
281
282         gtk_container_add (GTK_CONTAINER (e), t);
283         gtk_box_pack_end (GTK_BOX (v), e, FALSE, TRUE, 0);
284         gtk_paned_add1 (GTK_PANED (h), v);
285
286 /*
287         priv->notesview_scrolled_window = GTK_WIDGET (g_object_new (
288                 GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, NULL));
289         gtk_paned_add2 (GTK_PANED (h), priv->notesview_scrolled_window);
290
291         priv->notesview = ev_view_new ();
292         g_object_ref (priv->notesview);
293         ev_view_set_screen_dpi (EV_VIEW (priv->notesview),
294                                 get_screen_dpi (GTK_WINDOW (self)));
295 +               gtk_container_add (GTK_CONTAINER (priv->notesview_scrolled_window),
296 +                                  priv->notesview);
297 +
298 +               ev_view_set_continuous (EV_VIEW (priv->notesview), FALSE);
299 +               ev_view_set_dual_page (EV_VIEW (priv->notesview), FALSE);
300 +               ev_view_set_sizing_mode (EV_VIEW (priv->notesview), EV_SIZING_BEST_FIT);
301 +       }
302 +
303 +       gtk_paned_set_position (GTK_PANED (h), 400);
304         gtk_widget_show_all (h);
305 +       gtk_container_add (GTK_CONTAINER (self), h);
306 +
307 +       /* fallback if we have >2 monitors (see window placement) */
308 /*+     gtk_window_set_default_size (GTK_WINDOW (self), 800, 600);
309 +
310 +       g_signal_connect (h, "notify::position",
311 +               G_CALLBACK (ev_dscwindow_handle_resized), self);
312 +
313 +       g_signal_connect (self, "size-allocate",
314 +               G_CALLBACK (ev_dscwindow_handle_resized), self);
315 +
316 +       /* This would just open new windows. */
317 /*+     gtk_drag_dest_unset (GTK_WIDGET (priv->notesview));
318 +       gtk_drag_dest_unset (GTK_WIDGET (priv->overview));
319 +
320 +       gint click = GDK_BUTTON1_MOTION_MASK | GDK_KEY_PRESS_MASK;
321 +       gtk_widget_add_events (GTK_WIDGET (priv->overview), click);
322 +       g_signal_connect (priv->notesview, "button-press-event",
323 +                         G_CALLBACK (ev_dscwindow_notes_clicked), self);
324 */
325 }
326
327
328 static void
329 ev_dscwindow_dispose (GObject *obj)
330 {
331         EvDSCWindow * ev_dscwindow = EV_DSCWINDOW (obj);
332         EvDSCWindowPrivate *priv = ev_dscwindow->priv;
333
334 /*      if (EV_IS_VIEW (priv->overview) {
335                 ev_document_model_set_document (priv->model, NULL);
336
337 +               ev_view_set_document (EV_VIEW (priv->overview),  NULL);
338 +               g_object_unref (priv->overview);
339 +       }
340 +       if (EV_IS_VIEW (priv->notesview)) {
341 +               ev_view_set_document (EV_VIEW (priv->notesview), NULL);
342 +               g_object_unref (priv->notesview);
343 +       }*/
344 /*TODO: save fulscreen state*/
345         ev_window_stop_presentation (priv->presentation_window, 0);
346
347         if (priv->moveback_monitor >= 0) {
348                 GtkWindow * presentation_window = GTK_WINDOW (priv->presentation_window);
349                 GdkRectangle coords;
350
351                 gdk_screen_get_monitor_geometry (
352                         gtk_window_get_screen (presentation_window),
353                         priv->moveback_monitor, &coords);
354
355                 gtk_window_move (presentation_window, coords.x, coords.y);
356         }
357
358         G_OBJECT_CLASS (ev_dscwindow_parent_class)->dispose (obj);
359 }
360
361
362 static void
363 ev_dscwindow_class_init (EvDSCWindowClass *ev_dscwindow_class)
364 {
365         GObjectClass *g_object_class = G_OBJECT_CLASS (ev_dscwindow_class);
366         /*parent_class = g_type_class_peek_parent (ev_dscwindow_class);*/
367         g_type_class_add_private (g_object_class, sizeof (EvDSCWindowPrivate));
368         g_object_class->dispose  = ev_dscwindow_dispose;
369 }
370
371 GtkWidget *
372 ev_dscwindow_new (void)
373 {
374         EvDSCWindow *ev_dscwindow;
375
376         ev_dscwindow = g_object_new (EV_TYPE_DSCWINDOW, "type", GTK_WINDOW_TOPLEVEL, NULL);
377         return GTK_WIDGET (ev_dscwindow);
378 }