fix wallpaper for multimonitor (#200); recommend image size

This commit is contained in:
end-4
2024-01-20 14:24:06 +07:00
parent 15c426df9e
commit 34622f29cf
2 changed files with 15 additions and 9 deletions
+12 -7
View File
@@ -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 Service from 'resource:///com/github/Aylur/ags/service.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { exec, execAsync } = Utils; const { exec, execAsync } = Utils;
@@ -19,6 +19,7 @@ class WallpaperService extends Service {
_wallPath = ''; _wallPath = '';
_wallJson = []; _wallJson = [];
_monitorCount = 1;
_save() { _save() {
Utils.writeFile(JSON.stringify(this._wallJson), this._wallPath) Utils.writeFile(JSON.stringify(this._wallJson), this._wallPath)
@@ -32,7 +33,8 @@ class WallpaperService extends Service {
} }
set(path, monitor = -1) { 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) if (monitor == -1)
this._wallJson.fill(path); this._wallJson.fill(path);
else else
@@ -48,18 +50,21 @@ class WallpaperService extends Service {
constructor() { constructor() {
super(); 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`; 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(`bash -c 'mkdir -p ${GLib.get_user_cache_dir()}/ags/user'`);
Utils.exec(`touch ${this._wallPath}`); Utils.exec(`touch ${this._wallPath}`);
Utils.writeFile('[]', this._wallPath).then(() => { Utils.writeFile('[]', this._wallPath).then(() => {
this._wallJson = JSON.parse(Utils.readFile(this._wallPath)) this._wallJson = JSON.parse(Utils.readFile(this._wallPath))
}).catch(print); }).catch(print);
} }
else {
const fileContents = Utils.readFile(this._wallPath);
this._wallJson = JSON.parse(fileContents);
}
} }
} }
@@ -10,7 +10,7 @@ import Wallpaper from '../../services/wallpaper.js';
import { setupCursorHover } from '../../lib/cursorhover.js'; import { setupCursorHover } from '../../lib/cursorhover.js';
const SWITCHWALL_SCRIPT_PATH = `${App.configDir}/scripts/color_generation/switchwall.sh`; 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 MAX_WORKSPACES = 10;
const WALLPAPER_OFFSCREEN_X = (WALLPAPER_ZOOM_SCALE - 1) * SCREEN_WIDTH; const WALLPAPER_OFFSCREEN_X = (WALLPAPER_ZOOM_SCALE - 1) * SCREEN_WIDTH;
@@ -69,8 +69,9 @@ export default (monitor = 0) => {
children: [ children: [
Label({ Label({
hpack: 'center', hpack: 'center',
justification: 'center',
className: 'txt-large', 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({ Button({
hpack: 'center', hpack: 'center',