From 648a3193781bad3fe1cf5e581c8b6ccf1bc2ee15 Mon Sep 17 00:00:00 2001 From: xbezdick <255993@mail.muni.cz> Date: Wed, 4 May 2011 22:15:29 +0200 Subject: [PATCH] [dualscreen] fix Issue #6 --- shell/ev-dualscreen.c | 68 ++++++++++++++++++------------------------- shell/ev-window.c | 4 +-- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/shell/ev-dualscreen.c b/shell/ev-dualscreen.c index 507c76b1..a3b1117d 100644 --- a/shell/ev-dualscreen.c +++ b/shell/ev-dualscreen.c @@ -62,57 +62,45 @@ struct _EvDSCWindowPrivate { #define EV_DSCWINDOW_GET_PRIVATE(object) \ (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_DSCWINDOW, EvDSCWindowPrivate)) #define PAGE_CACHE_SIZE 52428800 /* 50MB */ -#define SIDEBAR_DEFAULT_SIZE 25 /* This seems like bug in gtk to me */ -#define MAX_PRESENTATION_TIME 1440 /*60*24 ONE DAY*/ +#define SIDEBAR_DEFAULT_SIZE 30 /* This seems like bug in gtk to me */ +#define MAX_PRESENTATION_TIME 1440 /* 60*24 ONE DAY */ G_DEFINE_TYPE (EvDSCWindow, ev_dscwindow, GTK_TYPE_WINDOW) - -static void -ev_dscwindow_window_placement (EvDSCWindow *ev_dscwindow) +static gint +ev_dscwindow_get_presentation_window_monitor (EvDSCWindow *ev_dscwindow) { GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window); GdkScreen *screen = gtk_window_get_screen (presentation_window); - gint work_monitor = gdk_screen_get_monitor_at_window (screen, - gtk_widget_get_window (GTK_WIDGET (presentation_window))); - gint presentation_monitor = (work_monitor + 1) % 2; - GdkRectangle coords; - gdk_screen_get_monitor_geometry (screen, presentation_monitor, - &coords); - - gtk_window_move (presentation_window, coords.x, coords.y); - ev_dscwindow->priv->moveback_monitor = work_monitor; - gtk_window_maximize (GTK_WINDOW (ev_dscwindow)); + gint work_monitor = gdk_screen_get_monitor_at_window (screen, gtk_widget_get_window (GTK_WIDGET (presentation_window))); + return work_monitor; } static gboolean -ev_dscwindow_switch_monitors (GtkWidget *widget, EvDSCWindow *ev_dscwindow) +ev_dscwindow_windows_placement (EvDSCWindow *ev_dscwindow) { if (!EV_IS_DSCWINDOW (ev_dscwindow)) return FALSE; gint num_monitors = get_num_monitors (GTK_WINDOW (ev_dscwindow)); - if (num_monitors == 2) { - GtkWindow *presentation_window = GTK_WINDOW (ev_dscwindow->priv->presentation_window); - GdkScreen *screen = gtk_window_get_screen (presentation_window); - - gint monitor_1 = gdk_screen_get_monitor_at_window (screen, - gtk_widget_get_window (GTK_WIDGET (presentation_window))); - - gint monitor_2 = (monitor_1 + 1) % 2; - GdkRectangle coords; - gdk_screen_get_monitor_geometry (screen, monitor_2, &coords); - gtk_window_move (presentation_window, coords.x, coords.y); - ev_dscwindow->priv->moveback_monitor = monitor_1; + GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (ev_dscwindow)); + gint presentation_monitor = ev_dscwindow_get_presentation_window_monitor(ev_dscwindow); + gint control_monitor = presentation_monitor; - gdk_screen_get_monitor_geometry (screen, monitor_1, &coords); + gdk_screen_get_monitor_geometry (screen, control_monitor, &coords); gtk_window_unmaximize (GTK_WINDOW (ev_dscwindow)); gtk_window_move (GTK_WINDOW (ev_dscwindow), coords.x, coords.y); gtk_window_maximize (GTK_WINDOW (ev_dscwindow)); - } - return TRUE; + + presentation_monitor = (control_monitor + 1) % 2; + gdk_screen_get_monitor_geometry (screen, presentation_monitor,&coords); + gtk_window_move (GTK_WINDOW (ev_dscwindow->priv->presentation_window), coords.x, coords.y); + + return TRUE; + } else + return FALSE; } static void @@ -239,6 +227,7 @@ ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow, ev_dscwindow->priv->presentation_document = document; ev_dscwindow->priv->presentation_view = EV_VIEW_PRESENTATION(pview); ev_dscwindow->priv->page = ev_view_presentation_get_current_page (pview); + ev_dscwindow->priv->moveback_monitor = ev_dscwindow_get_presentation_window_monitor (ev_dscwindow); ev_document_model_set_document(ev_dscwindow->priv->model, document); ev_document_model_set_page(ev_dscwindow->priv->model, ev_dscwindow->priv->page); @@ -257,8 +246,11 @@ ev_dscwindow_set_presentation (EvDSCWindow *ev_dscwindow, ev_dscwindow); ev_presentation_timer_set_pages (EV_PRESENTATION_TIMER(ev_dscwindow->priv->timer), ev_document_get_n_pages (document)); - - ev_dscwindow_window_placement (ev_dscwindow); + /* Wait for windows to get shown before moving them */ + while(gtk_events_pending()) + gtk_main_iteration(); + /* something like http://mail.gnome.org/archives/gtk-list/2008-June/msg00061.html */ + ev_dscwindow_windows_placement (ev_dscwindow); } static gboolean @@ -328,8 +320,8 @@ ev_dscwindow_init (EvDSCWindow *ev_dscwindow) _("Switch monitors, In case of more than two monitor window placing has to be manual.")); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (b_switch), "object-flip-horizontal"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), b_switch, -1); - g_signal_connect (b_switch, "clicked", - G_CALLBACK (ev_dscwindow_switch_monitors), ev_dscwindow); + g_signal_connect_swapped (b_switch, "clicked", + G_CALLBACK (ev_dscwindow_windows_placement), ev_dscwindow); GtkToolItem *b_notes = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN); gtk_tool_button_set_label (GTK_TOOL_BUTTON(b_notes), _("Load notes...")); @@ -389,10 +381,8 @@ ev_dscwindow_dispose (GObject *obj) GtkWindow *presentation_window = GTK_WINDOW (priv->presentation_window); GdkRectangle coords; - gdk_screen_get_monitor_geometry ( - gtk_window_get_screen (presentation_window), - priv->moveback_monitor, &coords); - + gdk_screen_get_monitor_geometry (gtk_window_get_screen (presentation_window), + priv->moveback_monitor, &coords); gtk_window_move (presentation_window, coords.x, coords.y); } ev_window_stop_presentation (EV_WINDOW(priv->presentation_window), TRUE); diff --git a/shell/ev-window.c b/shell/ev-window.c index 30491844..ef6f0b16 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -4053,13 +4053,13 @@ ev_window_run_presentation (EvWindow *window) if (window->priv->metadata && !ev_window_is_empty (window)) ev_metadata_set_boolean (window->priv->metadata, "presentation", TRUE); - //if ( get_num_monitors(GTK_WINDOW(window)) > 1) { + if ( get_num_monitors(GTK_WINDOW(window)) > 1) { EvDSCWindow *control = ev_dscwindow_get_control(); gtk_window_present (GTK_WINDOW (control)); ev_dscwindow_set_presentation (control, window, window->priv->document, EV_VIEW_PRESENTATION(window->priv->presentation_view)); - //} + } } void -- 2.43.5