screen: accept monitor number param (#1263)

This allows starting fullscreen on a specific display/monitor while in standalone mode
This commit is contained in:
Alfredo Monclus 2024-02-19 20:23:02 -03:00 committed by GitHub
parent f0abcfb0b0
commit 0226ba0d95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 9 deletions

View File

@ -239,8 +239,7 @@ KlipperScreen will search for a configuration file in the following order:
2. _~/.config/KlipperScreen/KlipperScreen.conf_
3. _${KlipperScreen_Directory}/KlipperScreen.conf_
If you need a custom location for the configuration file, you can add -c or --configfile to the systemd file and specify
the location of your configuration file.
If you need a custom location for the configuration file, you can add [launch argument](#adding-launch-arguments)
If one of those files are found, it will be merged with the default configuration.
Default Preheat options will be discarded if a custom preheat is found.
@ -252,3 +251,32 @@ _${KlipperScreen_Directory}/ks_includes/default.conf_
*Do not* copy the entire default.conf file, just configure the settings needed.
If no config file is found, then when a setting is changed in the settings panel, a new configuration file should be created automatically.
## Starting on a different monitor/display/screen
Add -m or --monitor as a launch argument, to specify the number of the monitor, that will show Klipperscreen (default: 0).
!!! warning
Selecting the monitor is only allowed when KlipperScreen is set to launch fullscreen in standalone mode (no DE)
## Adding launch arguments
The recommended way to add launch arguments is:
1. Create a launch script:
```bash
touch ~/KlipperScreen/scripts/launch_KlipperScreen.sh
chmod +x launch_KlipperScreen.sh
```
2. Edit the script:
```bash
nano ~/KlipperScreen/scripts/launch_KlipperScreen.sh
```
Add the init and the launch argument, this example will launch KlipperScreen on the second monitor if exists:
```
/usr/bin/xinit $KS_XCLIENT --monitor 1
```
!!! tip
you can use --configfile and --logfile to specify custom locations for those files

View File

@ -123,12 +123,16 @@ class KlipperScreen(Gtk.Window):
self.connect("key-press-event", self._key_press_event)
self.connect("configure_event", self.update_size)
monitor = Gdk.Display.get_default().get_primary_monitor()
if monitor is None:
self.wayland = True
monitor = Gdk.Display.get_default().get_monitor(0)
if monitor is None:
raise RuntimeError("Couldn't get default monitor")
monitor_amount = Gdk.Display.get_n_monitors(Gdk.Display.get_default())
try:
mon_n = int(args.monitor)
if not (-1 < mon_n < monitor_amount):
raise ValueError
except ValueError:
mon_n = 0
logging.info(f"Monitors: {monitor_amount} using number: {mon_n}")
monitor = Gdk.Display.get_default().get_monitor(mon_n)
self.wayland = Gdk.Display.get_default().get_primary_monitor() is None
self.width = self._config.get_main_config().getint("width", None)
self.height = self._config.get_main_config().getint("height", None)
if 'XDG_CURRENT_DESKTOP' in os.environ:
@ -139,12 +143,14 @@ class KlipperScreen(Gtk.Window):
self.height = max(int(monitor.get_geometry().height * .5), 320)
if self.width or self.height:
logging.info("Setting windowed mode")
if mon_n > 0:
logging.error("Monitor selection is only supported for fullscreen")
self.set_resizable(True)
self.windowed = True
else:
self.width = monitor.get_geometry().width
self.height = monitor.get_geometry().height
self.fullscreen()
self.fullscreen_on_monitor(self.get_screen(), mon_n)
self.set_default_size(self.width, self.height)
self.aspect_ratio = self.width / self.height
self.vertical_mode = self.aspect_ratio < 1.0
@ -1111,6 +1117,10 @@ def main():
"-l", "--logfile", default=os.path.join(logdir, "KlipperScreen.log"), metavar='<logfile>',
help="Location of KlipperScreen logfile output"
)
parser.add_argument(
"-m", "--monitor", default="0", metavar='<monitor>',
help="Number of the monitor, that will show Klipperscreen (default: 0)"
)
args = parser.parse_args()
functions.setup_logging(os.path.normpath(os.path.expanduser(args.logfile)))