From 97e8e7362f6a95a4adaa02f8d3a225d374704375 Mon Sep 17 00:00:00 2001 From: Bin Guo Date: Wed, 22 Jan 2014 21:45:07 -0500 Subject: [PATCH] Added --other-screen=screen/monitor option. Support different screens (:0.0 and :0.1) with option --other-screen=1 --- src/classes/options.vala | 45 +++++++++++++++++++++ src/classes/window/fullscreen.vala | 46 ++++++++++++++++------ src/classes/window/presentation.vala | 4 +- src/classes/window/presenter.vala | 4 +- src/pdfpc.vala | 58 +++++++++++++++++++++++++--- 5 files changed, 135 insertions(+), 22 deletions(-) diff --git a/src/classes/options.vala b/src/classes/options.vala index 58753e10..1fcb13c7 100644 --- a/src/classes/options.vala +++ b/src/classes/options.vala @@ -104,5 +104,50 @@ namespace pdfpc { * Position of notes on slides */ public static string? notes_position = null; + + /** + * Other screen to use + */ + public static string? other_screen = null; + } + + /** + * Screen number and monitor number passed in as + * [ScreenNum][/MonitorNum] + */ + public struct ScreenMonitorNum { + /** + * Screen number, default to unspecified (-1) + */ + public int screen_num; + + /** + * Monitor number, default to unspecified (-1) + */ + public int monitor_num; + + /** + * Parse options into this structure + * [ScreenNum][/MonitorNum] + */ + public ScreenMonitorNum(string? screen_monitor_str) { + this.screen_num = -1; + this.monitor_num = -1; + + if (screen_monitor_str == null) { + return; + } + + if (screen_monitor_str.scanf("%d/%d", &this.screen_num, &this.monitor_num) <= 0) { + screen_monitor_str.scanf("/%d", &this.monitor_num); + } + } + + /** + * Parse options into new structure + */ + public static ScreenMonitorNum from_string(string? screen_monitor_str) { + return ScreenMonitorNum(screen_monitor_str); + } } } diff --git a/src/classes/window/fullscreen.vala b/src/classes/window/fullscreen.vala index ba0262e8..df8f3a54 100644 --- a/src/classes/window/fullscreen.vala +++ b/src/classes/window/fullscreen.vala @@ -53,21 +53,43 @@ namespace pdfpc.Window { */ protected bool frozen = false; - public Fullscreen( int screen_num ) { + /** + * Screen and monitor number + */ + protected int screen_num = -1; + protected int monitor_num = -1; + + public Fullscreen( int screen_num, int monitor_num ) { + var display = Gdk.Display.get_default(); Gdk.Screen screen; - if ( screen_num >= 0 ) { - // Start in the given monitor - screen = Screen.get_default(); - screen.get_monitor_geometry( screen_num, out this.screen_geometry ); - } else { - // Start in the monitor the cursor is in - var display = Gdk.Display.get_default(); - int pointerx, pointery; - display.get_pointer(out screen, out pointerx, out pointery, null); - int current_screen = screen.get_monitor_at_point(pointerx, pointery); - screen.get_monitor_geometry( current_screen, out this.screen_geometry ); + // Start in the given screen + if (screen_num >= 0) { + screen = display.get_screen(screen_num); + if ( monitor_num >= 0 ) { + // Start in the given monitor + screen.get_monitor_geometry( monitor_num, out this.screen_geometry ); + } else { + // Start in the primary monitor + monitor_num = screen.get_primary_monitor(); + screen.get_monitor_geometry( monitor_num, out this.screen_geometry ); + } + } else { // Start in default screen + if ( monitor_num >= 0 ) { + // Start in the given monitor + screen = Screen.get_default(); + screen.get_monitor_geometry( monitor_num, out this.screen_geometry ); + } else { + // Start in the monitor the cursor is in + int pointerx, pointery; + display.get_pointer(out screen, out pointerx, out pointery, null); + monitor_num = screen.get_monitor_at_point(pointerx, pointery); + screen.get_monitor_geometry( monitor_num, out this.screen_geometry ); + } } + this.set_screen(screen); + this.screen_num = screen_num; + this.monitor_num = monitor_num; if ( !Options.windowed ) { // Move to the correct monitor diff --git a/src/classes/window/presentation.vala b/src/classes/window/presentation.vala index 7637f16b..0ff71a52 100644 --- a/src/classes/window/presentation.vala +++ b/src/classes/window/presentation.vala @@ -44,8 +44,8 @@ namespace pdfpc.Window { /** * Base constructor instantiating a new presentation window */ - public Presentation( Metadata.Pdf metadata, int screen_num, PresentationController presentation_controller ) { - base( screen_num ); + public Presentation( Metadata.Pdf metadata, int screen_num, int monitor_num, PresentationController presentation_controller ) { + base( screen_num, monitor_num ); this.role = "presentation"; this.destroy.connect( (source) => { diff --git a/src/classes/window/presenter.vala b/src/classes/window/presenter.vala index e07afc7b..b7e20213 100644 --- a/src/classes/window/presenter.vala +++ b/src/classes/window/presenter.vala @@ -137,8 +137,8 @@ namespace pdfpc.Window { /** * Base constructor instantiating a new presenter window */ - public Presenter( Metadata.Pdf metadata, int screen_num, PresentationController presentation_controller ) { - base( screen_num ); + public Presenter( Metadata.Pdf metadata, int screen_num, int monitor_num, PresentationController presentation_controller ) { + base( screen_num, monitor_num ); this.role = "presenter"; this.destroy.connect( (source) => { diff --git a/src/pdfpc.vala b/src/pdfpc.vala index cbdf5a8b..1bb057e2 100644 --- a/src/pdfpc.vala +++ b/src/pdfpc.vala @@ -75,6 +75,7 @@ namespace pdfpc { { "list-actions", 'L', 0, 0, ref Options.list_actions, "List actions supported in the config file(s)", null}, { "windowed", 'w', 0, 0, ref Options.windowed, "Run in windowed mode (devel tool)", null}, { "notes", 'n', 0, OptionArg.STRING, ref Options.notes_position, "Position of notes on the pdf page (either left, right, top or bottom)", "P"}, + { "other-screen", 'O', 0, OptionArg.STRING, ref Options.other_screen, "Other screen[/monitor] to use", "P"}, { null } }; @@ -108,8 +109,8 @@ namespace pdfpc { * Create and return a PresenterWindow using the specified monitor * while displaying the given file */ - private Window.Presenter create_presenter_window( Metadata.Pdf metadata, int monitor ) { - var presenter_window = new Window.Presenter( metadata, monitor, this.controller ); + private Window.Presenter create_presenter_window( Metadata.Pdf metadata, int monitor, int screen = -1 ) { + var presenter_window = new Window.Presenter( metadata, screen, monitor, this.controller ); //controller.register_controllable( presenter_window ); presenter_window.set_cache_observer( this.cache_status ); @@ -120,8 +121,8 @@ namespace pdfpc { * Create and return a PresentationWindow using the specified monitor * while displaying the given file */ - private Window.Presentation create_presentation_window( Metadata.Pdf metadata, int monitor ) { - var presentation_window = new Window.Presentation( metadata, monitor, this.controller ); + private Window.Presentation create_presentation_window( Metadata.Pdf metadata, int monitor, int screen = -1 ) { + var presentation_window = new Window.Presentation( metadata, screen, monitor, this.controller ); //controller.register_controllable( presentation_window ); presentation_window.set_cache_observer( this.cache_status ); @@ -179,8 +180,53 @@ namespace pdfpc { configFileReader.readConfig(etc_path + "/pdfpcrc"); configFileReader.readConfig(Environment.get_home_dir() + "/.pdfpcrc"); - var screen = Gdk.Screen.get_default(); - if ( !Options.windowed && !Options.single_screen && screen.get_n_monitors() > 1 ) { + Gdk.Screen screen = Gdk.Screen.get_default(); + Gdk.Screen? other_screen = null; + + /* other screen can set screen and/or monitor */ + var other_option = pdfpc.ScreenMonitorNum.from_string(Options.other_screen); + if (other_option.screen_num >= 0 || other_option.monitor_num >= 0) { + var display = screen.get_display(); + if (other_option.screen_num >= display.get_n_screens()) { + other_option.screen_num = -1; + } + if (other_option.screen_num < 0) { + other_option.screen_num = screen.get_number(); + } + + other_screen = display.get_screen(other_option.screen_num); + if (other_screen != null) { + if (other_option.monitor_num >= other_screen.get_n_monitors()) { + other_option.monitor_num = -1; + } + if (other_option.monitor_num < 0) { + other_option.monitor_num = other_screen.get_primary_monitor(); + } + if (other_option.monitor_num < 0) { + other_screen = null; + } + } + } + + if ( !Options.windowed && !Options.single_screen && other_screen != null ) { + int presenter_screen, presentation_screen; + int presenter_monitor, presentation_monitor; + if ( Options.display_switch != true ) { + presenter_screen = screen.get_number(); + presenter_monitor = screen.get_primary_monitor(); + presentation_screen = other_screen.get_number(); + presentation_monitor = other_option.monitor_num; + } else { + presenter_screen = other_screen.get_number(); + presenter_monitor = other_option.monitor_num; + presentation_screen = screen.get_number(); + presentation_monitor = screen.get_primary_monitor(); + } + this.presenter_window = + this.create_presenter_window( metadata, presenter_monitor, presenter_screen ); + this.presentation_window = + this.create_presentation_window( metadata, presentation_monitor, presentation_screen ); + } else if ( !Options.windowed && !Options.single_screen && screen.get_n_monitors() > 1 ) { int presenter_monitor, presentation_monitor; if ( Options.display_switch != true ) presenter_monitor = screen.get_primary_monitor();