Path: blob/master/platform/linuxbsd/freedesktop_portal_desktop.h
10277 views
/**************************************************************************/1/* freedesktop_portal_desktop.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#ifdef DBUS_ENABLED3334#include "core/os/thread.h"35#include "core/os/thread_safe.h"36#include "servers/display_server.h"3738struct DBusMessage;39struct DBusConnection;40struct DBusMessageIter;4142class FreeDesktopPortalDesktop : public Object {43private:44bool unsupported = false;4546enum ReadVariantType {47VAR_TYPE_UINT32, // u48VAR_TYPE_BOOL, // b49VAR_TYPE_COLOR, // (ddd)50};5152static bool try_parse_variant(DBusMessage *p_reply_message, ReadVariantType p_type, void *r_value);53// Read a setting from org.freekdesktop.portal.Settings54bool read_setting(const char *p_namespace, const char *p_key, ReadVariantType p_type, void *r_value);5556static void append_dbus_string(DBusMessageIter *p_iter, const String &p_string);57static void append_dbus_dict_options(DBusMessageIter *p_iter, const TypedArray<Dictionary> &p_options, HashMap<String, String> &r_ids);58static 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);59static void append_dbus_dict_string(DBusMessageIter *p_iter, const String &p_key, const String &p_value, bool p_as_byte_array = false);60static void append_dbus_dict_bool(DBusMessageIter *p_iter, const String &p_key, bool p_value);61static 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);62static bool color_picker_parse_response(DBusMessageIter *p_iter, bool &r_cancel, Color &r_color);6364struct ColorPickerData {65Callable callback;66String filter;67String path;68};6970struct ColorPickerCallback {71Callable callback;72Variant status;73Variant color;74};75List<ColorPickerCallback> pending_color_cbs;7677Mutex color_picker_mutex;78Vector<ColorPickerData> color_pickers;7980struct FileDialogData {81Vector<String> filter_names;82HashMap<String, String> option_ids;83DisplayServer::WindowID prev_focus = DisplayServer::INVALID_WINDOW_ID;84Callable callback;85String filter;86String path;87bool opt_in_cb = false;88};8990struct FileDialogCallback {91Callable callback;92Variant status;93Variant files;94Variant index;95Variant options;96bool opt_in_cb = false;97};98List<FileDialogCallback> pending_file_cbs;99100Mutex file_dialog_mutex;101Vector<FileDialogData> file_dialogs;102Thread monitor_thread;103SafeFlag monitor_thread_abort;104DBusConnection *monitor_connection = nullptr;105106String theme_path;107Callable system_theme_changed;108void _system_theme_changed_callback();109bool _is_interface_supported(const char *p_iface);110111static void _thread_monitor(void *p_ud);112113public:114FreeDesktopPortalDesktop();115~FreeDesktopPortalDesktop();116117bool is_supported() { return !unsupported; }118bool is_file_chooser_supported();119bool is_settings_supported();120bool is_screenshot_supported();121122// org.freedesktop.portal.FileChooser methods.123Error 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);124void process_callbacks();125126// org.freedesktop.portal.Settings methods.127128// Retrieve the system's preferred color scheme.129// 0: No preference or unknown.130// 1: Prefer dark appearance.131// 2: Prefer light appearance.132uint32_t get_appearance_color_scheme();133Color get_appearance_accent_color();134void set_system_theme_change_callback(const Callable &p_system_theme_changed) {135system_theme_changed = p_system_theme_changed;136}137138// Retrieve high-contrast setting.139// -1: Unknown.140// 0: Disabled.141// 1: Enabled.142uint32_t get_high_contrast();143144// org.freedesktop.portal.Screenshot methods.145bool color_picker(const String &p_xid, const Callable &p_callback);146};147148#endif // DBUS_ENABLED149150151