Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GHOST_WaylandCursorSettings.h « intern « ghost « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7d2d82ff841a69583f40b3bba620741d9574156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * 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 2
 * 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, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/** \file
 * \ingroup GHOST
 */

#pragma once
#include <dbus/dbus.h>
#include <string>

static DBusMessage *get_setting_sync(DBusConnection *const connection,
                                     const char *key,
                                     const char *value)
{
  DBusError error;
  dbus_bool_t success;
  DBusMessage *message;
  DBusMessage *reply;

  dbus_error_init(&error);

  message = dbus_message_new_method_call("org.freedesktop.portal.Desktop",
                                         "/org/freedesktop/portal/desktop",
                                         "org.freedesktop.portal.Settings",
                                         "Read");

  success = dbus_message_append_args(
      message, DBUS_TYPE_STRING, &key, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID);

  if (!success) {
    return NULL;
  }

  reply = dbus_connection_send_with_reply_and_block(
      connection, message, DBUS_TIMEOUT_USE_DEFAULT, &error);

  dbus_message_unref(message);

  if (dbus_error_is_set(&error)) {
    return NULL;
  }

  return reply;
}

static bool parse_type(DBusMessage *const reply, const int type, void *value)
{
  DBusMessageIter iter[3];

  dbus_message_iter_init(reply, &iter[0]);
  if (dbus_message_iter_get_arg_type(&iter[0]) != DBUS_TYPE_VARIANT) {
    return false;
  }

  dbus_message_iter_recurse(&iter[0], &iter[1]);
  if (dbus_message_iter_get_arg_type(&iter[1]) != DBUS_TYPE_VARIANT) {
    return false;
  }

  dbus_message_iter_recurse(&iter[1], &iter[2]);
  if (dbus_message_iter_get_arg_type(&iter[2]) != type) {
    return false;
  }

  dbus_message_iter_get_basic(&iter[2], value);

  return true;
}

static bool get_cursor_settings(std::string &theme, int &size)
{
  static const char name[] = "org.gnome.desktop.interface";
  static const char key_theme[] = "cursor-theme";
  static const char key_size[] = "cursor-size";

  DBusError error;
  DBusConnection *connection;
  DBusMessage *reply;
  const char *value_theme = NULL;

  dbus_error_init(&error);

  connection = dbus_bus_get(DBUS_BUS_SESSION, &error);

  if (dbus_error_is_set(&error)) {
    return false;
  }

  reply = get_setting_sync(connection, name, key_theme);
  if (!reply) {
    return false;
  }

  if (!parse_type(reply, DBUS_TYPE_STRING, &value_theme)) {
    dbus_message_unref(reply);
    return false;
  }

  theme = std::string(value_theme);

  dbus_message_unref(reply);

  reply = get_setting_sync(connection, name, key_size);
  if (!reply) {
    return false;
  }

  if (!parse_type(reply, DBUS_TYPE_INT32, &size)) {
    dbus_message_unref(reply);
    return false;
  }

  dbus_message_unref(reply);

  return true;
}