Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/components/PaletteGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const PaletteGenerator = GObject.registerClass(
'adjustments-applied': {param_types: [GObject.TYPE_JSOBJECT]},
'overrides-changed': {param_types: [GObject.TYPE_JSOBJECT]},
'open-wallpaper-editor': {param_types: [GObject.TYPE_STRING]},
'apply-wallpaper': {},
},
},
class PaletteGenerator extends Gtk.Box {
Expand Down Expand Up @@ -331,6 +332,30 @@ export const PaletteGenerator = GObject.registerClass(
);
buttonBox.append(this._editWallpaperBtn);

// Apply only wallpaper button (right side)
const applyWallpaperButtonBox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 6,
});

const applyWallpaperButtonIcon = new Gtk.Image({
icon_name: 'wallpaper-symbolic',
});

const applyWallpaperLabel = new Gtk.Label({
label: 'Apply',
});

applyWallpaperButtonBox.append(applyWallpaperButtonIcon);
applyWallpaperButtonBox.append(applyWallpaperLabel);

this._applyWallpaperBtn = new Gtk.Button({
child: applyWallpaperButtonBox,
tooltip_text: 'Apply wallpaper to the desktop',
});
this._applyWallpaperBtn.connect('clicked', () => this.emit('apply-wallpaper'));
buttonBox.append(this._applyWallpaperBtn);

// Loading spinner
this._spinner = new Gtk.Spinner({
width_request: 24,
Expand Down
13 changes: 13 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ const AetherWindow = GObject.registerClass(
}
);

this.paletteGenerator.connect('apply-wallpaper', () => {
this._applyWallpaper();
});

this.colorSynthesizer.connect('color-changed', (_, role, color) => {
this._updateAccessibility();
this._updateAppOverrideColors();
Expand Down Expand Up @@ -401,6 +405,15 @@ const AetherWindow = GObject.registerClass(
this.blueprintService.saveBlueprint(palette, settings, lightMode);
}

_applyWallpaper() {
try {
const palette = this.paletteGenerator.getPalette();
this.configWriter.applyWallpaper(palette.wallpaper);
} catch (e) {
console.error(`Error applying wallpaper: ${e.message}`);
}
}

_exportTheme() {
const colors = this.colorSynthesizer.getColors();
const palette = this.paletteGenerator.getPalette();
Expand Down
53 changes: 53 additions & 0 deletions src/utils/ConfigWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,57 @@ export class ConfigWriter {
console.error('Error applying omarchy theme:', e.message);
}
}

applyWallpaper(wallpaperPath) {
try {
console.log('Applying wallpaper from path:', wallpaperPath);
if (wallpaperPath) {
// Create symlink ~/.config/omarchy/current/background -> wallpaperPath
const symlinkPath = GLib.build_filenamev([
this.configDir,
'omarchy',
'current',
'background',
]);
this._createSymlink(wallpaperPath, symlinkPath, 'wallpaper');
GLib.spawn_command_line_async('pkill -x swaybg');
GLib.spawn_command_line_async(`swaybg -i "${wallpaperPath}" -m fill`);
Comment on lines +603 to +604
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately omarchy doesn't have a built-in command to use that instead, So this will be a tech-debt maybe until omarchy implements it.

}
} catch (e) {
console.error('Error applying wallpaper:', e.message);
}
}

_createSymlink(sourcePath, symlinkPath, label = 'symlink') {
try {
// Ensure parent directory exists
const parentDir = GLib.path_get_dirname(symlinkPath);
ensureDirectoryExists(parentDir);

// Remove existing symlink or file if it exists
const symlinkFile = Gio.File.new_for_path(symlinkPath);
if (symlinkFile.query_exists(null)) {
try {
symlinkFile.delete(null);
console.log(`Removed existing ${label} symlink`);
} catch (e) {
console.error(`Error removing existing ${label} symlink:`, e.message);
}
}

// Create symlink
try {
const symlinkGFile = Gio.File.new_for_path(symlinkPath);
symlinkGFile.make_symbolic_link(sourcePath, null);
console.log(`Created ${label} symlink: ${symlinkPath} -> ${sourcePath}`);
} catch (e) {
console.error(`Error creating ${label} symlink:`, e.message);
// Fallback: copy the file if symlink fails
copyFile(sourcePath, symlinkPath);
console.log(`Fallback: Copied file to ${symlinkPath}`);
}
} catch (e) {
console.error(`Error creating ${label} symlink:`, e.message);
}
}
}