From 34622f29cf48ff22af7913012381e7c6e8d89e34 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:24:06 +0700 Subject: [PATCH] fix wallpaper for multimonitor (#200); recommend image size --- .config/ags/services/wallpaper.js | 19 ++++++++++++------- .../widgets/desktopbackground/wallpaper.js | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.config/ags/services/wallpaper.js b/.config/ags/services/wallpaper.js index 9d69c4c8..9b501c8e 100644 --- a/.config/ags/services/wallpaper.js +++ b/.config/ags/services/wallpaper.js @@ -1,4 +1,4 @@ -const { Gio, GLib } = imports.gi; +const { Gdk, Gio, GLib } = imports.gi; import Service from 'resource:///com/github/Aylur/ags/service.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; const { exec, execAsync } = Utils; @@ -19,6 +19,7 @@ class WallpaperService extends Service { _wallPath = ''; _wallJson = []; + _monitorCount = 1; _save() { Utils.writeFile(JSON.stringify(this._wallJson), this._wallPath) @@ -32,7 +33,8 @@ class WallpaperService extends Service { } set(path, monitor = -1) { - if(this._wallJson.length == 0) this._wallJson.push(""); + this._monitorCount = Gdk.Display.get_default()?.get_n_monitors() || 1; + if (this._wallJson.length < this._monitorCount) this._wallJson[this._monitorCount - 1] = ""; if (monitor == -1) this._wallJson.fill(path); else @@ -48,18 +50,21 @@ class WallpaperService extends Service { constructor() { super(); + // How many screens? + this._monitorCount = Gdk.Display.get_default()?.get_n_monitors() || 1; + // Read config this._wallPath = `${GLib.get_user_cache_dir()}/ags/user/wallpaper.json`; - if (!fileExists(this._wallPath)) { // No? create file with empty array + try { + const fileContents = Utils.readFile(this._wallPath); + this._wallJson = JSON.parse(fileContents); + } + catch { Utils.exec(`bash -c 'mkdir -p ${GLib.get_user_cache_dir()}/ags/user'`); Utils.exec(`touch ${this._wallPath}`); Utils.writeFile('[]', this._wallPath).then(() => { this._wallJson = JSON.parse(Utils.readFile(this._wallPath)) }).catch(print); } - else { - const fileContents = Utils.readFile(this._wallPath); - this._wallJson = JSON.parse(fileContents); - } } } diff --git a/.config/ags/widgets/desktopbackground/wallpaper.js b/.config/ags/widgets/desktopbackground/wallpaper.js index 87336ac6..56bf693e 100644 --- a/.config/ags/widgets/desktopbackground/wallpaper.js +++ b/.config/ags/widgets/desktopbackground/wallpaper.js @@ -10,7 +10,7 @@ import Wallpaper from '../../services/wallpaper.js'; import { setupCursorHover } from '../../lib/cursorhover.js'; const SWITCHWALL_SCRIPT_PATH = `${App.configDir}/scripts/color_generation/switchwall.sh`; -const WALLPAPER_ZOOM_SCALE = 1.1; // For scrolling when we switch workspace +const WALLPAPER_ZOOM_SCALE = 1.2; // For scrolling when we switch workspace const MAX_WORKSPACES = 10; const WALLPAPER_OFFSCREEN_X = (WALLPAPER_ZOOM_SCALE - 1) * SCREEN_WIDTH; @@ -69,8 +69,9 @@ export default (monitor = 0) => { children: [ Label({ hpack: 'center', + justification: 'center', className: 'txt-large', - label: `No wallpaper loaded`, + label: `No wallpaper loaded.\nAn image ≥ ${SCREEN_WIDTH * WALLPAPER_ZOOM_SCALE} × ${SCREEN_HEIGHT * WALLPAPER_ZOOM_SCALE} is recommended.`, }), Button({ hpack: 'center',