parallax wallpaper

This commit is contained in:
end-4
2024-01-19 21:08:01 +07:00
parent 3a4a5226b8
commit a7d70b7cb0
5 changed files with 44 additions and 34 deletions
@@ -12,7 +12,8 @@ else
exit 0 exit 0
fi fi
ags run-js "wallpaper.set('${imgpath}')" ags run-js "wallpaper.set('')"
sleep 0.1 && ags run-js "wallpaper.set('${imgpath}')" &
fi fi
# Generate colors for ags n stuff # Generate colors for ags n stuff
+1 -1
View File
@@ -10,7 +10,7 @@ function trimTrackTitle(title) {
/【[^】]*】/, // Touhou n weeb stuff /【[^】]*】/, // Touhou n weeb stuff
/\[FREE DOWNLOAD\]/, // F-777 /\[FREE DOWNLOAD\]/, // F-777
]; ];
cleanRegexes.forEach((expr) => cleanedTitle.replace(expr, '')); cleanRegexes.forEach((expr) => title.replace(expr, ''));
return title; return title;
} }
@@ -10,7 +10,7 @@ export default (monitor) => Widget.Window({
layer: 'background', layer: 'background',
exclusivity: 'ignore', exclusivity: 'ignore',
visible: true, visible: true,
// child: Wallpaper(monitor), // child: WallpaperImage(monitor),
child: Widget.Overlay({ child: Widget.Overlay({
child: WallpaperImage(monitor), child: WallpaperImage(monitor),
overlays: [ overlays: [
@@ -21,4 +21,4 @@ export default (monitor) => Widget.Window({
self.set_overlay_pass_through(self.get_children()[1], true); self.set_overlay_pass_through(self.get_children()[1], true);
}, },
}), }),
}); });
@@ -4,47 +4,56 @@ import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../imports.js'; import { SCREEN_HEIGHT, SCREEN_WIDTH } from '../../imports.js';
const { exec, execAsync } = Utils; const { exec, execAsync } = Utils;
const { Box, Button, Label, Stack } = Widget; const { Box, Button, Label, Stack } = Widget;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import Wallpaper from '../../services/wallpaper.js'; 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.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) => { export default (monitor = 0) => {
let pixbuf = undefined;
const wallpaperImage = Widget.DrawingArea({ const wallpaperImage = Widget.DrawingArea({
css: `transition: 1000ms cubic-bezier(0.1, 1, 0, 1);`, attribute: {
setup: (self) => { 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.set_size_request(SCREEN_WIDTH, SCREEN_HEIGHT);
self.on('draw', (widget, cr) => { self
if (!pixbuf) return; .hook(Hyprland.active.workspace, (self) =>
Gdk.cairo_set_source_pixbuf(cr, pixbuf, 0, 0); self.setCss(`font-size: ${Hyprland.active.workspace.id}px;`)
cr.paint(); )
}); .on('draw', (self, cr) => {
self.hook(Wallpaper, (self) => { if (!self.attribute.pixbuf) return;
const wallPath = Wallpaper.get(monitor); const styleContext = self.get_style_context();
if (!wallPath || wallPath === "") return; const workspace = styleContext.get_property('font-size', Gtk.StateFlags.NORMAL);
pixbuf = GdkPixbuf.Pixbuf.new_from_file(wallPath); Gdk.cairo_set_source_pixbuf(cr, self.attribute.pixbuf,
-(WALLPAPER_OFFSCREEN_X / (MAX_WORKSPACES - 1) * (workspace - 1)),
const scale_x = SCREEN_WIDTH * WALLPAPER_ZOOM_SCALE / pixbuf.get_width(); -WALLPAPER_OFFSCREEN_Y / 2);
const scale_y = SCREEN_HEIGHT * WALLPAPER_ZOOM_SCALE / pixbuf.get_height(); cr.paint();
const scale_factor = Math.max(scale_x, scale_y); })
.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( const scale_x = SCREEN_WIDTH * WALLPAPER_ZOOM_SCALE / self.attribute.pixbuf.get_width();
Math.round(pixbuf.get_width() * scale_factor), const scale_y = SCREEN_HEIGHT * WALLPAPER_ZOOM_SCALE / self.attribute.pixbuf.get_height();
Math.round(pixbuf.get_height() * scale_factor), const scale_factor = Math.max(scale_x, scale_y);
GdkPixbuf.InterpType.BILINEAR
);
// pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(wallPath, SCREEN_WIDTH, SCREEN_HEIGHT); self.attribute.pixbuf = self.attribute.pixbuf.scale_simple(
// console.log(pixbuf.get_width(), pixbuf.get_height()) Math.round(self.attribute.pixbuf.get_width() * scale_factor),
Math.round(self.attribute.pixbuf.get_height() * scale_factor),
// pixbuf = GdkPixbuf.Pixbuf.new_from_file(wallPath); GdkPixbuf.InterpType.BILINEAR
// console.log(pixbuf.get_width(), pixbuf.get_height()) );
self.queue_draw();
self.queue_draw(); }, 'updated');
}, 'updated'); ;
} }
, ,
}); });
@@ -73,7 +73,7 @@ function trimTrackTitle(title) {
/【[^】]*】/, // Touhou n weeb stuff /【[^】]*】/, // Touhou n weeb stuff
/\[FREE DOWNLOAD\]/, // F-777 /\[FREE DOWNLOAD\]/, // F-777
]; ];
cleanRegexes.forEach((expr) => cleanedTitle.replace(expr, '')); cleanRegexes.forEach((expr) => title.replace(expr, ''));
return title; return title;
} }