| 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 |
#pragma once |
| 32 |
|
| 33 |
#ifdef DBUS_ENABLED |
| 34 |
|
| 35 |
#include "core/os/thread.h" |
| 36 |
#include "core/os/thread_safe.h" |
| 37 |
#include "servers/display/display_server.h" |
| 38 |
|
| 39 |
struct DBusMessage; |
| 40 |
struct DBusConnection; |
| 41 |
struct DBusMessageIter; |
| 42 |
|
| 43 |
class FreeDesktopPortalDesktop : public Object { |
| 44 |
GDSOFTCLASS(FreeDesktopPortalDesktop, Object); |
| 45 |
|
| 46 |
private: |
| 47 |
bool unsupported = false; |
| 48 |
|
| 49 |
enum ReadVariantType { |
| 50 |
VAR_TYPE_UINT32, |
| 51 |
VAR_TYPE_BOOL, |
| 52 |
VAR_TYPE_COLOR, |
| 53 |
}; |
| 54 |
|
| 55 |
static bool try_parse_variant(DBusMessage *p_reply_message, ReadVariantType p_type, void *r_value); |
| 56 |
|
| 57 |
bool read_setting(const char *p_namespace, const char *p_key, ReadVariantType p_type, void *r_value); |
| 58 |
|
| 59 |
static void append_dbus_string(DBusMessageIter *p_iter, const String &p_string); |
| 60 |
static void append_dbus_dict_options(DBusMessageIter *p_iter, const TypedArray<Dictionary> &p_options, HashMap<String, String> &r_ids); |
| 61 |
static void append_dbus_dict_filters(DBusMessageIter *p_iter, const Vector<String> &p_filter_names, const Vector<String> &p_filter_exts, const Vector<String> &p_filter_mimes); |
| 62 |
static void append_dbus_dict_string(DBusMessageIter *p_iter, const String &p_key, const String &p_value, bool p_as_byte_array = false); |
| 63 |
static void append_dbus_dict_bool(DBusMessageIter *p_iter, const String &p_key, bool p_value); |
| 64 |
|
| 65 |
static bool file_chooser_parse_response(DBusMessageIter *p_iter, const Vector<String> &p_names, const HashMap<String, String> &p_ids, bool &r_cancel, Vector<String> &r_urls, int &r_index, Dictionary &r_options); |
| 66 |
static bool color_picker_parse_response(DBusMessageIter *p_iter, bool &r_cancel, Color &r_color); |
| 67 |
|
| 68 |
static Error make_request_token(String &r_token); |
| 69 |
bool send_request(DBusMessage *p_message, const String &r_token, String &r_response_path, String &r_response_filter); |
| 70 |
|
| 71 |
struct ColorPickerData { |
| 72 |
Callable callback; |
| 73 |
String filter; |
| 74 |
String path; |
| 75 |
}; |
| 76 |
|
| 77 |
struct ColorPickerCallback { |
| 78 |
Callable callback; |
| 79 |
Variant status; |
| 80 |
Variant color; |
| 81 |
}; |
| 82 |
List<ColorPickerCallback> pending_color_cbs; |
| 83 |
|
| 84 |
Mutex color_picker_mutex; |
| 85 |
Vector<ColorPickerData> color_pickers; |
| 86 |
|
| 87 |
struct FileDialogData { |
| 88 |
Vector<String> filter_names; |
| 89 |
HashMap<String, String> option_ids; |
| 90 |
DisplayServer::WindowID prev_focus = DisplayServer::INVALID_WINDOW_ID; |
| 91 |
Callable callback; |
| 92 |
String filter; |
| 93 |
String path; |
| 94 |
bool opt_in_cb = false; |
| 95 |
}; |
| 96 |
|
| 97 |
struct FileDialogCallback { |
| 98 |
Callable callback; |
| 99 |
Variant status; |
| 100 |
Variant files; |
| 101 |
Variant index; |
| 102 |
Variant options; |
| 103 |
bool opt_in_cb = false; |
| 104 |
}; |
| 105 |
List<FileDialogCallback> pending_file_cbs; |
| 106 |
|
| 107 |
Mutex file_dialog_mutex; |
| 108 |
Vector<FileDialogData> file_dialogs; |
| 109 |
Thread monitor_thread; |
| 110 |
SafeFlag monitor_thread_abort; |
| 111 |
DBusConnection *monitor_connection = nullptr; |
| 112 |
|
| 113 |
String theme_path; |
| 114 |
Callable system_theme_changed; |
| 115 |
void _system_theme_changed_callback(); |
| 116 |
bool _is_interface_supported(const char *p_iface, uint32_t p_minimum_version); |
| 117 |
|
| 118 |
Mutex inhibit_mutex; |
| 119 |
String inhibit_path; |
| 120 |
String inhibit_filter; |
| 121 |
|
| 122 |
static void _thread_monitor(void *p_ud); |
| 123 |
|
| 124 |
public: |
| 125 |
FreeDesktopPortalDesktop(); |
| 126 |
~FreeDesktopPortalDesktop(); |
| 127 |
|
| 128 |
bool is_supported() { return !unsupported; } |
| 129 |
bool is_file_chooser_supported(); |
| 130 |
bool is_settings_supported(); |
| 131 |
bool is_screenshot_supported(); |
| 132 |
bool is_inhibit_supported(); |
| 133 |
|
| 134 |
|
| 135 |
Error file_dialog_show(DisplayServer::WindowID p_window_id, const String &p_xid, const String &p_title, const String &p_current_directory, const String &p_root, const String &p_filename, DisplayServer::FileDialogMode p_mode, const Vector<String> &p_filters, const TypedArray<Dictionary> &p_options, const Callable &p_callback, bool p_options_in_cb); |
| 136 |
void process_callbacks(); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
uint32_t get_appearance_color_scheme(); |
| 145 |
Color get_appearance_accent_color(); |
| 146 |
void set_system_theme_change_callback(const Callable &p_system_theme_changed) { |
| 147 |
system_theme_changed = p_system_theme_changed; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
uint32_t get_high_contrast(); |
| 155 |
|
| 156 |
|
| 157 |
bool color_picker(const String &p_xid, const Callable &p_callback); |
| 158 |
|
| 159 |
|
| 160 |
bool inhibit(const String &p_xid); |
| 161 |
void uninhibit(); |
| 162 |
}; |
| 163 |
|
| 164 |
#endif |