Path: blob/master/platform/linuxbsd/freedesktop_portal_desktop.h
11352 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/display_server.h"3738struct DBusMessage;39struct DBusConnection;40struct DBusMessageIter;4142class FreeDesktopPortalDesktop : public Object {43GDSOFTCLASS(FreeDesktopPortalDesktop, Object);4445private:46bool unsupported = false;4748enum ReadVariantType {49VAR_TYPE_UINT32, // u50VAR_TYPE_BOOL, // b51VAR_TYPE_COLOR, // (ddd)52};5354static bool try_parse_variant(DBusMessage *p_reply_message, ReadVariantType p_type, void *r_value);55// Read a setting from org.freekdesktop.portal.Settings56bool read_setting(const char *p_namespace, const char *p_key, ReadVariantType p_type, void *r_value);5758static void append_dbus_string(DBusMessageIter *p_iter, const String &p_string);59static void append_dbus_dict_options(DBusMessageIter *p_iter, const TypedArray<Dictionary> &p_options, HashMap<String, String> &r_ids);60static 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);61static void append_dbus_dict_string(DBusMessageIter *p_iter, const String &p_key, const String &p_value, bool p_as_byte_array = false);62static void append_dbus_dict_bool(DBusMessageIter *p_iter, const String &p_key, bool p_value);63static 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);64static bool color_picker_parse_response(DBusMessageIter *p_iter, bool &r_cancel, Color &r_color);6566struct ColorPickerData {67Callable callback;68String filter;69String path;70};7172struct ColorPickerCallback {73Callable callback;74Variant status;75Variant color;76};77List<ColorPickerCallback> pending_color_cbs;7879Mutex color_picker_mutex;80Vector<ColorPickerData> color_pickers;8182struct FileDialogData {83Vector<String> filter_names;84HashMap<String, String> option_ids;85DisplayServer::WindowID prev_focus = DisplayServer::INVALID_WINDOW_ID;86Callable callback;87String filter;88String path;89bool opt_in_cb = false;90};9192struct FileDialogCallback {93Callable callback;94Variant status;95Variant files;96Variant index;97Variant options;98bool opt_in_cb = false;99};100List<FileDialogCallback> pending_file_cbs;101102Mutex file_dialog_mutex;103Vector<FileDialogData> file_dialogs;104Thread monitor_thread;105SafeFlag monitor_thread_abort;106DBusConnection *monitor_connection = nullptr;107108String theme_path;109Callable system_theme_changed;110void _system_theme_changed_callback();111bool _is_interface_supported(const char *p_iface);112113static void _thread_monitor(void *p_ud);114115public:116FreeDesktopPortalDesktop();117~FreeDesktopPortalDesktop();118119bool is_supported() { return !unsupported; }120bool is_file_chooser_supported();121bool is_settings_supported();122bool is_screenshot_supported();123124// org.freedesktop.portal.FileChooser methods.125Error 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);126void process_callbacks();127128// org.freedesktop.portal.Settings methods.129130// Retrieve the system's preferred color scheme.131// 0: No preference or unknown.132// 1: Prefer dark appearance.133// 2: Prefer light appearance.134uint32_t get_appearance_color_scheme();135Color get_appearance_accent_color();136void set_system_theme_change_callback(const Callable &p_system_theme_changed) {137system_theme_changed = p_system_theme_changed;138}139140// Retrieve high-contrast setting.141// -1: Unknown.142// 0: Disabled.143// 1: Enabled.144uint32_t get_high_contrast();145146// org.freedesktop.portal.Screenshot methods.147bool color_picker(const String &p_xid, const Callable &p_callback);148};149150#endif // DBUS_ENABLED151152153