Skip to content

Commit 237dd41

Browse files
authored
Add apply wallpaper button (#18)
* Add apply wallpaper button * change label
1 parent 96f73b5 commit 237dd41

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

src/components/PaletteGenerator.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const PaletteGenerator = GObject.registerClass(
2424
'adjustments-applied': {param_types: [GObject.TYPE_JSOBJECT]},
2525
'overrides-changed': {param_types: [GObject.TYPE_JSOBJECT]},
2626
'open-wallpaper-editor': {param_types: [GObject.TYPE_STRING]},
27+
'apply-wallpaper': {},
2728
},
2829
},
2930
class PaletteGenerator extends Gtk.Box {
@@ -332,6 +333,30 @@ export const PaletteGenerator = GObject.registerClass(
332333
);
333334
buttonBox.append(this._editWallpaperBtn);
334335

336+
// Apply only wallpaper button (right side)
337+
const applyWallpaperButtonBox = new Gtk.Box({
338+
orientation: Gtk.Orientation.HORIZONTAL,
339+
spacing: 6,
340+
});
341+
342+
const applyWallpaperButtonIcon = new Gtk.Image({
343+
icon_name: 'wallpaper-symbolic',
344+
});
345+
346+
const applyWallpaperLabel = new Gtk.Label({
347+
label: 'Apply',
348+
});
349+
350+
applyWallpaperButtonBox.append(applyWallpaperButtonIcon);
351+
applyWallpaperButtonBox.append(applyWallpaperLabel);
352+
353+
this._applyWallpaperBtn = new Gtk.Button({
354+
child: applyWallpaperButtonBox,
355+
tooltip_text: 'Apply wallpaper to the desktop',
356+
});
357+
this._applyWallpaperBtn.connect('clicked', () => this.emit('apply-wallpaper'));
358+
buttonBox.append(this._applyWallpaperBtn);
359+
335360
// Loading spinner
336361
this._spinner = new Gtk.Spinner({
337362
width_request: 24,

src/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ const AetherWindow = GObject.registerClass(
325325
}
326326
);
327327

328+
this.paletteGenerator.connect('apply-wallpaper', () => {
329+
this._applyWallpaper();
330+
});
331+
328332
this.colorSynthesizer.connect('color-changed', (_, role, color) => {
329333
this._updateAccessibility();
330334
this._updateAppOverrideColors();
@@ -450,6 +454,15 @@ const AetherWindow = GObject.registerClass(
450454
this.blueprintService.saveBlueprint(palette, settings, lightMode);
451455
}
452456

457+
_applyWallpaper() {
458+
try {
459+
const palette = this.paletteGenerator.getPalette();
460+
this.configWriter.applyWallpaper(palette.wallpaper);
461+
} catch (e) {
462+
console.error(`Error applying wallpaper: ${e.message}`);
463+
}
464+
}
465+
453466
_exportTheme() {
454467
const colors = this.colorSynthesizer.getColors();
455468
const palette = this.paletteGenerator.getPalette();

src/utils/ConfigWriter.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,57 @@ export class ConfigWriter {
587587
console.error('Error applying omarchy theme:', e.message);
588588
}
589589
}
590+
591+
applyWallpaper(wallpaperPath) {
592+
try {
593+
console.log('Applying wallpaper from path:', wallpaperPath);
594+
if (wallpaperPath) {
595+
// Create symlink ~/.config/omarchy/current/background -> wallpaperPath
596+
const symlinkPath = GLib.build_filenamev([
597+
this.configDir,
598+
'omarchy',
599+
'current',
600+
'background',
601+
]);
602+
this._createSymlink(wallpaperPath, symlinkPath, 'wallpaper');
603+
GLib.spawn_command_line_async('pkill -x swaybg');
604+
GLib.spawn_command_line_async(`swaybg -i "${wallpaperPath}" -m fill`);
605+
}
606+
} catch (e) {
607+
console.error('Error applying wallpaper:', e.message);
608+
}
609+
}
610+
611+
_createSymlink(sourcePath, symlinkPath, label = 'symlink') {
612+
try {
613+
// Ensure parent directory exists
614+
const parentDir = GLib.path_get_dirname(symlinkPath);
615+
ensureDirectoryExists(parentDir);
616+
617+
// Remove existing symlink or file if it exists
618+
const symlinkFile = Gio.File.new_for_path(symlinkPath);
619+
if (symlinkFile.query_exists(null)) {
620+
try {
621+
symlinkFile.delete(null);
622+
console.log(`Removed existing ${label} symlink`);
623+
} catch (e) {
624+
console.error(`Error removing existing ${label} symlink:`, e.message);
625+
}
626+
}
627+
628+
// Create symlink
629+
try {
630+
const symlinkGFile = Gio.File.new_for_path(symlinkPath);
631+
symlinkGFile.make_symbolic_link(sourcePath, null);
632+
console.log(`Created ${label} symlink: ${symlinkPath} -> ${sourcePath}`);
633+
} catch (e) {
634+
console.error(`Error creating ${label} symlink:`, e.message);
635+
// Fallback: copy the file if symlink fails
636+
copyFile(sourcePath, symlinkPath);
637+
console.log(`Fallback: Copied file to ${symlinkPath}`);
638+
}
639+
} catch (e) {
640+
console.error(`Error creating ${label} symlink:`, e.message);
641+
}
642+
}
590643
}

0 commit comments

Comments
 (0)