-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start to implement org.freedesktop.impl.portal.Background.
ref: #2
- Loading branch information
Showing
6 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" | ||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> | ||
<!-- GDBus 2.48.1 --> | ||
<node> | ||
<interface name="org.cinnamon.PortalHandlers"> | ||
<method name="GetAppStates"> \ | ||
<arg type="a{su}" direction="out" name="apps" /> \ | ||
</method> \ | ||
<signal name="RunningAppsChanged"/> \ | ||
</interface> | ||
</node> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[portal] | ||
DBusName=org.freedesktop.impl.portal.desktop.xapp | ||
Interfaces=org.freedesktop.impl.portal.Wallpaper;org.freedesktop.impl.portal.Inhibit;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Lockdown;org.freedesktop.impl.portal.Settings; | ||
Interfaces=org.freedesktop.impl.portal.Wallpaper;org.freedesktop.impl.portal.Inhibit;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Lockdown;org.freedesktop.impl.portal.Settings;org.freedesktop.impl.portal.Background; | ||
UseIn=X-Cinnamon;MATE;XFCE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
#define _GNU_SOURCE 1 | ||
|
||
#include <config.h> | ||
|
||
#include <errno.h> | ||
#include <locale.h> | ||
#include <string.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
|
||
#include <glib/gstdio.h> | ||
#include <gio/gdesktopappinfo.h> | ||
#include <gio/gunixfdlist.h> | ||
|
||
#include "common-dbus.h" | ||
|
||
#include "request.h" | ||
#include "utils.h" | ||
|
||
static OrgCinnamonPortalHandlers *portal_handlers; | ||
|
||
static gboolean | ||
needs_quoting (const char *arg) | ||
{ | ||
while (*arg != 0) | ||
{ | ||
char c = *arg; | ||
if (!g_ascii_isalnum (c) && | ||
!(c == '-' || c == '/' || c == '~' || | ||
c == ':' || c == '.' || c == '_' || | ||
c == '=' || c == '@')) | ||
return TRUE; | ||
arg++; | ||
} | ||
return FALSE; | ||
} | ||
|
||
char * | ||
flatpak_quote_argv (const char *argv[], | ||
gssize len) | ||
{ | ||
GString *res = g_string_new (""); | ||
int i; | ||
|
||
if (len == -1) | ||
len = g_strv_length ((char **) argv); | ||
|
||
for (i = 0; i < len; i++) | ||
{ | ||
if (i != 0) | ||
g_string_append_c (res, ' '); | ||
|
||
if (needs_quoting (argv[i])) | ||
{ | ||
g_autofree char *quoted = g_shell_quote (argv[i]); | ||
g_string_append (res, quoted); | ||
} | ||
else | ||
g_string_append (res, argv[i]); | ||
} | ||
|
||
return g_string_free (res, FALSE); | ||
} | ||
|
||
typedef enum { | ||
AUTOSTART_FLAGS_NONE = 0, | ||
AUTOSTART_FLAGS_ACTIVATABLE = 1 << 0, | ||
} AutostartFlags; | ||
|
||
static gboolean | ||
handle_enable_autostart (XdpImplBackground *object, | ||
GDBusMethodInvocation *invocation, | ||
const char *app_id, | ||
gboolean enable, | ||
const char * const *commandline, | ||
guint flags) | ||
{ | ||
g_autofree gchar *dir = NULL; | ||
g_autofree gchar *path = NULL; | ||
gchar *file = NULL; | ||
gboolean result = FALSE; | ||
|
||
g_debug ("background: handle EnableAutostart"); | ||
|
||
file = g_strconcat (app_id, ".desktop", NULL); | ||
dir = g_build_filename (g_get_user_config_dir (), "autostart", NULL); | ||
path = g_build_filename (dir, file, NULL); | ||
g_free (file); | ||
|
||
|
||
if (enable) | ||
{ | ||
GKeyFile *keyfile = NULL; | ||
GError *error = NULL; | ||
g_autofree gchar *exec = NULL; | ||
|
||
if (g_mkdir_with_parents (dir, 0755) != 0) | ||
{ | ||
g_warning ("Failed to create dirs %s", dir); | ||
xdp_impl_background_complete_enable_autostart (object, invocation, FALSE); | ||
return TRUE; | ||
} | ||
|
||
exec = flatpak_quote_argv ((const char **) commandline, -1); | ||
|
||
keyfile = g_key_file_new (); | ||
|
||
g_key_file_set_string (keyfile, | ||
G_KEY_FILE_DESKTOP_GROUP, | ||
G_KEY_FILE_DESKTOP_KEY_TYPE, | ||
"Application"); | ||
g_key_file_set_string (keyfile, | ||
G_KEY_FILE_DESKTOP_GROUP, | ||
G_KEY_FILE_DESKTOP_KEY_NAME, | ||
app_id); | ||
g_key_file_set_string (keyfile, | ||
G_KEY_FILE_DESKTOP_GROUP, | ||
G_KEY_FILE_DESKTOP_KEY_EXEC, | ||
exec); | ||
if (flags & AUTOSTART_FLAGS_ACTIVATABLE) | ||
{ | ||
g_key_file_set_boolean (keyfile, | ||
G_KEY_FILE_DESKTOP_GROUP, | ||
G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE, | ||
TRUE); | ||
} | ||
|
||
g_key_file_set_string (keyfile, | ||
G_KEY_FILE_DESKTOP_GROUP, | ||
"X-Flatpak", | ||
app_id); | ||
|
||
if (!g_key_file_save_to_file (keyfile, path, &error)) | ||
{ | ||
g_warning ("Failed to save %s: %s", path, error->message); | ||
g_clear_error (&error); | ||
} | ||
else | ||
{ | ||
g_debug ("Wrote autostart file %s", path); | ||
result = TRUE; | ||
} | ||
} | ||
else | ||
{ | ||
g_unlink (path); | ||
g_debug ("Removed %s", path); | ||
} | ||
|
||
xdp_impl_background_complete_enable_autostart (object, invocation, result); | ||
return TRUE; | ||
} | ||
|
||
gboolean | ||
background_init (GDBusConnection *bus, | ||
GError **error) | ||
{ | ||
GDBusInterfaceSkeleton *helper; | ||
|
||
helper = G_DBUS_INTERFACE_SKELETON (xdp_impl_background_skeleton_new ()); | ||
|
||
// g_signal_connect (helper, "handle-get-app-state", G_CALLBACK (handle_get_app_state), NULL); | ||
// g_signal_connect (helper, "handle-notify-background", G_CALLBACK (handle_notify_background), NULL); | ||
g_signal_connect (helper, "handle-enable-autostart", G_CALLBACK (handle_enable_autostart), NULL); | ||
|
||
if (!g_dbus_interface_skeleton_export (helper, | ||
bus, | ||
DESKTOP_PORTAL_OBJECT_PATH, | ||
error)) | ||
return FALSE; | ||
|
||
portal_handlers = org_cinnamon_portal_handlers_proxy_new_sync (bus, | ||
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, | ||
"org.Cinnamon", | ||
"/org/Cinnamon", | ||
NULL, | ||
error); | ||
if (portal_handlers == NULL) | ||
return FALSE; | ||
|
||
g_debug ("providing %s", g_dbus_interface_skeleton_get_info (helper)->name); | ||
|
||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright © 2018 Red Hat, Inc | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Authors: | ||
* Matthias Clasen <[email protected]> | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <gio/gio.h> | ||
|
||
gboolean background_init (GDBusConnection *bus, GError **error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters