Path: blob/master/platform/linuxbsd/freedesktop_portal_desktop.h
21760 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);6364static 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);65static bool color_picker_parse_response(DBusMessageIter *p_iter, bool &r_cancel, Color &r_color);6667static Error make_request_token(String &r_token);68bool send_request(DBusMessage *p_message, const String &r_token, String &r_response_path, String &r_response_filter);6970struct ColorPickerData {71Callable callback;72String filter;73String path;74};7576struct ColorPickerCallback {77Callable callback;78Variant status;79Variant color;80};81List<ColorPickerCallback> pending_color_cbs;8283Mutex color_picker_mutex;84Vector<ColorPickerData> color_pickers;8586struct FileDialogData {87Vector<String> filter_names;88HashMap<String, String> option_ids;89DisplayServer::WindowID prev_focus = DisplayServer::INVALID_WINDOW_ID;90Callable callback;91String filter;92String path;93bool opt_in_cb = false;94};9596struct FileDialogCallback {97Callable callback;98Variant status;99Variant files;100Variant index;101Variant options;102bool opt_in_cb = false;103};104List<FileDialogCallback> pending_file_cbs;105106Mutex file_dialog_mutex;107Vector<FileDialogData> file_dialogs;108Thread monitor_thread;109SafeFlag monitor_thread_abort;110DBusConnection *monitor_connection = nullptr;111112String theme_path;113Callable system_theme_changed;114void _system_theme_changed_callback();115bool _is_interface_supported(const char *p_iface, uint32_t p_minimum_version);116117Mutex inhibit_mutex;118String inhibit_path;119String inhibit_filter;120121static void _thread_monitor(void *p_ud);122123public:124FreeDesktopPortalDesktop();125~FreeDesktopPortalDesktop();126127bool is_supported() { return !unsupported; }128bool is_file_chooser_supported();129bool is_settings_supported();130bool is_screenshot_supported();131bool is_inhibit_supported();132133// org.freedesktop.portal.FileChooser methods.134Error 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);135void process_callbacks();136137// org.freedesktop.portal.Settings methods.138139// Retrieve the system's preferred color scheme.140// 0: No preference or unknown.141// 1: Prefer dark appearance.142// 2: Prefer light appearance.143uint32_t get_appearance_color_scheme();144Color get_appearance_accent_color();145void set_system_theme_change_callback(const Callable &p_system_theme_changed) {146system_theme_changed = p_system_theme_changed;147}148149// Retrieve high-contrast setting.150// -1: Unknown.151// 0: Disabled.152// 1: Enabled.153uint32_t get_high_contrast();154155// org.freedesktop.portal.Screenshot methods.156bool color_picker(const String &p_xid, const Callable &p_callback);157158// org.freedesktop.portal.Inhibit methods.159bool inhibit(const String &p_xid);160void uninhibit();161};162163#endif // DBUS_ENABLED164165166