Skip to content

Commit

Permalink
Added new path for custom wallpapers inside config folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rsubtil committed Jul 30, 2020
1 parent 6e229c3 commit 95ec8b0
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/OnScreen/BackgroundWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ namespace Komorebi.OnScreen {

if(wallpaperType == "video") {

var videoPath = @"file://$package_datadir/$wallpaperName/$videoFileName";
var videoPath = @"file:///$wallpaperPath/$videoFileName";
videoPlayback.uri = videoPath;
videoPlayback.playing = true;

Expand Down Expand Up @@ -387,7 +387,7 @@ namespace Komorebi.OnScreen {

wallpaperActor.set_content(wallpaperImage);

wallpaperPixbuf = new Gdk.Pixbuf.from_file_at_scale(@"$package_datadir/$wallpaperName/wallpaper.jpg",
wallpaperPixbuf = new Gdk.Pixbuf.from_file_at_scale(@"$wallpaperPath/wallpaper.jpg",
scaleWidth, scaleHeight, false);

wallpaperImage.set_data (wallpaperPixbuf.get_pixels(), Cogl.PixelFormat.RGB_888,
Expand Down
2 changes: 1 addition & 1 deletion src/OnScreen/Thumbnail.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Komorebi.OnScreen {

this.name = name;

thumbnailImage.pixbuf = new Gdk.Pixbuf.from_file_at_scale(path + name + "/wallpaper.jpg", 150, 100, false);
thumbnailImage.pixbuf = new Gdk.Pixbuf.from_file_at_scale(GLib.Path.build_filename(path, name, "wallpaper.jpg"), 150, 100, false);

// Signals
button_release_event.connect(() => {
Expand Down
44 changes: 23 additions & 21 deletions src/OnScreen/WallpapersSelector.vala
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,39 @@ namespace Komorebi.OnScreen {
foreach(var thumbnail in thumbnailsList)
thumbnailsList.remove(thumbnail);

File wallpapersFolder = File.new_for_path(package_datadir);
foreach(var path in Komorebi.Paths.getWallpaperPaths()) {
File wallpapersFolder = File.new_for_path(path);

try {
try {

var enumerator = wallpapersFolder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);
var enumerator = wallpapersFolder.enumerate_children ("standard::*", FileQueryInfoFlags.NOFOLLOW_SYMLINKS);

FileInfo info;
FileInfo info;

while ((info = enumerator.next_file ()) != null)
if (info.get_file_type () == FileType.DIRECTORY) {
while ((info = enumerator.next_file ()) != null)
if (info.get_file_type () == FileType.DIRECTORY) {

var name = info.get_name();
var fullPath = path + name;
var name = info.get_name();
var fullPath = GLib.Path.build_filename(path, name);

// Check if we have a valid wallpaper
if (File.new_for_path(fullPath + "/wallpaper.jpg").query_exists() &&
File.new_for_path(fullPath + "/config").query_exists()) {
// Check if we have a valid wallpaper
if (File.new_build_filename(fullPath, "wallpaper.jpg").query_exists() &&
File.new_build_filename(fullPath, "config").query_exists()) {

var thumbnail = new Thumbnail(path, name);
var thumbnail = new Thumbnail(path, name);

// Signals
thumbnail.clicked.connect(() => wallpaperChanged());
// Signals
thumbnail.clicked.connect(() => wallpaperChanged());

addThumbnail(thumbnail);
thumbnailsList.append(thumbnail);
} else
print(@"[WARNING]: Found an invalid wallpaper with name: $name \n");
}
addThumbnail(thumbnail);
thumbnailsList.append(thumbnail);
} else
print(@"[WARNING]: Found an invalid wallpaper with name: $name \n");
}

} catch {
print(@"Could not read directory '$package_datadir'");
} catch {
print(@"Could not read directory '$path'");
}
}
}

Expand Down
49 changes: 49 additions & 0 deletions src/Paths.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Copyright (C) 2016-2020 Abraham Masri
// Copyright (C) 2020-2020 Komorebi Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

namespace Komorebi.Paths {

string[] wallpaperPaths;

/* Returns the path for hosting configuration files and wallpapers */
public string getConfigDir() {

string basePath = Environment.get_variable ("XDG_CONFIG_HOME");

if(basePath == null) {
basePath = GLib.Path.build_filename(Environment.get_home_dir(), ".config");

if(basePath == null)
basePath = Environment.get_home_dir();
}

return GLib.Path.build_filename(basePath, "komorebi");
}

/* Returns the list of paths to search for wallpapers */
public string[] getWallpaperPaths() {
if(wallpaperPaths == null) {
wallpaperPaths = {
GLib.Path.build_filename(getConfigDir(), "wallpapers"),
Config.package_datadir
};
}

return wallpaperPaths;
}
}
46 changes: 22 additions & 24 deletions src/Utilities.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using GLib;
using Cairo;

using Komorebi.OnScreen;
using Komorebi.Paths;

namespace Komorebi.Utilities {

Expand Down Expand Up @@ -68,7 +69,7 @@ namespace Komorebi.Utilities {

// Wallpaper variables
KeyFile wallpaperKeyFile;

string wallpaperPath;
string wallpaperType;
string videoFileName;
string webPageUrl;
Expand Down Expand Up @@ -158,21 +159,6 @@ namespace Komorebi.Utilities {
return dateTime.format("%m/%d/%Y %l:%M %p");
}

/* Returns the path for hosting configuration files and wallpapers */
public string getConfigDir() {

string basePath = Environment.get_variable ("XDG_CONFIG_HOME");

if(basePath == null) {
basePath = GLib.Path.build_filename(Environment.get_home_dir(), ".config");

if(basePath == null)
basePath = Environment.get_home_dir();
}

return GLib.Path.build_filename(basePath, "komorebi");
}

/* Reads the .prop file */
public void readConfigurationFile () {

Expand Down Expand Up @@ -240,7 +226,7 @@ namespace Komorebi.Utilities {

/* Bootstraps the base configuration path if it doesn't exist, and detects older versions of this app */
public void bootstrapConfigPath() {
File configPath = File.new_for_path(getConfigDir());
File configPath = File.new_build_filename(getConfigDir(), "wallpapers");
if(!configPath.query_exists())
configPath.make_directory_with_parents();

Expand Down Expand Up @@ -299,15 +285,27 @@ namespace Komorebi.Utilities {

// check if the wallpaper exists
// also, make sure the wallpaper name is valid
string package_datadir = Config.package_datadir;
var wallpaperPath = @"$package_datadir/$wallpaperName";
var wallpaperConfigPath = @"$wallpaperPath/config";
string wallpaperConfigPath = "";
bool wallpaperFound = false;

// Populates the wallpaper path list
getWallpaperPaths();

for(int i = 0; i < wallpaperPaths.length; i++) {
wallpaperPath = @"$(wallpaperPaths[i])/$wallpaperName";
wallpaperConfigPath = @"$wallpaperPath/config";

if(wallpaperName == null || !File.new_for_path(wallpaperPath).query_exists() ||
!File.new_for_path(wallpaperConfigPath).query_exists())
continue;

if(wallpaperName == null || !File.new_for_path(wallpaperPath).query_exists() ||
!File.new_for_path(wallpaperConfigPath).query_exists()) {
wallpaperFound = true;
break;
}

if(!wallpaperFound) {
wallpaperName = "foggy_sunny_mountain";
wallpaperPath = @"$package_datadir/$wallpaperName";
wallpaperPath = @"$(Config.package_datadir)/$wallpaperName";
wallpaperConfigPath = @"$wallpaperPath/config";

print(@"[ERROR]: got an invalid wallpaper. Setting to default: $wallpaperName\n");
Expand Down Expand Up @@ -376,7 +374,7 @@ namespace Komorebi.Utilities {
assetHeight = wallpaperKeyFile.get_integer ("Asset", "Height");

// Set GNOME's wallpaper to this
var wallpaperJpgPath = @"$package_datadir/$wallpaperName/wallpaper.jpg";
var wallpaperJpgPath = GLib.Path.build_filename(wallpaperPath, "wallpaper.jpg");
new GLib.Settings("org.gnome.desktop.background").set_string("picture-uri", ("file://" + wallpaperJpgPath));
new GLib.Settings("org.gnome.desktop.background").set_string("picture-options", "stretched");
}
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sources = files(
'OnScreen/BubbleMenuItem.vala',
'OnScreen/AssetActor.vala',
'OnScreen/PreferencesWindow.vala',
'Paths.vala',
'Utilities.vala'
)

Expand Down

0 comments on commit 95ec8b0

Please sign in to comment.