From 18de9e2fea19f919dce04c1a6dafa7b49903716a Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:20:15 +0700 Subject: [PATCH] fix screen size for multimonitor and scaled screens (#417) (#424) --- .../ags/modules/.miscutils/hyprlanddata.js | 17 ++++++++ .config/ags/modules/click2close/main.js | 6 +-- .../modules/desktopbackground/wallpaper.js | 18 ++++----- .config/ags/modules/dock/dock.js | 40 ------------------- .../ags/modules/overview/overview_hyprland.js | 26 ++++++------ .config/ags/modules/session/sessionscreen.js | 6 +-- .config/ags/variables.js | 4 -- 7 files changed, 44 insertions(+), 73 deletions(-) create mode 100644 .config/ags/modules/.miscutils/hyprlanddata.js diff --git a/.config/ags/modules/.miscutils/hyprlanddata.js b/.config/ags/modules/.miscutils/hyprlanddata.js new file mode 100644 index 000000000..2a4de2cf6 --- /dev/null +++ b/.config/ags/modules/.miscutils/hyprlanddata.js @@ -0,0 +1,17 @@ +const { GLib } = imports.gi; +import Variable from 'resource:///com/github/Aylur/ags/variable.js'; +import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; +const { execAsync, exec } = Utils; + +export let monitors; + +// ughh condition race theoretically but overview won't be open at init so i guess it's okay +async function updateStuff() { + monitors = JSON.parse(exec('hyprctl monitors -j')) + monitors.forEach(monitor => { + monitor.width /= monitor.scale; + monitor.height /= monitor.scale; + }); +} + +updateStuff(); diff --git a/.config/ags/modules/click2close/main.js b/.config/ags/modules/click2close/main.js index 94426da21..82bb1b3c7 100644 --- a/.config/ags/modules/click2close/main.js +++ b/.config/ags/modules/click2close/main.js @@ -1,7 +1,7 @@ const { Gdk } = imports.gi; import Widget from 'resource:///com/github/Aylur/ags/widget.js'; import PopupWindow from '../.widgethacks/popupwindow.js'; -import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../variables.js'; +import { monitors } from '../.miscutils/hyprlanddata.js'; const WINDOWS_NEED_CLICK2CLOSE = [ 'sideleft', 'sideright', 'overview', 'cheatsheet' @@ -43,8 +43,8 @@ export default (monitor = 0) => PopupWindow({ child: Widget.Box({ css: ` ${userOptions.appearance.layerSmoke ? 'background-color: rgba(0,0,0,' + String(userOptions.appearance.layerSmokeStrength) + ');' : ''} - min-height: ${SCREEN_HEIGHT}px; - min-width: ${SCREEN_WIDTH}px; + min-height: ${monitors[monitor].height}px; + min-width: ${monitors[monitor].width}px; ` }), }) diff --git a/.config/ags/modules/desktopbackground/wallpaper.js b/.config/ags/modules/desktopbackground/wallpaper.js index 695f381a6..599a75269 100644 --- a/.config/ags/modules/desktopbackground/wallpaper.js +++ b/.config/ags/modules/desktopbackground/wallpaper.js @@ -1,7 +1,6 @@ const { Gdk, GdkPixbuf, Gio, GLib, Gtk } = imports.gi; import Widget from 'resource:///com/github/Aylur/ags/widget.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; -import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../variables.js'; const { exec, execAsync } = Utils; const { Box, Button, Label, Stack } = Widget; import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; @@ -9,6 +8,7 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import Wallpaper from '../../services/wallpaper.js'; import { setupCursorHover } from '../.widgetutils/cursorhover.js'; import { clamp } from '../.miscutils/mathfuncs.js'; +import { monitors } from '../.miscutils/hyprlanddata.js'; const DISABLE_AGS_WALLPAPER = true; @@ -16,11 +16,9 @@ const SWITCHWALL_SCRIPT_PATH = `${App.configDir}/scripts/color_generation/switch const WALLPAPER_ZOOM_SCALE = 1.25; // For scrolling when we switch workspace const MAX_WORKSPACES = 10; -const WALLPAPER_OFFSCREEN_X = (WALLPAPER_ZOOM_SCALE - 1) * SCREEN_WIDTH; -const WALLPAPER_OFFSCREEN_Y = (WALLPAPER_ZOOM_SCALE - 1) * SCREEN_HEIGHT; - - export default (monitor = 0) => { + const WALLPAPER_OFFSCREEN_X = (WALLPAPER_ZOOM_SCALE - 1) * monitors[monitor].width; + const WALLPAPER_OFFSCREEN_Y = (WALLPAPER_ZOOM_SCALE - 1) * monitors[monitor].height; const wallpaperImage = Widget.DrawingArea({ attribute: { pixbuf: undefined, @@ -33,7 +31,7 @@ export default (monitor = 0) => { }, className: 'bg-wallpaper-transition', setup: (self) => { - self.set_size_request(SCREEN_WIDTH, SCREEN_HEIGHT); + self.set_size_request(monitors[monitor].width, monitors[monitor].height); self // TODO: reduced updates using timeouts to reduce lag // .hook(Hyprland.active.workspace, (self) => { @@ -61,8 +59,8 @@ export default (monitor = 0) => { if (!wallPath || wallPath === "") return; self.attribute.pixbuf = GdkPixbuf.Pixbuf.new_from_file(wallPath); - const scale_x = SCREEN_WIDTH * WALLPAPER_ZOOM_SCALE / self.attribute.pixbuf.get_width(); - const scale_y = SCREEN_HEIGHT * WALLPAPER_ZOOM_SCALE / self.attribute.pixbuf.get_height(); + const scale_x = monitors[monitor].width * WALLPAPER_ZOOM_SCALE / self.attribute.pixbuf.get_width(); + const scale_y = monitors[monitor].height * WALLPAPER_ZOOM_SCALE / self.attribute.pixbuf.get_height(); const scale_factor = Math.max(scale_x, scale_y); self.attribute.pixbuf = self.attribute.pixbuf.scale_simple( @@ -86,7 +84,7 @@ export default (monitor = 0) => { hpack: 'center', justification: 'center', className: 'txt-large', - label: `No wallpaper loaded.\nAn image ≥ ${SCREEN_WIDTH * WALLPAPER_ZOOM_SCALE} × ${SCREEN_HEIGHT * WALLPAPER_ZOOM_SCALE} is recommended.`, + label: `No wallpaper loaded.\nAn image ≥ ${monitors[monitor].width * WALLPAPER_ZOOM_SCALE} × ${monitors[monitor].height * WALLPAPER_ZOOM_SCALE} is recommended.`, }), Button({ hpack: 'center', @@ -107,7 +105,7 @@ export default (monitor = 0) => { }, setup: (self) => self .hook(Wallpaper, (self) => { - if(DISABLE_AGS_WALLPAPER) { + if (DISABLE_AGS_WALLPAPER) { self.shown = 'disabled'; return; } diff --git a/.config/ags/modules/dock/dock.js b/.config/ags/modules/dock/dock.js index d6d9db211..789ddae27 100755 --- a/.config/ags/modules/dock/dock.js +++ b/.config/ags/modules/dock/dock.js @@ -1,5 +1,4 @@ const { Gtk, GLib } = imports.gi; -import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../variables.js'; import App from 'resource:///com/github/Aylur/ags/app.js'; import Widget from 'resource:///com/github/Aylur/ags/widget.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; @@ -263,45 +262,6 @@ export default (monitor = 0) => { const dockRevealer = Revealer({ attribute: { 'updateShow': self => { // I only use mouse to resize. I don't care about keyboard resize if that's a thing - // const dockSize = [ - // dockContent.get_allocated_width(), - // dockContent.get_allocated_height() - // ] - // const dockAt = [ - // SCREEN_WIDTH / 2 - dockSize[0] / 2, - // SCREEN_HEIGHT - dockSize[1], - // ]; - // const dockLeft = dockAt[0]; - // const dockRight = dockAt[0] + dockSize[0]; - // const dockTop = dockAt[1]; - // const dockBottom = dockAt[1] + dockSize[1]; - // - // const currentWorkspace = Hyprland.active.workspace.id; - // var toReveal = true; - // const hyprlandClients = JSON.parse(exec('hyprctl clients -j')); - // for (const index in hyprlandClients) { - // const client = hyprlandClients[index]; - // const clientLeft = client.at[0]; - // const clientRight = client.at[0] + client.size[0]; - // const clientTop = client.at[1]; - // const clientBottom = client.at[1] + client.size[1]; - // - // if (client.workspace.id == currentWorkspace) { - // if ( - // // clientLeft < dockRight && - // // clientRight > dockLeft && - // // clientTop < dockBottom && - // // clientBottom > dockTop - // ) { - // self.revealChild = false; - // return; - // } - // } - // } - // // if (currentWorkspace === client.workspace.id) { - // self.revealChild = true; - // // } - if (userOptions.dock.monitorExclusivity) self.revealChild = Hyprland.active.monitor.id === monitor; else diff --git a/.config/ags/modules/overview/overview_hyprland.js b/.config/ags/modules/overview/overview_hyprland.js index 1419ee172..e1e55cc54 100644 --- a/.config/ags/modules/overview/overview_hyprland.js +++ b/.config/ags/modules/overview/overview_hyprland.js @@ -4,7 +4,6 @@ // const { Gdk, Gtk } = imports.gi; const { Gravity } = imports.gi.Gdk; -import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../variables.js'; import App from 'resource:///com/github/Aylur/ags/app.js'; import Variable from 'resource:///com/github/Aylur/ags/variable.js'; import Widget from 'resource:///com/github/Aylur/ags/widget.js'; @@ -15,13 +14,14 @@ const { execAsync, exec } = Utils; import { setupCursorHoverGrab } from '../.widgetutils/cursorhover.js'; import { dumpToWorkspace, swapWorkspace } from "./actions.js"; import { substitute } from "../.miscutils/icons.js"; +import { monitors } from '../.miscutils/hyprlanddata.js'; const NUM_OF_WORKSPACES_SHOWN = userOptions.overview.numOfCols * userOptions.overview.numOfRows; const TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)]; const overviewTick = Variable(false); -export default () => { +export default (overviewMonitor = 0) => { const clientMap = new Map(); let workspaceGroup = 0; const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widget.MenuItem({ @@ -49,20 +49,20 @@ export default () => { } }) - const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, class: c, title, xwayland }, screenCoords) => { + const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, class: c, monitor, title, xwayland }, screenCoords) => { const revealInfoCondition = (Math.min(w, h) * userOptions.overview.scale > 70); if (w <= 0 || h <= 0 || (c === '' && title === '')) return null; // Non-primary monitors if (screenCoords.x != 0) x -= screenCoords.x; if (screenCoords.y != 0) y -= screenCoords.y; // Other offscreen adjustments - if (x + w <= 0) x += (Math.floor(x / SCREEN_WIDTH) * SCREEN_WIDTH); + if (x + w <= 0) x += (Math.floor(x / monitors[monitor].width) * monitors[monitor].width); else if (x < 0) { w = x + w; x = 0; } - if (y + h <= 0) x += (Math.floor(y / SCREEN_HEIGHT) * SCREEN_HEIGHT); + if (y + h <= 0) x += (Math.floor(y / monitors[monitor].height) * monitors[monitor].height); else if (y < 0) { h = y + h; y = 0; } // Truncate if offscreen - if (x + w > SCREEN_WIDTH) w = SCREEN_WIDTH - x; - if (y + h > SCREEN_HEIGHT) h = SCREEN_HEIGHT - y; + if (x + w > monitors[monitor]) w = monitors[monitor] - x; + if (y + h > monitors[monitor].height) h = monitors[monitor].height - y; const appIcon = Widget.Icon({ icon: substitute(c), @@ -141,8 +141,8 @@ export default () => { truncate: 'end', className: `margin-top-5 ${xwayland ? 'txt txt-italic' : 'txt'}`, css: ` - font-size: ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * userOptions.overview.scale / 14.6}px; - margin: 0px ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * userOptions.overview.scale / 10}px; + font-size: ${Math.min(monitors[monitor].width, monitors[monitor].height) * userOptions.overview.scale / 14.6}px; + margin: 0px ${Math.min(monitors[monitor].width, monitors[monitor].height) * userOptions.overview.scale / 10}px; `, // If the title is too short, include the class label: (title.length <= 1 ? `${c}: ${title}` : title), @@ -213,8 +213,8 @@ export default () => { className: 'overview-tasks-workspace-number', label: `${index}`, css: ` - margin: ${Math.min(SCREEN_WIDTH, SCREEN_HEIGHT) * userOptions.overview.scale * userOptions.overview.wsNumMarginScale}px; - font-size: ${SCREEN_HEIGHT * userOptions.overview.scale * userOptions.overview.wsNumScale}px; + margin: ${Math.min(monitors[overviewMonitor].width, monitors[overviewMonitor].height) * userOptions.overview.scale * userOptions.overview.wsNumMarginScale}px; + font-size: ${monitors[overviewMonitor].height * userOptions.overview.scale * userOptions.overview.wsNumScale}px; `, setup: (self) => self.hook(Hyprland.active.workspace, (self) => { // Update when going to new ws group @@ -227,8 +227,8 @@ export default () => { className: 'overview-tasks-workspace', vpack: 'center', css: ` - min-width: ${SCREEN_WIDTH * userOptions.overview.scale}px; - min-height: ${SCREEN_HEIGHT * userOptions.overview.scale}px; + min-width: ${monitors[overviewMonitor].width * userOptions.overview.scale}px; + min-height: ${monitors[overviewMonitor].height * userOptions.overview.scale}px; `, children: [Widget.EventBox({ hexpand: true, diff --git a/.config/ags/modules/session/sessionscreen.js b/.config/ags/modules/session/sessionscreen.js index e0306ff87..aed8c3cc2 100644 --- a/.config/ags/modules/session/sessionscreen.js +++ b/.config/ags/modules/session/sessionscreen.js @@ -1,10 +1,10 @@ // This is for the cool memory indicator on the sidebar // For the right pill of the bar, see system.js const { Gdk, Gtk } = imports.gi; -import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../variables.js'; import App from 'resource:///com/github/Aylur/ags/app.js'; import Widget from 'resource:///com/github/Aylur/ags/widget.js'; import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; +import { monitors } from '../.miscutils/hyprlanddata.js'; const { exec, execAsync } = Utils; @@ -98,8 +98,8 @@ export default ({ id = '' }) => { return Widget.Box({ className: 'session-bg', css: ` - min-width: ${SCREEN_WIDTH}px; - min-height: ${SCREEN_HEIGHT}px; + min-width: ${monitors[(id == '' ? 0 : id)].width}px; + min-height: ${monitors[(id == '' ? 0 : id)].height}px; `, // idk why but height = screen height doesn't fill vertical: true, children: [ diff --git a/.config/ags/variables.js b/.config/ags/variables.js index efc0beb55..c77027f2d 100644 --- a/.config/ags/variables.js +++ b/.config/ags/variables.js @@ -15,10 +15,6 @@ globalThis['openMusicControls'] = showMusicControls; globalThis['openColorScheme'] = showColorScheme; globalThis['mpris'] = Mpris; -// Screen size -export const SCREEN_WIDTH = Number(exec(`bash -c "xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1 | head -1" | awk '{print $1}'`)); -export const SCREEN_HEIGHT = Number(exec(`bash -c "xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2 | head -1" | awk '{print $1}'`)); - // Mode switching export const currentShellMode = Variable('normal', {}) // normal, focus globalThis['currentMode'] = currentShellMode;