From a7d70b7cb0e554111386187094fcc508edfb39ed Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:08:01 +0700 Subject: [PATCH] parallax wallpaper --- .../scripts/color_generation/switchwall.sh | 3 +- .config/ags/widgets/bar/music.js | 2 +- .config/ags/widgets/desktopbackground/main.js | 4 +- .../widgets/desktopbackground/wallpaper.js | 67 +++++++++++-------- .../ags/widgets/indicators/musiccontrols.js | 2 +- 5 files changed, 44 insertions(+), 34 deletions(-) diff --git a/.config/ags/scripts/color_generation/switchwall.sh b/.config/ags/scripts/color_generation/switchwall.sh index b2b96db7..84f109e4 100755 --- a/.config/ags/scripts/color_generation/switchwall.sh +++ b/.config/ags/scripts/color_generation/switchwall.sh @@ -12,7 +12,8 @@ else exit 0 fi - ags run-js "wallpaper.set('${imgpath}')" + ags run-js "wallpaper.set('')" + sleep 0.1 && ags run-js "wallpaper.set('${imgpath}')" & fi # Generate colors for ags n stuff diff --git a/.config/ags/widgets/bar/music.js b/.config/ags/widgets/bar/music.js index b0924ff8..54257db6 100644 --- a/.config/ags/widgets/bar/music.js +++ b/.config/ags/widgets/bar/music.js @@ -10,7 +10,7 @@ function trimTrackTitle(title) { /【[^】]*】/, // Touhou n weeb stuff /\[FREE DOWNLOAD\]/, // F-777 ]; - cleanRegexes.forEach((expr) => cleanedTitle.replace(expr, '')); + cleanRegexes.forEach((expr) => title.replace(expr, '')); return title; } diff --git a/.config/ags/widgets/desktopbackground/main.js b/.config/ags/widgets/desktopbackground/main.js index 8ad2de94..576a40e7 100644 --- a/.config/ags/widgets/desktopbackground/main.js +++ b/.config/ags/widgets/desktopbackground/main.js @@ -10,7 +10,7 @@ export default (monitor) => Widget.Window({ layer: 'background', exclusivity: 'ignore', visible: true, - // child: Wallpaper(monitor), + // child: WallpaperImage(monitor), child: Widget.Overlay({ child: WallpaperImage(monitor), overlays: [ @@ -21,4 +21,4 @@ export default (monitor) => Widget.Window({ self.set_overlay_pass_through(self.get_children()[1], true); }, }), -}); \ No newline at end of file +}); diff --git a/.config/ags/widgets/desktopbackground/wallpaper.js b/.config/ags/widgets/desktopbackground/wallpaper.js index cba07528..54abdacd 100644 --- a/.config/ags/widgets/desktopbackground/wallpaper.js +++ b/.config/ags/widgets/desktopbackground/wallpaper.js @@ -4,47 +4,56 @@ import * as Utils from 'resource:///com/github/Aylur/ags/utils.js'; import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../imports.js'; const { exec, execAsync } = Utils; const { Box, Button, Label, Stack } = Widget; +import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; 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 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) => { - let pixbuf = undefined; const wallpaperImage = Widget.DrawingArea({ - css: `transition: 1000ms cubic-bezier(0.1, 1, 0, 1);`, - setup: (self) => { + attribute: { + pixbuf: undefined, + }, + css: `transition: 2000ms cubic-bezier(0.05, 0.7, 0.1, 1); font-size: 1px;`, + setup: (self) => { self.set_size_request(SCREEN_WIDTH, SCREEN_HEIGHT); - self.on('draw', (widget, cr) => { - if (!pixbuf) return; - Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0); - cr.paint(); - }); - self.hook(Wallpaper, (self) => { - const wallPath = Wallpaper.get(monitor); - if (!wallPath || wallPath === "") return; - pixbuf = GdkPixbuf.Pixbuf.new_from_file(wallPath); - - const scale_x = SCREEN_WIDTH * WALLPAPER_ZOOM_SCALE / pixbuf.get_width(); - const scale_y = SCREEN_HEIGHT * WALLPAPER_ZOOM_SCALE / pixbuf.get_height(); - const scale_factor = Math.max(scale_x, scale_y); + self + .hook(Hyprland.active.workspace, (self) => + self.setCss(`font-size: ${Hyprland.active.workspace.id}px;`) + ) + .on('draw', (self, cr) => { + if (!self.attribute.pixbuf) return; + const styleContext = self.get_style_context(); + const workspace = styleContext.get_property('font-size', Gtk.StateFlags.NORMAL); + Gdk.cairo_set_source_pixbuf(cr, self.attribute.pixbuf, + -(WALLPAPER_OFFSCREEN_X / (MAX_WORKSPACES - 1) * (workspace - 1)), + -WALLPAPER_OFFSCREEN_Y / 2); + cr.paint(); + }) + .hook(Wallpaper, (self) => { + const wallPath = Wallpaper.get(monitor); + if (!wallPath || wallPath === "") return; + self.attribute.pixbuf = GdkPixbuf.Pixbuf.new_from_file(wallPath); - pixbuf = pixbuf.scale_simple( - Math.round(pixbuf.get_width() * scale_factor), - Math.round(pixbuf.get_height() * scale_factor), - GdkPixbuf.InterpType.BILINEAR - ); + 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_factor = Math.max(scale_x, scale_y); - // pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(wallPath, SCREEN_WIDTH, SCREEN_HEIGHT); - // console.log(pixbuf.get_width(), pixbuf.get_height()) - - // pixbuf = GdkPixbuf.Pixbuf.new_from_file(wallPath); - // console.log(pixbuf.get_width(), pixbuf.get_height()) - - self.queue_draw(); - }, 'updated'); + self.attribute.pixbuf = self.attribute.pixbuf.scale_simple( + Math.round(self.attribute.pixbuf.get_width() * scale_factor), + Math.round(self.attribute.pixbuf.get_height() * scale_factor), + GdkPixbuf.InterpType.BILINEAR + ); + self.queue_draw(); + }, 'updated'); + ; } , }); diff --git a/.config/ags/widgets/indicators/musiccontrols.js b/.config/ags/widgets/indicators/musiccontrols.js index 9f35968e..5d5b001c 100644 --- a/.config/ags/widgets/indicators/musiccontrols.js +++ b/.config/ags/widgets/indicators/musiccontrols.js @@ -73,7 +73,7 @@ function trimTrackTitle(title) { /【[^】]*】/, // Touhou n weeb stuff /\[FREE DOWNLOAD\]/, // F-777 ]; - cleanRegexes.forEach((expr) => cleanedTitle.replace(expr, '')); + cleanRegexes.forEach((expr) => title.replace(expr, '')); return title; }