Skip to content

Commit 8f9beb2

Browse files
committed
Wallpaper (macOS): add support
1 parent 77b93a9 commit 8f9beb2

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR BSD" OFF)
5757
cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR BSD" OFF)
5858
cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR BSD" OFF)
5959
cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR BSD" OFF)
60-
cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR BSD" OFF)
60+
cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR BSD OR APPLE" OFF)
6161
cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX" OFF)
6262
cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR BSD OR APPLE OR WIN32" OFF)
6363
cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR BSD OR APPLE" OFF)
@@ -494,7 +494,7 @@ elseif(APPLE)
494494
src/detection/terminalshell/terminalshell_linux.c
495495
src/detection/uptime/uptime_bsd.c
496496
src/detection/users/users_linux.c
497-
src/detection/wallpaper/wallpaper_nosupport.c
497+
src/detection/wallpaper/wallpaper_apple.c
498498
src/detection/wifi/wifi_apple.m
499499
src/detection/wmtheme/wmtheme_apple.m
500500
src/util/apple/cf_helpers.c

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ The following libraries are used if present at runtime:
6464
* [`MoltenVK`](https://github.com/KhronosGroup/MoltenVK): Vulkan driver for macOS. [`molten-vk`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/molten-vk.rb)
6565
* [`libmagickcore` (ImageMagick)](https://www.imagemagick.org/): Images in terminal using sixel graphics protocol. [`imagemagick`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/imagemagick.rb)
6666
* [`libchafa`](https://github.com/hpjansson/chafa): Image output as ascii art. [`chafa`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/chafa.rb)
67+
* [`libsqlite3`](https://www.sqlite.org/index.html): Used for fast wallpaper detection ( fallback to AppleScript )
6768

6869
For the image logo, iTerm with iterm image protocol should work. Apple Terminal is not supported.
6970

src/common/settings.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ typedef struct SQLiteData
297297
FF_LIBRARY_SYMBOL(sqlite3_step)
298298
FF_LIBRARY_SYMBOL(sqlite3_data_count)
299299
FF_LIBRARY_SYMBOL(sqlite3_column_int)
300+
FF_LIBRARY_SYMBOL(sqlite3_column_text)
300301
FF_LIBRARY_SYMBOL(sqlite3_finalize)
301302
FF_LIBRARY_SYMBOL(sqlite3_close)
302303
} SQLiteData;
@@ -310,6 +311,7 @@ static const SQLiteData* getSQLiteData(const FFinstance* instance)
310311
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_step)
311312
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_data_count)
312313
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_column_int)
314+
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_column_text)
313315
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_finalize)
314316
FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_close)
315317

@@ -350,12 +352,52 @@ int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, cons
350352

351353
return result;
352354
}
355+
356+
bool ffSettingsGetSQLite3String(const FFinstance* instance, const char* dbPath, const char* query, FFstrbuf* result)
357+
{
358+
if(!ffPathExists(dbPath, FF_PATHTYPE_FILE))
359+
return false;
360+
361+
const SQLiteData* data = getSQLiteData(instance);
362+
if(data == NULL)
363+
return false;
364+
365+
sqlite3* db;
366+
if(data->ffsqlite3_open_v2(dbPath, &db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK)
367+
return false;
368+
369+
sqlite3_stmt* stmt;
370+
if(data->ffsqlite3_prepare_v2(db, query, (int) strlen(query), &stmt, NULL) != SQLITE_OK)
371+
{
372+
data->ffsqlite3_close(db);
373+
return false;
374+
}
375+
376+
if(data->ffsqlite3_step(stmt) != SQLITE_ROW || data->ffsqlite3_data_count(stmt) < 1)
377+
{
378+
data->ffsqlite3_finalize(stmt);
379+
data->ffsqlite3_close(db);
380+
return false;
381+
}
382+
383+
ffStrbufSetS(result, (const char *) data->ffsqlite3_column_text(stmt, 0));
384+
385+
data->ffsqlite3_finalize(stmt);
386+
data->ffsqlite3_close(db);
387+
388+
return true;
389+
}
353390
#else //FF_HAVE_SQLITE3
354391
int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, const char* query)
355392
{
356393
FF_UNUSED(instance, dbPath, query)
357394
return 0;
358395
}
396+
bool ffSettingsGetSQLite3String(const FFinstance* instance, const char* dbPath, const char* query, FFstrbuf* result)
397+
{
398+
FF_UNUSED(instance, dbPath, query, result)
399+
return false;
400+
}
359401
#endif //FF_HAVE_SQLITE3
360402

361403
#ifdef __ANDROID__

src/common/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ FFvariant ffSettingsGet(const FFinstance* instance, const char* dconfKey, const
3131
FFvariant ffSettingsGetXFConf(const FFinstance* instance, const char* channelName, const char* propertyName, FFvarianttype type);
3232

3333
int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, const char* query);
34+
bool ffSettingsGetSQLite3String(const FFinstance* instance, const char* dbPath, const char* query, FFstrbuf* result);
3435

3536
#ifdef __ANDROID__
3637
void ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "wallpaper.h"
2+
#include "common/settings.h"
3+
#include "util/apple/osascript.h"
4+
5+
const char* ffDetectWallpaper(FF_MAYBE_UNUSED const FFinstance* instance, FFstrbuf* result)
6+
{
7+
// https://stackoverflow.com/questions/301215/getting-desktop-background-on-mac
8+
9+
#ifdef FF_HAVE_SQLITE3
10+
11+
FF_STRBUF_AUTO_DESTROY path;
12+
ffStrbufInitCopy(&path, &instance->state.platform.homeDir);
13+
ffStrbufAppendS(&path, "Library/Application Support/Dock/desktoppicture.db");
14+
if (ffSettingsGetSQLite3String(instance, path.chars,
15+
"SELECT value\n"
16+
"FROM preferences\n"
17+
"JOIN data ON preferences.data_id=data.ROWID\n"
18+
"JOIN pictures ON preferences.picture_id=pictures.ROWID\n"
19+
"JOIN displays ON pictures.display_id=displays.ROWID\n"
20+
"JOIN spaces ON pictures.space_id=spaces.ROWID\n"
21+
"WHERE display_id=1 AND space_id=1 AND key=1", result)
22+
)
23+
return NULL;
24+
25+
#endif
26+
27+
if (!ffOsascript("tell application \"Finder\" to get POSIX path of (get desktop picture as alias)", result))
28+
return "ffOsascript() failed";
29+
30+
return NULL;
31+
}

0 commit comments

Comments
 (0)