Blender  V3.3
GHOST_WaylandCursorSettings.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 #include <string>
9 
10 #ifdef WITH_GHOST_WAYLAND_DBUS
11 # include <dbus/dbus.h>
12 #endif
13 
14 #ifdef WITH_GHOST_WAYLAND_DBUS
15 static DBusMessage *get_setting_sync(DBusConnection *const connection,
16  const char *key,
17  const char *value)
18 {
19  DBusError error;
20  dbus_bool_t success;
21  DBusMessage *message;
22  DBusMessage *reply;
23 
24  dbus_error_init(&error);
25 
26  message = dbus_message_new_method_call("org.freedesktop.portal.Desktop",
27  "/org/freedesktop/portal/desktop",
28  "org.freedesktop.portal.Settings",
29  "Read");
30 
31  success = dbus_message_append_args(
32  message, DBUS_TYPE_STRING, &key, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID);
33 
34  if (!success) {
35  return nullptr;
36  }
37 
38  reply = dbus_connection_send_with_reply_and_block(
39  connection, message, DBUS_TIMEOUT_USE_DEFAULT, &error);
40 
41  dbus_message_unref(message);
42 
43  if (dbus_error_is_set(&error)) {
44  return nullptr;
45  }
46 
47  return reply;
48 }
49 
50 static bool parse_type(DBusMessage *const reply, const int type, void *value)
51 {
52  DBusMessageIter iter[3];
53 
54  dbus_message_iter_init(reply, &iter[0]);
55  if (dbus_message_iter_get_arg_type(&iter[0]) != DBUS_TYPE_VARIANT) {
56  return false;
57  }
58 
59  dbus_message_iter_recurse(&iter[0], &iter[1]);
60  if (dbus_message_iter_get_arg_type(&iter[1]) != DBUS_TYPE_VARIANT) {
61  return false;
62  }
63 
64  dbus_message_iter_recurse(&iter[1], &iter[2]);
65  if (dbus_message_iter_get_arg_type(&iter[2]) != type) {
66  return false;
67  }
68 
69  dbus_message_iter_get_basic(&iter[2], value);
70 
71  return true;
72 }
73 #endif /* WITH_GHOST_WAYLAND_DBUS */
74 
75 static bool get_cursor_settings(std::string &theme, int &size)
76 {
77 #ifdef WITH_GHOST_WAYLAND_DBUS
78  static const char name[] = "org.gnome.desktop.interface";
79  static const char key_theme[] = "cursor-theme";
80  static const char key_size[] = "cursor-size";
81 
82  DBusError error;
83  DBusConnection *connection;
84  DBusMessage *reply;
85  const char *value_theme = nullptr;
86 
87  dbus_error_init(&error);
88 
89  connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
90 
91  if (dbus_error_is_set(&error)) {
92  return false;
93  }
94 
95  reply = get_setting_sync(connection, name, key_theme);
96  if (!reply) {
97  return false;
98  }
99 
100  if (!parse_type(reply, DBUS_TYPE_STRING, &value_theme)) {
101  dbus_message_unref(reply);
102  return false;
103  }
104 
105  theme = std::string(value_theme);
106 
107  dbus_message_unref(reply);
108 
109  reply = get_setting_sync(connection, name, key_size);
110  if (!reply) {
111  return false;
112  }
113 
114  if (!parse_type(reply, DBUS_TYPE_INT32, &size)) {
115  dbus_message_unref(reply);
116  return false;
117  }
118 
119  dbus_message_unref(reply);
120 
121  return true;
122 #else
123  /* NOTE: eventually we could have alternative ways to access the theme,
124  * this uses the "default" theme which is functional (instead of a user-defined theme). */
125  (void)theme;
126  (void)size;
127  return false;
128 #endif /* !WITH_GHOST_WAYLAND_DBUS */
129 }
static bool get_cursor_settings(std::string &theme, int &size)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SyclQueue void void size_t num_bytes void
static void error(const char *str)
Definition: meshlaplacian.c:51