ukui-settings-daemon/ 0000755 0001750 0001750 00000000000 14205117202 013544 5 ustar feng feng ukui-settings-daemon/plugins/ 0000755 0001750 0001750 00000000000 14205117202 015225 5 ustar feng feng ukui-settings-daemon/plugins/xsettings/ 0000755 0001750 0001750 00000000000 14205117202 017255 5 ustar feng feng ukui-settings-daemon/plugins/xsettings/ukui-xsettings-manager.h 0000644 0001750 0001750 00000003021 14205117202 024035 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef UKUIXSETTINGSMANAGER_H
#define UKUIXSETTINGSMANAGER_H
#include
#include
#include
#include
#include
#include
#include
//#include "ixsettings-manager.h"
#include "xsettings-manager.h"
#include "fontconfig-monitor.h"
class ukuiXSettingsManager
{
public:
ukuiXSettingsManager();
~ukuiXSettingsManager();
bool start();
int stop();
void sendSessionDbus();
//gboolean setup_xsettings_managers (ukuiXSettingsManager *manager);
XsettingsManager **pManagers;
GHashTable *gsettings;
GSettings *gsettings_font;
//GSettings *plugin_settings;
fontconfig_monitor_handle_t *fontconfig_handle;
};
#endif // UKUIXSETTINGSMANAGER_H
ukui-settings-daemon/plugins/xsettings/xsettings-common.c 0000644 0001750 0001750 00000014217 14205117202 022744 0 ustar feng feng /*
* Copyright © 2001 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Red Hat not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Red Hat makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Owen Taylor, Red Hat, Inc.
*/
#include "string.h"
#include "stdlib.h"
#include
#include /* For CARD32 */
#include "xsettings-common.h"
XSettingsSetting * xsettings_setting_copy (XSettingsSetting *setting)
{
XSettingsSetting *result;
size_t str_len;
result = malloc (sizeof *result);
if (!result)
return NULL;
str_len = strlen (setting->name);
result->name = malloc (str_len + 1);
if (!result->name)
goto err;
memcpy (result->name, setting->name, str_len + 1);
result->type = setting->type;
switch (setting->type)
{
case XSETTINGS_TYPE_INT:
result->data.v_int = setting->data.v_int;
break;
case XSETTINGS_TYPE_COLOR:
result->data.v_color = setting->data.v_color;
break;
case XSETTINGS_TYPE_STRING:
str_len = strlen (setting->data.v_string);
result->data.v_string = malloc (str_len + 1);
if (!result->data.v_string)
goto err;
memcpy (result->data.v_string, setting->data.v_string, str_len + 1);
break;
}
result->last_change_serial = setting->last_change_serial;
return result;
err:
if (result->name)
free (result->name);
free (result);
return NULL;
}
XSettingsList * xsettings_list_copy (XSettingsList *list)
{
XSettingsList *new = NULL;
XSettingsList *old_iter = list;
XSettingsList *new_iter = NULL;
while (old_iter)
{
XSettingsList *new_node;
new_node = malloc (sizeof *new_node);
if (!new_node)
goto error;
new_node->setting = xsettings_setting_copy (old_iter->setting);
if (!new_node->setting)
{
free (new_node);
goto error;
}
if (new_iter)
new_iter->next = new_node;
else
new = new_node;
new_iter = new_node;
old_iter = old_iter->next;
}
return new;
error:
xsettings_list_free (new);
return NULL;
}
int
xsettings_setting_equal (XSettingsSetting *setting_a,
XSettingsSetting *setting_b)
{
if (setting_a->type != setting_b->type)
return 0;
if (strcmp (setting_a->name, setting_b->name) != 0)
return 0;
switch (setting_a->type)
{
case XSETTINGS_TYPE_INT:
return setting_a->data.v_int == setting_b->data.v_int;
case XSETTINGS_TYPE_COLOR:
return (setting_a->data.v_color.red == setting_b->data.v_color.red &&
setting_a->data.v_color.green == setting_b->data.v_color.green &&
setting_a->data.v_color.blue == setting_b->data.v_color.blue &&
setting_a->data.v_color.alpha == setting_b->data.v_color.alpha);
case XSETTINGS_TYPE_STRING:
return strcmp (setting_a->data.v_string, setting_b->data.v_string) == 0;
}
return 0;
}
void
xsettings_setting_free (XSettingsSetting *setting)
{
if (setting->type == XSETTINGS_TYPE_STRING)
free (setting->data.v_string);
if (setting->name)
free (setting->name);
free (setting);
}
void
xsettings_list_free (XSettingsList *list)
{
while (list)
{
XSettingsList *next = list->next;
xsettings_setting_free (list->setting);
free (list);
list = next;
}
}
XSettingsResult
xsettings_list_insert (XSettingsList **list,
XSettingsSetting *setting)
{
XSettingsList *node;
XSettingsList *iter;
XSettingsList *last = NULL;
node = malloc (sizeof *node);
if (!node)
return XSETTINGS_NO_MEM;
node->setting = setting;
iter = *list;
while (iter)
{
int cmp = strcmp (setting->name, iter->setting->name);
if (cmp < 0)
break;
else if (cmp == 0)
{
free (node);
return XSETTINGS_DUPLICATE_ENTRY;
}
last = iter;
iter = iter->next;
}
if (last)
last->next = node;
else
*list = node;
node->next = iter;
return XSETTINGS_SUCCESS;
}
XSettingsResult
xsettings_list_delete (XSettingsList **list,
const char *name)
{
XSettingsList *iter;
XSettingsList *last = NULL;
iter = *list;
while (iter)
{
if (strcmp (name, iter->setting->name) == 0)
{
if (last)
last->next = iter->next;
else
*list = iter->next;
xsettings_setting_free (iter->setting);
free (iter);
return XSETTINGS_SUCCESS;
}
last = iter;
iter = iter->next;
}
return XSETTINGS_FAILED;
}
XSettingsSetting *
xsettings_list_lookup (XSettingsList *list,
const char *name)
{
XSettingsList *iter;
iter = list;
while (iter)
{
if (strcmp (name, iter->setting->name) == 0) {
return iter->setting;
}
iter = iter->next;
}
return NULL;
}
char
xsettings_byte_order (void)
{
CARD32 myint = 0x01020304;
return (*(char *)&myint == 1) ? MSBFirst : LSBFirst;
}
ukui-settings-daemon/plugins/xsettings/xsettings-const.h 0000644 0001750 0001750 00000004525 14205117202 022610 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef XSETTINGSCOMMON_H
#define XSETTINGSCOMMON_H
#define MOUSE_SCHEMA "org.ukui.peripherals-mouse"
#define INTERFACE_SCHEMA "org.mate.interface"
#define SOUND_SCHEMA "org.mate.sound"
#define CURSOR_THEME_KEY "cursor-theme"
#define CURSOR_SIZE_KEY "cursor-size"
#define FONT_RENDER_SCHEMA "org.ukui.font-rendering"
#define FONT_ANTIALIASING_KEY "antialiasing"
#define FONT_HINTING_KEY "hinting"
#define FONT_RGBA_ORDER_KEY "rgba-order"
#define FONT_DPI_KEY "dpi"
#define XSETTINGS_PLUGIN_SCHEMA "org.ukui.SettingsDaemon.plugins.xsettings"
#define SCALING_FACTOR_KEY "scaling-factor"
/* X servers sometimes lie about the screen's physical dimensions, so we cannot
* compute an accurate DPI value. When this happens, the user gets fonts that
* are too huge or too tiny. So, we see what the server returns: if it reports
* something outside of the range [DPI_LOW_REASONABLE_VALUE,
* DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use
* DPI_FALLBACK instead.
*
* See get_dpi_from_gsettings_or_server() below, and also
* https://bugzilla.novell.com/show_bug.cgi?id=217790
*/
#define DPI_FALLBACK 96
#define DPI_LOW_REASONABLE_VALUE 50
#define DPI_HIGH_REASONABLE_VALUE 500
/* The minimum resolution at which we turn on a window-scale of 2 */
#define HIDPI_LIMIT (DPI_FALLBACK * 2)
/* The minimum screen height at which we turn on a window-scale of 2;
* below this there just isn't enough vertical real estate for GNOME
* apps to work, and it's better to just be tiny */
#define HIDPI_MIN_HEIGHT 1500
#endif // XSETTINGSCOMMON_H
ukui-settings-daemon/plugins/xsettings/fontconfig-monitor.c 0000644 0001750 0001750 00000010561 14205117202 023245 0 ustar feng feng /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author: Behdad Esfahbod, Red Hat, Inc.
*/
#include "fontconfig-monitor.h"
#include
#include
#define TIMEOUT_SECONDS 2
static void
stuff_changed (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
GFileMonitorEvent event_type,
gpointer handle);
void
fontconfig_cache_init (void)
{
FcInit ();
}
gboolean
fontconfig_cache_update (void)
{
return !FcConfigUptoDate (NULL) && FcInitReinitialize ();
}
static void
monitor_files (GPtrArray *monitors,
FcStrList *list,
gpointer data)
{
const char *str;
while ((str = (const char *) FcStrListNext (list))) {
GFile *file;
GFileMonitor *monitor;
file = g_file_new_for_path (str);
monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, NULL);
g_object_unref (file);
if (!monitor)
continue;
g_signal_connect (monitor, "changed", G_CALLBACK (stuff_changed), data);
g_ptr_array_add (monitors, monitor);
}
FcStrListDone (list);
}
struct _fontconfig_monitor_handle {
GPtrArray *monitors;
guint timeout;
GFunc notify_callback;
gpointer notify_data;
};
static GPtrArray *
monitors_create (gpointer data)
{
GPtrArray *monitors = g_ptr_array_new ();
monitor_files (monitors, FcConfigGetConfigFiles (NULL), data);
monitor_files (monitors, FcConfigGetFontDirs (NULL), data);
return monitors;
}
static void
monitors_free (GPtrArray *monitors)
{
if (!monitors)
return;
g_ptr_array_foreach (monitors, (GFunc) g_object_unref, NULL);
g_ptr_array_free (monitors, TRUE);
}
static gboolean
update (gpointer data)
{
fontconfig_monitor_handle_t *handle = data;
gboolean notify = FALSE;
handle->timeout = 0;
if (fontconfig_cache_update ()) {
notify = TRUE;
monitors_free (handle->monitors);
handle->monitors = monitors_create (data);
}
/* we finish modifying handle before calling the notify callback,
* allowing the callback to free the monitor if it decides to. */
if (notify && handle->notify_callback)
handle->notify_callback (data, handle->notify_data);
return FALSE;
}
static void
stuff_changed (GFileMonitor *monitor G_GNUC_UNUSED,
GFile *file G_GNUC_UNUSED,
GFile *other_file G_GNUC_UNUSED,
GFileMonitorEvent event_type G_GNUC_UNUSED,
gpointer data)
{
fontconfig_monitor_handle_t *handle = data;
/* wait for quiescence */
if (handle->timeout)
g_source_remove (handle->timeout);
handle->timeout = g_timeout_add_seconds (TIMEOUT_SECONDS, update, data);
}
fontconfig_monitor_handle_t *
fontconfig_monitor_start (GFunc notify_callback,
gpointer notify_data)
{
fontconfig_monitor_handle_t *handle = g_slice_new0 (fontconfig_monitor_handle_t);
handle->notify_callback = notify_callback;
handle->notify_data = notify_data;
handle->monitors = monitors_create (handle);
return handle;
}
void
fontconfig_monitor_stop (fontconfig_monitor_handle_t *handle)
{
if (handle->timeout)
g_source_remove (handle->timeout);
handle->timeout = 0;
monitors_free (handle->monitors);
handle->monitors = NULL;
}
#ifdef FONTCONFIG_MONITOR_TEST
static void
yay (void)
{
g_message ("yay");
}
int
main (void)
{
GMainLoop *loop;
fontconfig_monitor_start ((GFunc) yay, NULL);
loop = g_main_loop_new (NULL, TRUE);
g_main_loop_run (loop);
return 0;
}
#endif
ukui-settings-daemon/plugins/xsettings/xsettings.pro 0000644 0001750 0001750 00000002054 14205117202 022030 0 ustar feng feng #-------------------------------------------------
#
# Project created by QtCreator 2020-05-30T09:30:00
#
#-------------------------------------------------
QT += gui
QT += core widgets x11extras dbus
CONFIG += c++11 no_keywords link_pkgconfig plugin
CONFIG += app_bunale
DEFINES += QT_DEPRECATED_WARNINGS
TEMPLATE = lib
TARGET = xsettings
DEFINES += QT_DEPRECATED_WARNINGS MODULE_NAME=\\\"xsettings\\\"
include($$PWD/../../common/common.pri)
PKGCONFIG +=\
glib-2.0 \
gio-2.0 \
gdk-3.0 \
atk \
fontconfig \
xcursor \
xfixes
SOURCES += \
ukui-xsettings-plugin.cpp \
xsettings-manager.cpp \
ukui-xsettings-manager.cpp \
ukui-xft-settings.cpp \
xsettings-common.c \
fontconfig-monitor.c
HEADERS += \
ukui-xsettings-plugin.h \
xsettings-manager.h \
ukui-xsettings-manager.h \
ukui-xft-settings.h \
xsettings-const.h \
xsettings-common.h \
fontconfig-monitor.h
xsettings_lib.path = $${PLUGIN_INSTALL_DIRS}
xsettings_lib.files += $$OUT_PWD/libxsettings.so
INSTALLS += xsettings_lib
ukui-settings-daemon/plugins/xsettings/ukui-xft-settings.cpp 0000644 0001750 0001750 00000035560 14205117202 023404 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include "xsettings-const.h"
#include "ukui-xft-settings.h"
#include "ukui-xsettings-manager.h"
#ifdef __cplusplus
extern "C" {
#endif
#include
#include
#include
#ifdef __cplusplus
}
#endif
static const char *rgba_types[] = { "rgb", "bgr", "vbgr", "vrgb" };
static void update_property (GString *props, const gchar* key, const gchar* value)
{
gchar* needle;
size_t needle_len;
gchar* found = NULL;
/* update an existing property */
needle = g_strconcat (key, ":", NULL);
needle_len = strlen (needle);
if (g_str_has_prefix (props->str, needle))
found = props->str;
else
found = strstr (props->str, needle);
if (found) {
size_t value_index;
gchar* end;
end = strchr (found, '\n');
value_index = (found - props->str) + needle_len + 1;
g_string_erase (props, value_index, end ? (end - found - needle_len) : -1);
g_string_insert (props, value_index, "\n");
g_string_insert (props, value_index, value);
} else {
g_string_append_printf (props, "%s:\t%s\n", key, value);
}
g_free (needle);
}
static double dpi_from_pixels_and_mm (int pixels, int mm)
{
double dpi;
if (mm >= 1)
dpi = pixels / (mm / 25.4);
else
dpi = 0;
return dpi;
}
static double get_dpi_from_x_server (void)
{
GdkScreen *screen;
double dpi;
screen = gdk_screen_get_default ();
if (screen != NULL) {
double width_dpi, height_dpi;
Screen *xscreen = gdk_x11_screen_get_xscreen (screen);
width_dpi = dpi_from_pixels_and_mm (WidthOfScreen (xscreen), WidthMMOfScreen (xscreen));
height_dpi = dpi_from_pixels_and_mm (HeightOfScreen (xscreen), HeightMMOfScreen (xscreen));
if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE
|| height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE) {
dpi = DPI_FALLBACK;
} else {
dpi = (width_dpi + height_dpi) / 2.0;
}
} else {
/* Huh!? No screen? */
dpi = DPI_FALLBACK;
}
return dpi;
}
static double get_dpi_from_gsettings_or_x_server (GSettings *gsettings)
{
double value;
double dpi;
value = g_settings_get_double (gsettings, FONT_DPI_KEY);
/* If the user has ever set the DPI preference in GSettings, we use that.
* Otherwise, we see if the X server reports a reasonable DPI value: some X
* servers report completely bogus values, and the user gets huge or tiny
* fonts which are unusable.
*/
if (value != 0) {
dpi = value;
} else {
dpi = DPI_FALLBACK;//get_dpi_from_x_server ();
}
return dpi;
}
/* Auto-detect the most appropriate scale factor for the primary monitor.
* A lot of this code is copied and adapted from Linux Mint/Cinnamon.
* 如果设置缩放为0,通过获取物理显示器的分辨率大小进行设置合适的DPI缩放
*/
static int
get_window_scale_auto ()
{
GdkDisplay *display;
GdkMonitor *monitor;
GdkRectangle rect;
int width_mm, height_mm;
int monitor_scale, window_scale;
display = gdk_display_get_default ();
monitor = gdk_display_get_primary_monitor (display);
/* Use current value as the default */
window_scale = 1;
gdk_monitor_get_geometry (monitor, &rect);
width_mm = gdk_monitor_get_width_mm (monitor);
height_mm = gdk_monitor_get_height_mm (monitor);
monitor_scale = gdk_monitor_get_scale_factor (monitor);
if (rect.height * monitor_scale < HIDPI_MIN_HEIGHT)
return 1;
/* Some monitors/TV encode the aspect ratio (16/9 or 16/10) instead of the physical size */
if ((width_mm == 160 && height_mm == 90) ||
(width_mm == 160 && height_mm == 100) ||
(width_mm == 16 && height_mm == 9) ||
(width_mm == 16 && height_mm == 10))
return 1;
if (width_mm > 0 && height_mm > 0) {
double dpi_x, dpi_y;
dpi_x = (double)rect.width * monitor_scale / (width_mm / 25.4);
dpi_y = (double)rect.height * monitor_scale / (height_mm / 25.4);
/* We don't completely trust these values so both must be high, and never pick
* higher ratio than 2 automatically */
if (dpi_x > HIDPI_LIMIT && dpi_y > HIDPI_LIMIT)
window_scale = 2;
}
return window_scale;
}
/* Get the key value to set the zoom
* 获取要设置缩放的键值
*/
static double
get_window_scale (ukuiXSettingsManager *manager)
{
GSettings *gsettings;
double scale;
gsettings = (GSettings *)g_hash_table_lookup(manager->gsettings,XSETTINGS_PLUGIN_SCHEMA);
scale = g_settings_get_double (gsettings, SCALING_FACTOR_KEY);
/* Auto-detect */
if (scale == 0)
scale = get_window_scale_auto ();
return scale;
}
void UkuiXftSettings::xft_settings_set_xsettings (ukuiXSettingsManager *manager)
{
int i;
double scale = get_window_scale (manager);
if(scale >= 2.0)
scale = scale - 1.0;
if(scale >= 3.0)
scale = scale - 2.0;
for (i = 0; manager->pManagers [i]; i++) {
manager->pManagers [i]->set_int ("Xft/Antialias", antialias);
manager->pManagers [i]->set_int ("Xft/Hinting", hinting);
manager->pManagers [i]->set_string ("Xft/HintStyle", hintstyle);
manager->pManagers [i]->set_int ( "Gdk/WindowScalingFactor",window_scale);
manager->pManagers [i]->set_int ("Gdk/UnscaledDPI",(double)dpi * scale);
manager->pManagers [i]->set_int ("Xft/DPI", scaled_dpi);
manager->pManagers [i]->set_string ("Xft/RGBA", rgba);
manager->pManagers [i]->set_string ("Xft/lcdfilter",
g_str_equal (rgba, "rgb") ? "lcddefault" : "none");
manager->pManagers [i]->set_int ("Gtk/CursorThemeSize", cursor_size);
manager->pManagers [i]->set_string ("Gtk/CursorThemeName", cursor_theme);
GdkCursor *cursor = gdk_cursor_new_for_display(gdk_display_get_default(),
GDK_LEFT_PTR);
gdk_window_set_cursor(gdk_get_default_root_window(), cursor);
g_object_unref(G_OBJECT(cursor));
}
}
void UkuiXftSettings::xft_settings_get (ukuiXSettingsManager *manager)
{
GSettings *mouse_gsettings;
char *antialiasing;
char *hinting;
char *rgba_order;
double dpi;
double scale;
mouse_gsettings = (GSettings *)g_hash_table_lookup (manager->gsettings, (void*)MOUSE_SCHEMA);
antialiasing = g_settings_get_string (manager->gsettings_font, FONT_ANTIALIASING_KEY);
hinting = g_settings_get_string (manager->gsettings_font, FONT_HINTING_KEY);
rgba_order = g_settings_get_string (manager->gsettings_font, FONT_RGBA_ORDER_KEY);
dpi = get_dpi_from_gsettings_or_x_server (manager->gsettings_font);
scale = get_window_scale (manager);
antialias = TRUE;
this->hinting = TRUE;
hintstyle = "hintslight";
if (scale >= 0 && scale <= 1.5) {
this->window_scale = 1;
} else if (scale >= 1.75 && scale <= 2.5) {
this->window_scale = 2;
} else if (scale >= 2.75) {
this->window_scale = 3;
}
this->dpi = dpi * 1024; /* Xft wants 1/1024ths of an inch */
this->scaled_dpi = dpi * scale * 1024;
cursor_theme = g_settings_get_string (mouse_gsettings, CURSOR_THEME_KEY);
cursor_size = g_settings_get_int (mouse_gsettings, CURSOR_SIZE_KEY);
rgba = "rgb";
if (rgba_order) {
int i;
gboolean found = FALSE;
for (i = 0; i < (int)G_N_ELEMENTS (rgba_types) && !found; i++) {
if (strcmp (rgba_order, rgba_types[i]) == 0) {
rgba = rgba_types[i];
found = TRUE;
}
}
if (!found) {
g_warning ("Invalid value for " FONT_RGBA_ORDER_KEY ": '%s'",
rgba_order);
}
}
if (hinting) {
if (strcmp (hinting, "none") == 0) {
this->hinting = 0;
hintstyle = "hintnone";
} else if (strcmp (hinting, "slight") == 0) {
this->hinting = 1;
hintstyle = "hintslight";
} else if (strcmp (hinting, "medium") == 0) {
this->hinting = 1;
hintstyle = "hintmedium";
} else if (strcmp (hinting, "full") == 0) {
this->hinting = 1;
hintstyle = "hintfull";
} else {
g_warning ("Invalid value for " FONT_HINTING_KEY ": '%s'",
hinting);
}
}
if (antialiasing) {
gboolean use_rgba = FALSE;
if (strcmp (antialiasing, "none") == 0) {
antialias = 0;
} else if (strcmp (antialiasing, "grayscale") == 0) {
antialias = 1;
} else if (strcmp (antialiasing, "rgba") == 0) {
antialias = 1;
use_rgba = TRUE;
} else {
g_warning ("Invalid value for " FONT_ANTIALIASING_KEY " : '%s'",
antialiasing);
}
if (!use_rgba) {
rgba = "none";
}
}
g_free (rgba_order);
g_free (hinting);
g_free (antialiasing);
}
void UkuiXftSettings::xft_settings_set_xresources ()
{
GString *add_string;
char dpibuf[G_ASCII_DTOSTR_BUF_SIZE];
Display *dpy;
/* get existing properties */
dpy = XOpenDisplay (NULL);
g_return_if_fail (dpy != NULL);
add_string = g_string_new (XResourceManagerString (dpy));
g_debug("xft_settings_set_xresources: orig res '%s'", add_string->str);
char tmpCursorTheme[255] = {'\0'};
int tmpCursorSize = 0;
if (strlen (this->cursor_theme) > 0) {
strncpy(tmpCursorTheme, this->cursor_theme, 255);
} else {
// unset, use default
strncpy(tmpCursorTheme, "DMZ-Black", 255);
}
if (this->cursor_size > 0) {
tmpCursorSize = this->cursor_size;
} else {
tmpCursorSize = XcursorGetDefaultSize(dpy);
}
QDir dir;
QString FilePath = dir.homePath() + "/.xresources";
QFile file;
QString date = QString("Xcursor.size:%1\n"
"Xcursor.theme:%2").arg(cursor_size).arg(cursor_theme);
file.setFileName(FilePath);
if(file.open(QIODevice::WriteOnly | QIODevice::Text)){
file.write(date.toLatin1().data());
}
file.close();
update_property (add_string, "Xft.dpi",
g_ascii_dtostr (dpibuf, sizeof (dpibuf), (double) this->scaled_dpi / 1024.0));
update_property (add_string, "Xft.antialias",
this->antialias ? "1" : "0");
update_property (add_string, "Xft.hinting",
this->hinting ? "1" : "0");
update_property (add_string, "Xft.hintstyle",
this->hintstyle);
update_property (add_string, "Xft.rgba",
this->rgba);
update_property (add_string, "Xft.lcdfilter",
g_str_equal (this->rgba, "rgb") ? "lcddefault" : "none");
update_property (add_string, "Xcursor.theme",
this->cursor_theme);
update_property (add_string, "Xcursor.size",
g_ascii_dtostr (dpibuf, sizeof (dpibuf), (double) this->cursor_size));
g_debug("xft_settings_set_xresources: new res '%s'", add_string->str);
/* Set the new X property */
XChangeProperty(dpy, RootWindow (dpy, 0),
XA_RESOURCE_MANAGER, XA_STRING, 8, PropModeReplace, (unsigned char *) add_string->str, add_string->len);
// begin add:for qt adjust cursor size&theme. add by liutong
const char *CursorsNames[] = {
"X_cursor" , "arrow" , "bottom_side" , "bottom_tee" ,
"bd_double_arrow", "bottom_left_corner", "bottom_right_corner", "color-picker",
"cross" , "cross_reverse" , "copy" , "circle" ,
"crossed_circle", "dnd-ask" , "dnd-copy" , "dnd-link" ,
"dnd-move" , "dnd-none" , "dot_box_mask" , "fd_double_arrow",
"crosshair" , "diamond_cross" , "dotbox" , "draped_box" ,
"double_arrow" , "draft_large" , "draft_small" , "fleur" ,
"grabbing" , "help" , "hand", "hand1" , "hand2" ,
"icon" , "left_ptr" , "left_side" , "left_tee" ,
"left_ptr_watch", "ll_angle" , "lr_angle" , "link" ,
"move" , "pencil" , "pirate" , "plus" ,
"question_arrow", "right_ptr" , "right_side" , "right_tee" ,
"sb_down_arrow" , "sb_h_double_arrow", "sb_left_arrow" , "sb_right_arrow" ,
"sb_up_arrow" , "sb_v_double_arrow", "target" , "tcross" ,
"top_left_arrow", "top_left_corner" , "top_right_corner", "top_side" ,
"top_tee" , "ul_angle" , "ur_angle" , "watch" ,
"xterm" , "h_double_arrow" , "v_double_arrow" , "left_ptr_help",
NULL};
if (strlen (tmpCursorTheme) > 0 ) {
int len = sizeof(CursorsNames)/sizeof(*CursorsNames);
for (int i = 0; i < len-1; i++) {
XcursorImages *images = XcursorLibraryLoadImages(CursorsNames[i], tmpCursorTheme, tmpCursorSize);
if (!images) {
g_debug("xcursorlibrary load images :null image, theme name=%s", tmpCursorTheme);
continue;
}
Cursor handle = XcursorImagesLoadCursor(dpy, images);
int event_base, error_base;
if (XFixesQueryExtension(dpy, &event_base, &error_base))
{
int major, minor;
XFixesQueryVersion(dpy, &major, &minor);
if (major >= 2) {
g_debug("set CursorNmae=%s", CursorsNames[i]);
XFixesSetCursorName(dpy, handle, CursorsNames[i]);
}
}
XFixesChangeCursorByName(dpy, handle, CursorsNames[i]);
XcursorImagesDestroy(images);
}
}
// end add
XCloseDisplay (dpy);
g_string_free (add_string, TRUE);
}
ukui-settings-daemon/plugins/xsettings/xsettings-manager.cpp 0000644 0001750 0001750 00000024701 14205117202 023425 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include "xsettings-manager.h"
#include "xsettings-const.h"
#include
#include
#include
#include
#include
#include
#include
static Time get_server_time (Display *display,
Window window);
static XSettingsList *Settings;
XsettingsManager::XsettingsManager(Display *display,
int screen,
XSettingsTerminateFunc terminate,
int *cb_data)
{
XClientMessageEvent xev;
this->display = display;
this->screen = screen;
char buffer[256];
sprintf(buffer, "_XSETTINGS_S%d", this->screen);
this->selection_atom = XInternAtom (display, buffer, False);
this->xsettings_atom = XInternAtom (display, "_XSETTINGS_SETTINGS", False);
this->manager_atom = XInternAtom (display, "MANAGER", False);
this->terminate = terminate;
this->cb_data = cb_data;
this->settings = NULL;
this->serial = 0;
this->window = XCreateSimpleWindow (display,
RootWindow (display, screen),
0, 0, 10, 10, 0,
WhitePixel (display, screen),
WhitePixel (display, screen));
XSelectInput (display, this->window, PropertyChangeMask);
Time timestamp;
timestamp = get_server_time (display, this->window);
XSetSelectionOwner (display, this->selection_atom,
this->window, timestamp);
/* Check to see if we managed to claim the selection. If not,
* we treat it as if we got it then immediately lost it
*/
if (XGetSelectionOwner (display, this->selection_atom) ==
this->window)
{
xev.type = ClientMessage;
xev.window = RootWindow (display, screen);
xev.message_type = this->manager_atom;
xev.format = 32;
xev.data.l[0] = timestamp;
xev.data.l[1] = this->selection_atom;
xev.data.l[2] = this->window;
xev.data.l[3] = 0; /* manager specific data */
xev.data.l[4] = 0; /* manager specific data */
XSendEvent (display, RootWindow (display, screen),
False, StructureNotifyMask, (XEvent *)&xev);
}
else
{
this->terminate ((int*)this->cb_data);
}
}
XsettingsManager::~XsettingsManager()
{
XDestroyWindow (display, window);
xsettings_list_free (settings);
}
/**
* get_server_time:
* @display: display from which to get the time
* @window: a #Window, used for communication with the server.
* The window must have PropertyChangeMask in its
* events mask or a hang will result.
*
* Routine to get the current X server time stamp.
*
* Return value: the time stamp.
**/
typedef struct
{
Window window;
Atom timestamp_prop_atom;
} TimeStampInfo;
static Bool
timestamp_predicate (Display *display,
XEvent *xevent,
XPointer arg)
{
TimeStampInfo *info = (TimeStampInfo *)arg;
if (xevent->type == PropertyNotify &&
xevent->xproperty.window == info->window &&
xevent->xproperty.atom == info->timestamp_prop_atom)
return True;
return False;
}
static Time get_server_time (Display *display,
Window window)
{
unsigned char c = 'a';
XEvent xevent;
TimeStampInfo info;
info.timestamp_prop_atom = XInternAtom (display, "_TIMESTAMP_PROP", False);
info.window = window;
XChangeProperty (display, window,
info.timestamp_prop_atom, info.timestamp_prop_atom,
8, PropModeReplace, &c, 1);
XIfEvent (display, &xevent,
timestamp_predicate, (XPointer)&info);
return xevent.xproperty.time;
}
Window XsettingsManager::get_window()
{
return window;
}
Bool XsettingsManager::process_event (XEvent *xev)
{
if (xev->xany.window == this->window &&
xev->xany.type == SelectionClear &&
xev->xselectionclear.selection == this->selection_atom)
{
this->terminate ((int *)this->cb_data);
return True;
}
return False;
}
XSettingsResult XsettingsManager::delete_setting (const char *name)
{
return xsettings_list_delete (&Settings, name);
}
XSettingsResult XsettingsManager::set_setting (XSettingsSetting *setting)
{
XSettingsSetting *old_setting = xsettings_list_lookup (Settings, setting->name);
XSettingsSetting *new_setting;
XSettingsResult result;
if (old_setting)
{
if (xsettings_setting_equal (old_setting, setting))
return XSETTINGS_SUCCESS;
xsettings_list_delete (&Settings, setting->name);
}
new_setting = xsettings_setting_copy (setting);
if (!new_setting)
return XSETTINGS_NO_MEM;
new_setting->last_change_serial = this->serial;
result = xsettings_list_insert (&Settings, new_setting);
if (result != XSETTINGS_SUCCESS)
xsettings_setting_free (new_setting);
return result;
}
XSettingsResult XsettingsManager::set_int (const char *name,
int value)
{
XSettingsSetting setting;
setting.name = (char *)name;
setting.type = XSETTINGS_TYPE_INT;
setting.data.v_int = value;
return set_setting (&setting);
}
XSettingsResult XsettingsManager::set_string (const char *name,
const char *value)
{
XSettingsSetting setting;
setting.name = (char *)name;
setting.type = XSETTINGS_TYPE_STRING;
setting.data.v_string = (char *)value;
return set_setting (&setting);
}
XSettingsResult XsettingsManager::set_color (const char *name,
XSettingsColor *value)
{
XSettingsSetting setting;
setting.name = (char *)name;
setting.type = XSETTINGS_TYPE_COLOR;
setting.data.v_color = *value;
return set_setting (&setting);
}
static size_t setting_length (XSettingsSetting *setting)
{
size_t length = 8; /* type + pad + name-len + last-change-serial */
length += XSETTINGS_PAD (strlen (setting->name), 4);
switch (setting->type)
{
case XSETTINGS_TYPE_INT:
length += 4;
break;
case XSETTINGS_TYPE_STRING:
length += 4 + XSETTINGS_PAD (strlen (setting->data.v_string), 4);
break;
case XSETTINGS_TYPE_COLOR:
length += 8;
break;
}
return length;
}
Bool xsettings_manager_check_running (Display *display,
int screen)
{
char buffer[256];
Atom selection_atom;
sprintf(buffer, "_XSETTINGS_S%d", screen);
selection_atom = XInternAtom (display, buffer, False);
gdk_x11_display_error_trap_push (gdk_display_get_default());
if (XGetSelectionOwner (display, selection_atom)){
gdk_x11_display_error_trap_pop_ignored (gdk_display_get_default());
return True;
}
else
return False;
}
void XsettingsManager::setting_store (XSettingsSetting *setting,
XSettingsBuffer *buffer)
{
size_t string_len;
size_t length;
*(buffer->pos++) = setting->type;
*(buffer->pos++) = 0;
string_len = strlen (setting->name);
*(CARD16 *)(buffer->pos) = string_len;
buffer->pos += 2;
length = XSETTINGS_PAD (string_len, 4);
memcpy (buffer->pos, setting->name, string_len);
length -= string_len;
buffer->pos += string_len;
while (length > 0)
{
*(buffer->pos++) = 0;
length--;
}
*(CARD32 *)(buffer->pos) = setting->last_change_serial;
buffer->pos += 4;
switch (setting->type)
{
case XSETTINGS_TYPE_INT:
*(CARD32 *)(buffer->pos) = setting->data.v_int;
buffer->pos += 4;
break;
case XSETTINGS_TYPE_STRING:
string_len = strlen (setting->data.v_string);
*(CARD32 *)(buffer->pos) = string_len;
buffer->pos += 4;
length = XSETTINGS_PAD (string_len, 4);
memcpy (buffer->pos, setting->data.v_string, string_len);
length -= string_len;
buffer->pos += string_len;
while (length > 0)
{
*(buffer->pos++) = 0;
length--;
}
break;
case XSETTINGS_TYPE_COLOR:
*(CARD16 *)(buffer->pos) = setting->data.v_color.red;
*(CARD16 *)(buffer->pos + 2) = setting->data.v_color.green;
*(CARD16 *)(buffer->pos + 4) = setting->data.v_color.blue;
*(CARD16 *)(buffer->pos + 6) = setting->data.v_color.alpha;
buffer->pos += 8;
break;
}
}
XSettingsResult XsettingsManager::notify()
{
XSettingsBuffer buffer;
XSettingsList *iter;
int n_settings = 0;
buffer.len = 12; /* byte-order + pad + SERIAL + N_SETTINGS */
iter = Settings;
while (iter)
{
buffer.len += setting_length (iter->setting);
n_settings++;
iter = iter->next;
}
buffer.data = buffer.pos = new unsigned char[buffer.len];
if (!buffer.data)
return XSETTINGS_NO_MEM;
*buffer.pos = xsettings_byte_order ();
buffer.pos += 4;
*(CARD32 *)buffer.pos = this->serial++;
buffer.pos += 4;
*(CARD32 *)buffer.pos = n_settings;
buffer.pos += 4;
iter = Settings;
while (iter)
{
setting_store (iter->setting, &buffer);
iter = iter->next;
}
XChangeProperty (this->display, this->window,
this->xsettings_atom, this->xsettings_atom,
8, PropModeReplace, buffer.data, buffer.len);
free (buffer.data);
return XSETTINGS_SUCCESS;
}
ukui-settings-daemon/plugins/xsettings/ukui-xsettings-plugin.cpp 0000644 0001750 0001750 00000003517 14205117202 024266 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include "ukui-xsettings-plugin.h"
#include "clib-syslog.h"
PluginInterface *XSettingsPlugin::mInstance =nullptr;
ukuiXSettingsManager *XSettingsPlugin::m_pukuiXsettingManager = nullptr;
XSettingsPlugin::XSettingsPlugin()
{
if(nullptr == m_pukuiXsettingManager)
m_pukuiXsettingManager = new ukuiXSettingsManager();
}
XSettingsPlugin::~XSettingsPlugin()
{
if (m_pukuiXsettingManager) {
delete m_pukuiXsettingManager;
m_pukuiXsettingManager = nullptr;
}
}
void XSettingsPlugin::activate()
{
bool res;
res = m_pukuiXsettingManager->start();
if (!res) {
qWarning ("Unable to start XSettingsPlugin manager");
}
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
}
void XSettingsPlugin::deactivate()
{
m_pukuiXsettingManager->stop();
}
PluginInterface *XSettingsPlugin::getInstance()
{
if(nullptr == mInstance)
mInstance = new XSettingsPlugin();
return mInstance;
}
PluginInterface* createSettingsPlugin() {
return XSettingsPlugin::getInstance();
}
ukui-settings-daemon/plugins/xsettings/ukui-xsettings-manager.cpp 0000644 0001750 0001750 00000043702 14205117202 024402 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include
#include
#include
#include
#include
#include "ukui-xsettings-manager.h"
#include "xsettings-manager.h"
#include "fontconfig-monitor.h"
#include "ukui-xft-settings.h"
#include "xsettings-const.h"
#include
#include
#include "clib-syslog.h"
#include
#include
#include
#define MOUSE_SCHEMA "org.ukui.peripherals-mouse"
#define INTERFACE_SCHEMA "org.mate.interface"
#define SOUND_SCHEMA "org.mate.sound"
#define CURSOR_THEME_KEY "cursor-theme"
#define CURSOR_SIZE_KEY "cursor-size"
/* X servers sometimes lie about the screen's physical dimensions, so we cannot
* compute an accurate DPI value. When this happens, the user gets fonts that
* are too huge or too tiny. So, we see what the server returns: if it reports
* something outside of the range [DPI_LOW_REASONABLE_VALUE,
* DPI_HIGH_REASONABLE_VALUE], then we assume that it is lying and we use
* DPI_FALLBACK instead.
*
* See get_dpi_from_gsettings_or_server() below, and also
* https://bugzilla.novell.com/show_bug.cgi?id=217790
*/
#define DPI_FALLBACK 96
#define DPI_LOW_REASONABLE_VALUE 50
#define DPI_HIGH_REASONABLE_VALUE 500
typedef struct _TranslationEntry TranslationEntry;
typedef void (* TranslationFunc) (ukuiXSettingsManager *manager,
TranslationEntry *trans,
GVariant *value);
struct _TranslationEntry {
const char *gsettings_schema;
const char *gsettings_key;
const char *xsetting_name;
TranslationFunc translate;
};
struct ukuiXSettingsManagerPrivate
{
XsettingsManager **pManagers;
GHashTable *gsettings;
GSettings *gsettings_font;
// fontconfig_monitor_handle_t *fontconfig_handle;
};
#define USD_XSETTINGS_ERROR usd_xsettings_error_quark ()
enum {
USD_XSETTINGS_ERROR_INIT
};
static void fontconfig_callback (fontconfig_monitor_handle_t *handle,
ukuiXSettingsManager *manager);
static void
xft_callback (GSettings *gsettings,
const gchar *key,
ukuiXSettingsManager *manager);
static GQuark
usd_xsettings_error_quark (void)
{
return g_quark_from_static_string ("usd-xsettings-error-quark");
}
static void
translate_bool_int (ukuiXSettingsManager *manager,
TranslationEntry *trans,
GVariant *value)
{
int i;
for (i = 0; manager->pManagers [i]; i++) {
manager->pManagers [i]->set_int (trans->xsetting_name,
g_variant_get_boolean (value));
}
}
static void
translate_int_int (ukuiXSettingsManager *manager,
TranslationEntry *trans,
GVariant *value)
{
int i;
for (i = 0; manager-> pManagers [i]; i++) {
manager-> pManagers [i]->set_int (trans->xsetting_name,
g_variant_get_int32 (value));
}
}
static void
translate_string_string (ukuiXSettingsManager *manager,
TranslationEntry *trans,
GVariant *value)
{
int i;
for (i = 0; manager-> pManagers [i]; i++) {
manager-> pManagers [i]->set_string (trans->xsetting_name,
g_variant_get_string (value, NULL));
}
}
static void
translate_string_string_toolbar (ukuiXSettingsManager *manager,
TranslationEntry *trans,
GVariant *value)
{
int i;
const char *tmp;
/* This is kind of a workaround since GNOME expects the key value to be
* "both_horiz" and gtk+ wants the XSetting to be "both-horiz".
*/
tmp = g_variant_get_string (value, NULL);
if (tmp && strcmp (tmp, "both_horiz") == 0) {
tmp = "both-horiz";
}
for (i = 0; manager-> pManagers [i]; i++) {
manager-> pManagers [i]->set_string (trans->xsetting_name,
tmp);
}
}
static TranslationEntry translations [] = {
{ MOUSE_SCHEMA, "double-click", "Net/DoubleClickTime", translate_int_int },
{ MOUSE_SCHEMA, "drag-threshold", "Net/DndDragThreshold", translate_int_int },
{ MOUSE_SCHEMA, "cursor-theme", "Gtk/CursorThemeName", translate_string_string },
{ MOUSE_SCHEMA, "cursor-size", "Gtk/CursorThemeSize", translate_int_int },
{ INTERFACE_SCHEMA, "font-name", "Gtk/FontName", translate_string_string },
{ INTERFACE_SCHEMA, "gtk-key-theme", "Gtk/KeyThemeName", translate_string_string },
{ INTERFACE_SCHEMA, "toolbar-style", "Gtk/ToolbarStyle", translate_string_string_toolbar },
{ INTERFACE_SCHEMA, "toolbar-icons-size", "Gtk/ToolbarIconSize", translate_string_string },
{ INTERFACE_SCHEMA, "cursor-blink", "Net/CursorBlink", translate_bool_int },
{ INTERFACE_SCHEMA, "cursor-blink-time", "Net/CursorBlinkTime", translate_int_int },
{ INTERFACE_SCHEMA, "gtk-theme", "Net/ThemeName", translate_string_string },
{ INTERFACE_SCHEMA, "gtk-color-scheme", "Gtk/ColorScheme", translate_string_string },
{ INTERFACE_SCHEMA, "gtk-im-preedit-style", "Gtk/IMPreeditStyle", translate_string_string },
{ INTERFACE_SCHEMA, "gtk-im-status-style", "Gtk/IMStatusStyle", translate_string_string },
{ INTERFACE_SCHEMA, "gtk-im-module", "Gtk/IMModule", translate_string_string },
{ INTERFACE_SCHEMA, "icon-theme", "Net/IconThemeName", translate_string_string },
{ INTERFACE_SCHEMA, "file-chooser-backend", "Gtk/FileChooserBackend", translate_string_string },
{ INTERFACE_SCHEMA, "gtk-decoration-layout", "Gtk/DecorationLayout", translate_string_string },
{ INTERFACE_SCHEMA, "gtk-shell-shows-app-menu","Gtk/ShellShowsAppMenu", translate_bool_int },
{ INTERFACE_SCHEMA, "gtk-shell-shows-menubar","Gtk/ShellShowsMenubar", translate_bool_int },
{ INTERFACE_SCHEMA, "menus-have-icons", "Gtk/MenuImages", translate_bool_int },
{ INTERFACE_SCHEMA, "buttons-have-icons", "Gtk/ButtonImages", translate_bool_int },
{ INTERFACE_SCHEMA, "menubar-accel", "Gtk/MenuBarAccel", translate_string_string },
{ INTERFACE_SCHEMA, "show-input-method-menu", "Gtk/ShowInputMethodMenu", translate_bool_int },
{ INTERFACE_SCHEMA, "show-unicode-menu", "Gtk/ShowUnicodeMenu", translate_bool_int },
{ INTERFACE_SCHEMA, "automatic-mnemonics", "Gtk/AutoMnemonics", translate_bool_int },
{ INTERFACE_SCHEMA, "gtk-enable-animations", "Gtk/EnableAnimations", translate_bool_int },
{ INTERFACE_SCHEMA, "gtk-dialogs-use-header", "Gtk/DialogsUseHeader", translate_bool_int },
{ SOUND_SCHEMA, "theme-name", "Net/SoundThemeName", translate_string_string },
{ SOUND_SCHEMA, "event-sounds", "Net/EnableEventSounds" , translate_bool_int },
{ SOUND_SCHEMA, "input-feedback-sounds", "Net/EnableInputFeedbackSounds", translate_bool_int }
};
static gboolean start_fontconfig_monitor_idle_cb (ukuiXSettingsManager *manager)
{
manager-> fontconfig_handle = fontconfig_monitor_start ((GFunc) fontconfig_callback, manager);
return FALSE;
}
static void start_fontconfig_monitor (ukuiXSettingsManager *manager)
{
fontconfig_cache_init ();
g_idle_add ((GSourceFunc) start_fontconfig_monitor_idle_cb, manager);
}
static void stop_fontconfig_monitor (ukuiXSettingsManager *manager)
{
if (manager->fontconfig_handle) {
fontconfig_monitor_stop (manager->fontconfig_handle);
manager->fontconfig_handle = NULL;
}
}
static void process_value (ukuiXSettingsManager *manager,
TranslationEntry *trans,
GVariant *value)
{
(* trans->translate) (manager, trans, value);
}
static void terminate_cb (void *data)
{
gboolean *terminated = reinterpret_cast(data);
if (*terminated) {
return;
}
*terminated = TRUE;
USD_LOG(LOG_DEBUG,"terminate self.....");
exit(15);//gtk_main_quit ();
}
void setScreenScale()
{
GSettings *gsettings;
double scale;
gsettings =g_settings_new(XSETTINGS_PLUGIN_SCHEMA);
scale = g_settings_get_double (gsettings, SCALING_FACTOR_KEY);
if(scale > 1.25) {
bool state = false;
for(QScreen *screen : QGuiApplication::screens())
{
if (screen->geometry().width() < 1920 && screen->geometry().height() < 1080){
state = true;
}
else if ((screen->geometry().width() == 1920) &&
(screen->geometry().height() == 1080) &&
(scale > 1.5)) {
state = true;
}
else
state = false;
}
if (state){
GSettings *mGsettings;
mGsettings = g_settings_new(MOUSE_SCHEMA);
g_settings_set_int (mGsettings, CURSOR_SIZE_KEY, 24);
g_settings_set_double (gsettings, SCALING_FACTOR_KEY, 1.0);
g_object_unref(mGsettings);
}
}
g_object_unref(gsettings);
}
ukuiXSettingsManager::ukuiXSettingsManager()
{
gdk_init(NULL,NULL);
pManagers=nullptr;
gsettings=nullptr;
gsettings_font=nullptr;
fontconfig_handle=nullptr;
}
ukuiXSettingsManager::~ukuiXSettingsManager()
{
}
static TranslationEntry *
find_translation_entry (GSettings *gsettings, const char *key)
{
guint i;
char *schema;
g_object_get (gsettings, "schema", &schema, NULL);
for (i = 0; i < G_N_ELEMENTS (translations); i++) {
if (g_str_equal (schema, translations[i].gsettings_schema) &&
g_str_equal (key, translations[i].gsettings_key)) {
g_free (schema);
return &translations[i];
}
}
g_free (schema);
return NULL;
}
static void setKwinMouseSize(int size) {
QString filename = QDir::homePath() + "/.config/kcminputrc";
QSettings *mouseSettings = new QSettings(filename, QSettings::IniFormat);
mouseSettings->beginGroup("Mouse");
mouseSettings->setValue("cursorSize", size);
mouseSettings->endGroup();
mouseSettings->sync();
mouseSettings->deleteLater();
QDBusMessage message =
QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange");
QList args;
args.append(5);//cursor size change signal
args.append(0);//The sceond param unuse..
message.setArguments(args);
QDBusConnection::sessionBus().send(message);
}
static void
xsettings_callback (GSettings *gsettings,
const char *key,
ukuiXSettingsManager *manager)
{
TranslationEntry *trans;
int i;
GVariant *value;
// USD_LOG(LOG_DEBUG,"key:%s",key);
if (g_str_equal (key, CURSOR_THEME_KEY)||
g_str_equal (key, CURSOR_SIZE_KEY )) {
xft_callback (NULL, key, manager);
USD_LOG(LOG_ERR," key=%s",key);
if (g_str_equal (key, CURSOR_SIZE_KEY)) {
setKwinMouseSize(g_settings_get_int (gsettings, key));
USD_LOG_SHOW_PARAM1(g_settings_get_int (gsettings, key));
}
return;
}
trans = find_translation_entry (gsettings, key);
if (trans == NULL) {
USD_LOG(LOG_ERR,"can't find key:%s",key);
return;
}
value = g_settings_get_value (gsettings, key);
process_value (manager, trans, value);
g_variant_unref (value);
for (i = 0; manager->pManagers [i]; i++) {
manager->pManagers [i]->set_string ("Net/FallbackIconTheme",
"ukui");
}
for (i = 0; manager->pManagers [i]; i++) {
manager->pManagers [i]->notify ();
}
}
static gboolean
setup_xsettings_managers (ukuiXSettingsManager *manager)
{
GdkDisplay *display;
gboolean res;
gboolean terminated;
display = gdk_display_get_default ();
res = xsettings_manager_check_running (gdk_x11_display_get_xdisplay (display),0);
if (res) {
g_warning ("You can only run one xsettings manager at a time; exiting");
return FALSE;
}
if(!manager->pManagers)
manager->pManagers = new XsettingsManager*[2];
for(int i=0;manager->pManagers[i];i++)
manager->pManagers [i] = nullptr;
terminated = FALSE;
if(!manager->pManagers [0])
manager->pManagers [0] = new XsettingsManager (gdk_x11_display_get_xdisplay (display),
0,
(XSettingsTerminateFunc)terminate_cb,
&terminated);
if (! manager->pManagers [0]) {
g_warning ("Could not create xsettings manager for screen!");
return FALSE;
}
return TRUE;
}
void update_xft_settings (ukuiXSettingsManager *manager)
{
UkuiXftSettings settings;
settings.xft_settings_get (manager);
settings.xft_settings_set_xsettings (manager);
settings.xft_settings_set_xresources ();
}
static void
xft_callback (GSettings *gsettings,
const gchar *key,
ukuiXSettingsManager *manager)
{
int i;
update_xft_settings (manager);
for (i = 0; manager->pManagers [i]; i++) {
manager->pManagers [i]->notify ();
}
}
static void
fontconfig_callback (fontconfig_monitor_handle_t *handle,
ukuiXSettingsManager *manager)
{
int i;
int timestamp = time (NULL);
for (i = 0; manager-> pManagers [i]; i++) {
manager-> pManagers [i]->set_int ("Fontconfig/Timestamp", timestamp);
manager-> pManagers [i]->notify ();
}
}
void ukuiXSettingsManager::sendSessionDbus()
{
QDBusMessage message = QDBusMessage::createMethodCall("org.gnome.SessionManager",
"/org/gnome/SessionManager",
"org.gnome.SessionManager",
"startupfinished");
QList args;
args.append("ukui-settings-daemon");
args.append("startupfinished");
message.setArguments(args);
QDBusConnection::sessionBus().send(message);
}
bool ukuiXSettingsManager::start()
{
guint i;
GList *list, *l;
if (!setup_xsettings_managers (this)) {
USD_XSETTINGS_ERROR;
return false;
}
gsettings = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, (GDestroyNotify) g_object_unref);
g_hash_table_insert ( gsettings,(void*)MOUSE_SCHEMA,
g_settings_new (MOUSE_SCHEMA));
g_hash_table_insert ( gsettings,(void*)INTERFACE_SCHEMA,
g_settings_new (INTERFACE_SCHEMA));
g_hash_table_insert ( gsettings,(void*)SOUND_SCHEMA,
g_settings_new (SOUND_SCHEMA));
g_hash_table_insert (gsettings,(void*)XSETTINGS_PLUGIN_SCHEMA,
g_settings_new (XSETTINGS_PLUGIN_SCHEMA));
list = g_hash_table_get_values ( gsettings);
for (l = list; l != NULL; l = l->next) {
g_signal_connect (G_OBJECT (l->data), "changed",
G_CALLBACK (xsettings_callback), this);
}
g_list_free (list);
for (i = 0; i < G_N_ELEMENTS (translations); i++) {
GVariant *val;
GSettings *gsettings;
gsettings = (GSettings *)g_hash_table_lookup ( this->gsettings,
translations[i].gsettings_schema);
if (gsettings == NULL) {
USD_LOG(LOG_DEBUG,"Schemas '%s' has not been setup", translations[i].gsettings_schema);
continue;
}
val = g_settings_get_value (gsettings, translations[i].gsettings_key);
process_value (this, &translations[i], val);
g_variant_unref (val);
}
this->gsettings_font = g_settings_new (FONT_RENDER_SCHEMA);
g_signal_connect (this->gsettings_font, "changed", G_CALLBACK (xft_callback), this);
update_xft_settings (this);
start_fontconfig_monitor (this);
sendSessionDbus();
for (i = 0; pManagers [i]; i++){
pManagers [i]->set_string ( "Net/FallbackIconTheme", "ukui");
}
for (i = 0; pManagers [i]; i++) {
pManagers [i]->notify ( );
}
return true;
}
int ukuiXSettingsManager::stop()
{
int i;
if (pManagers != NULL) {
for (i = 0; pManagers [i]; ++i) {
delete (pManagers[i]);
pManagers[i] = NULL;
}
}
if (gsettings != NULL) {
g_hash_table_destroy (gsettings);
gsettings = NULL;
}
if (gsettings_font != NULL) {
g_object_unref (gsettings_font);
gsettings_font = NULL;
}
stop_fontconfig_monitor (this);
return 1;
}
ukui-settings-daemon/plugins/xsettings/ukui-xsettings-plugin.h 0000644 0001750 0001750 00000002530 14205117202 023725 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef XSETTINGS_H
#define XSETTINGS_H
#include "plugin-interface.h"
#include "ukui-xsettings-manager.h"
#include
class XSettingsPlugin: public PluginInterface
{
private:
XSettingsPlugin();
XSettingsPlugin(XSettingsPlugin&) = delete;
public:
~XSettingsPlugin();
static PluginInterface *getInstance();
virtual void activate();
virtual void deactivate();
private:
static ukuiXSettingsManager *m_pukuiXsettingManager;
static PluginInterface *mInstance;
};
extern "C" Q_DECL_EXPORT PluginInterface* createSettingsPlugin();
#endif // XSETTINGS_H
ukui-settings-daemon/plugins/xsettings/ukui-xft-settings.h 0000644 0001750 0001750 00000002561 14205117202 023044 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef UKUIXFTSETTINGS_H
#define UKUIXFTSETTINGS_H
#include
class ukuiXSettingsManager;
class UkuiXftSettings
{
private:
gboolean antialias;
gboolean hinting;
int dpi;
int scaled_dpi;
double window_scale;
char *cursor_theme;
int cursor_size;
const char *rgba;
const char *hintstyle;
public:
void xft_settings_get (ukuiXSettingsManager *manager);
void xft_settings_set_xsettings (ukuiXSettingsManager *manager);
void xft_settings_set_xresources ();
};
#endif // UKUIXFTSETTINGS_H
ukui-settings-daemon/plugins/xsettings/fontconfig-monitor.h 0000644 0001750 0001750 00000002612 14205117202 023250 0 ustar feng feng /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Red Hat, Inc.
*
* 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author: Behdad Esfahbod, Red Hat, Inc.
*/
#ifndef __FONTCONFIG_MONITOR_H
#define __FONTCONFIG_MONITOR_H
#include
#ifdef __cplusplus
extern "C" {
#endif
void fontconfig_cache_init (void);
gboolean fontconfig_cache_update (void);
typedef struct _fontconfig_monitor_handle fontconfig_monitor_handle_t;
fontconfig_monitor_handle_t *
fontconfig_monitor_start (GFunc notify_callback,
gpointer notify_data);
void fontconfig_monitor_stop (fontconfig_monitor_handle_t *handle);
#ifdef __cplusplus
}
#endif
#endif /* __FONTCONFIG_MONITOR_H */
ukui-settings-daemon/plugins/xsettings/xsettings-common.h 0000644 0001750 0001750 00000006611 14205117202 022750 0 ustar feng feng /*
* Copyright © 2001 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Red Hat not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. Red Hat makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL RED HAT
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Owen Taylor, Red Hat, Inc.
*/
#ifndef XSETTINGS_COMMON_H
#define XSETTINGS_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct _XSettingsBuffer XSettingsBuffer;
typedef struct _XSettingsColor XSettingsColor;
typedef struct _XSettingsList XSettingsList;
typedef struct _XSettingsSetting XSettingsSetting;
/* Types of settings possible. Enum values correspond to
* protocol values.
*/
typedef enum
{
XSETTINGS_TYPE_INT = 0,
XSETTINGS_TYPE_STRING = 1,
XSETTINGS_TYPE_COLOR = 2
} XSettingsType;
typedef enum
{
XSETTINGS_SUCCESS,
XSETTINGS_NO_MEM,
XSETTINGS_ACCESS,
XSETTINGS_FAILED,
XSETTINGS_NO_ENTRY,
XSETTINGS_DUPLICATE_ENTRY
} XSettingsResult;
struct _XSettingsBuffer
{
char byte_order;
size_t len;
unsigned char *data;
unsigned char *pos;
};
struct _XSettingsColor
{
unsigned short red, green, blue, alpha;
};
struct _XSettingsList
{
XSettingsSetting *setting;
XSettingsList *next;
};
struct _XSettingsSetting
{
char *name;
XSettingsType type;
union {
int v_int;
char *v_string;
XSettingsColor v_color;
} data;
unsigned long last_change_serial;
};
XSettingsSetting *xsettings_setting_copy (XSettingsSetting *setting);
void xsettings_setting_free (XSettingsSetting *setting);
int xsettings_setting_equal (XSettingsSetting *setting_a,
XSettingsSetting *setting_b);
void xsettings_list_free (XSettingsList *list);
XSettingsList *xsettings_list_copy (XSettingsList *list);
XSettingsResult xsettings_list_insert (XSettingsList **list,
XSettingsSetting *setting);
XSettingsSetting *xsettings_list_lookup (XSettingsList *list,
const char *name);
XSettingsResult xsettings_list_delete (XSettingsList **list,
const char *name);
char xsettings_byte_order (void);
#define XSETTINGS_PAD(n,m) ((n + m - 1) & (~(m-1)))
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* XSETTINGS_COMMON_H */
ukui-settings-daemon/plugins/xsettings/xsettings-manager.h 0000644 0001750 0001750 00000004446 14205117202 023076 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef XSETTINGSMANAGER_H
#define XSETTINGSMANAGER_H
#include
#include "xsettings-common.h"
typedef void (*XSettingsTerminateFunc) (int *cb_data);
#if defined __cplusplus
class XsettingsManager
{
public:
XsettingsManager(Display *display,
int screen,
XSettingsTerminateFunc terminate,
int *cb_data);
~XsettingsManager();
Window get_window ();
Bool process_event (XEvent *xev);
XSettingsResult delete_setting (const char *name);
XSettingsResult set_setting (XSettingsSetting *setting);
XSettingsResult set_int (const char *name,
int value);
XSettingsResult set_string (const char *name,
const char *value);
XSettingsResult set_color (const char *name,
XSettingsColor *value);
void setting_store (XSettingsSetting *setting,
XSettingsBuffer *buffer);
XSettingsResult notify ();
private:
Display *display;
int screen;
Window window;
Atom manager_atom;
Atom selection_atom;
Atom xsettings_atom;
XSettingsTerminateFunc terminate;
void *cb_data;
XSettingsList *settings;
unsigned long serial;
};
#endif
Bool
xsettings_manager_check_running (Display *display,
int screen);
#endif // XSETTINGSMANAGER_H
ukui-settings-daemon/plugins/keybindings/ 0000755 0001750 0001750 00000000000 14205117202 017533 5 ustar feng feng ukui-settings-daemon/plugins/keybindings/keybindings.pro 0000644 0001750 0001750 00000001572 14205117202 022570 0 ustar feng feng #-------------------------------------------------
#
# Project created by QtCreator 2020-05-24T09:30:00
#
#-------------------------------------------------
QT -= gui
QT += core widgets x11extras
TARGET = keybindings
TEMPLATE = lib
DEFINES += KEYBINDINGS_LIBRARY
CONFIG += c++11 no_keywords link_pkgconfig plugin
DEFINES += QT_DEPRECATED_WARNINGS MODULE_NAME=\\\"keybindings\\\"
include($$PWD/../../common/common.pri)
PKGCONFIG += \
gtk+-3.0 \
glib-2.0 \
gobject-2.0 \
gio-2.0 \
cairo \
gsettings-qt\
dconf
SOURCES += \
dconf-util.c \
keybindings-manager.cpp \
keybindings-plugin.cpp
HEADERS += \
dconf-util.h \
keybindings-manager.h \
keybindings-plugin.h
keybindings_lib.path = $${PLUGIN_INSTALL_DIRS}
keybindings_lib.files = $$OUT_PWD/libkeybindings.so
INSTALLS += keybindings_lib
ukui-settings-daemon/plugins/keybindings/keybindings-plugin.cpp 0000644 0001750 0001750 00000003706 14205117202 024047 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "keybindings-plugin.h"
#include "clib-syslog.h"
PluginInterface *KeybindingsPlugin::mInstance=nullptr;
KeybindingsManager *KeybindingsPlugin::mKeyManager=nullptr;
KeybindingsPlugin::KeybindingsPlugin()
{
USD_LOG(LOG_DEBUG,"KeybindingsPlugin initializing");
if(nullptr == mKeyManager)
mKeyManager = KeybindingsManager::KeybindingsManagerNew();
}
KeybindingsPlugin::~KeybindingsPlugin()
{
USD_LOG(LOG_DEBUG,"KeybindingsPlugin free");
if(mKeyManager){
delete mKeyManager;
mKeyManager = nullptr;
}
}
void KeybindingsPlugin::activate()
{
bool res;
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
res = mKeyManager->KeybindingsManagerStart();
if(!res)
USD_LOG(LOG_ERR,"Unable to start Keybindings manager");
}
PluginInterface *KeybindingsPlugin::getInstance()
{
if(nullptr == mInstance)
mInstance = new KeybindingsPlugin();
return mInstance;
}
void KeybindingsPlugin::deactivate()
{
USD_LOG(LOG_DEBUG,"Dectivating Keybindings Plugin");
mKeyManager->KeybindingsManagerStop();
}
PluginInterface *createSettingsPlugin()
{
return KeybindingsPlugin::getInstance();
}
ukui-settings-daemon/plugins/keybindings/dconf-util.h 0000755 0001750 0001750 00000002640 14205117202 021755 0 ustar feng feng /*
* dconf-util.h: helper API for dconf
*
* Copyright (C) 2012 Stefano Karapetsas
*
* 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.
*
* Authors:
* Stefano Karapetsas
* Vincent Untz
*/
#ifndef __DCONF_UTIL_H__
#define __DCONF_UTIL_H__
#include
G_BEGIN_DECLS
gboolean dconf_util_write_sync (const gchar *key,
GVariant *value,
GError **error);
gboolean dconf_util_recursive_reset (const gchar *dir,
GError **error);
gchar **dconf_util_list_subdirs (const gchar *dir,
gboolean remove_trailing_slash);
G_END_DECLS
#endif /* __DCONF_UTIL_H__ */
ukui-settings-daemon/plugins/keybindings/keybindings-manager.h 0000644 0001750 0001750 00000006007 14205117202 023625 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef KEYBINDINGSMANAGER_H
#define KEYBINDINGSMANAGER_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
extern "C"{
#include "ukui-keygrab.h"
#include "eggaccelerators.h"
#include "dconf-util.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
}
typedef struct {
char *binding_str;
char *action;
char *settings_path;
Key key;
Key previous_key;
} Binding;
class KeybindingsManager : public QObject
{
Q_OBJECT
private:
KeybindingsManager();
KeybindingsManager(KeybindingsManager&)=delete;
public:
~KeybindingsManager();
static KeybindingsManager *KeybindingsManagerNew();
bool KeybindingsManagerStart();
void KeybindingsManagerStop();
void get_screens_list();
public:
static void bindings_callback (DConfClient *client,
gchar *prefix,
const gchar **changes,
gchar *tag,
KeybindingsManager *manager);
static bool key_already_used (KeybindingsManager *manager,Binding *binding);
static void binding_register_keys (KeybindingsManager *manager);
static void binding_unregister_keys (KeybindingsManager *manager);
static void bindings_clear(KeybindingsManager *manager);
static void bindings_get_entries(KeybindingsManager *manager);
static bool bindings_get_entry (KeybindingsManager *manager,const char *settings_path);
friend GdkFilterReturn keybindings_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
KeybindingsManager *manager);
private:
static KeybindingsManager *mKeybinding;
DConfClient *client;
GSList *binding_list;
QList *screens;
QGSettings *dconfSet;
GMainLoop *loop;
};
#endif // KEYBINDINGSMANAGER_H
ukui-settings-daemon/plugins/keybindings/keybindings-plugin.h 0000644 0001750 0001750 00000002515 14205117202 023511 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef KEYBINDINGSPLUGIN_H
#define KEYBINDINGSPLUGIN_H
#include "keybindings-manager.h"
#include "plugin-interface.h"
class KeybindingsPlugin : public PluginInterface
{
public:
~KeybindingsPlugin();
static PluginInterface *getInstance();
virtual void activate();
virtual void deactivate();
private:
KeybindingsPlugin();
KeybindingsPlugin(KeybindingsPlugin&)=delete;
private:
static KeybindingsManager *mKeyManager;
static PluginInterface *mInstance;
};
extern "C" Q_DECL_EXPORT PluginInterface * createSettingsPlugin();
#endif // KEYBINDINGSPLUGIN_H
ukui-settings-daemon/plugins/keybindings/dconf-util.c 0000755 0001750 0001750 00000004757 14205117202 021763 0 ustar feng feng /*
* dconf-util.c: helper API for dconf
*
* Copyright (C) 2012 Stefano Karapetsas
*
* 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.
*
* Authors:
* Stefano Karapetsas
* Vincent Untz
*/
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include "dconf-util.h"
static DConfClient *
dconf_util_client_get (void)
{
return dconf_client_new ();
}
gboolean
dconf_util_write_sync (const gchar *key,
GVariant *value,
GError **error)
{
gboolean ret;
DConfClient *client = dconf_util_client_get ();
ret = dconf_client_write_sync (client, key, value, NULL, NULL, error);
g_object_unref (client);
return ret;
}
gboolean
dconf_util_recursive_reset (const gchar *dir,
GError **error)
{
gboolean ret;
DConfClient *client = dconf_util_client_get ();
ret = dconf_client_write_sync (client, dir, NULL, NULL, NULL, error);
g_object_unref (client);
return ret;
}
gchar **
dconf_util_list_subdirs (const gchar *dir,
gboolean remove_trailing_slash)
{
GArray *array;
gchar **children;
int len;
int i;
DConfClient *client = dconf_util_client_get ();
array = g_array_new (TRUE, TRUE, sizeof (gchar *));
children = dconf_client_list (client, dir, &len);
g_object_unref (client);
for (i = 0; children[i] != NULL; i++) {
if (dconf_is_rel_dir (children[i], NULL)) {
char *val = g_strdup (children[i]);
if (remove_trailing_slash)
val[strlen (val) - 1] = '\0';
array = g_array_append_val (array, val);
}
}
g_strfreev (children);
return (gchar **) g_array_free (array, FALSE);
}
ukui-settings-daemon/plugins/keybindings/keybindings-manager.cpp 0000644 0001750 0001750 00000044117 14205117202 024164 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include "keybindings-manager.h"
#include "config.h"
#include "clib-syslog.h"
#include
#include
#include
#define DESKTOP_APP_DIR "/usr/share/applications/"
//#define GSETTINGS_KEYBINDINGS_DIR "/org/ukui/desktop/session/"
#define GSETTINGS_KEYBINDINGS_DIR "/org/ukui/desktop/keybindings/"
#define CUSTOM_KEYBINDING_SCHEMA "org.ukui.control-center.keybinding"
KeybindingsManager *KeybindingsManager::mKeybinding = nullptr;
KeybindingsManager::KeybindingsManager()
{
}
KeybindingsManager::~KeybindingsManager()
{
}
KeybindingsManager *KeybindingsManager::KeybindingsManagerNew()
{
if(nullptr == mKeybinding)
mKeybinding = new KeybindingsManager();
return mKeybinding;
}
/**
* @brief parse_binding
* Whether the binding exists
* 获取此绑定的条目
* @return
*/
static bool
parse_binding (Binding *binding)
{
gboolean success;
if(!binding)
return false;
binding->key.keysym = 0;
binding->key.state = 0;
g_free (binding->key.keycodes);
binding->key.keycodes = NULL;
if (binding->binding_str == NULL ||
binding->binding_str[0] == '\0' ||
g_strcmp0 (binding->binding_str, "Disabled") == 0 ||
g_strcmp0 (binding->binding_str, "disabled") == 0 ) {
return false;
}
success = egg_accelerator_parse_virtual (binding->binding_str,
&binding->key.keysym,
&binding->key.keycodes,
(EggVirtualModifierType *)&binding->key.state);
if (!success)
USD_LOG(LOG_DEBUG,"Key binding (%s) is invalid", binding->settings_path);
return success;
}
static gint
compare_bindings (gconstpointer a,
gconstpointer b)
{
Binding *key_a = (Binding *) a;
char *key_b = (char *) b;
return g_strcmp0 (key_b, key_a->settings_path);
}
/**
* @brief KeybindingsManager::bindings_get_entry
* Gets binding shortcut data
* 获取绑定快捷键数据
* @return
*/
bool KeybindingsManager::bindings_get_entry (KeybindingsManager *manager,const char *settings_path)
{
GSettings *settings;
Binding *new_binding;
GSList *tmp_elem;
char *action = nullptr;
char *key = nullptr;
if (!settings_path) {
return false;
}
/* Get entries for this binding
* 获取此绑定的条目
*/
settings = g_settings_new_with_path (CUSTOM_KEYBINDING_SCHEMA, settings_path);
action = g_settings_get_string (settings, "action");
key = g_settings_get_string (settings, "binding");
g_object_unref (settings);
if (action==nullptr || key==nullptr)
{
USD_LOG(LOG_DEBUG,"Key binding (%s) is incomplete", settings_path);
return false;
}
tmp_elem = g_slist_find_custom (manager->binding_list,
settings_path,
compare_bindings);
if (!tmp_elem) {
new_binding = g_new0 (Binding, 1);
} else {
new_binding = (Binding *) tmp_elem->data;
g_free (new_binding->binding_str);
g_free (new_binding->action);
g_free (new_binding->settings_path);
new_binding->previous_key.keysym = new_binding->key.keysym;
new_binding->previous_key.state = new_binding->key.state;
new_binding->previous_key.keycodes = new_binding->key.keycodes;
new_binding->key.keycodes = NULL;
}
new_binding->binding_str = key;
new_binding->action = action;
new_binding->settings_path = g_strdup (settings_path);
if (parse_binding (new_binding)) {
if (!tmp_elem)
manager->binding_list = g_slist_prepend (manager->binding_list, new_binding);
} else {
g_free (new_binding->binding_str);
g_free (new_binding->action);
g_free (new_binding->settings_path);
g_free (new_binding->previous_key.keycodes);
g_free (new_binding);
if (tmp_elem)
manager->binding_list = g_slist_delete_link (manager->binding_list, tmp_elem);
return false;
}
return true;
}
/**
* @brief KeybindingsManager::bindings_clear
* Clear binding cache
* 清除绑定缓存
*/
void KeybindingsManager::bindings_clear (KeybindingsManager *manager)
{
GSList *l;
if (manager->binding_list != NULL)
{
for (l = manager->binding_list; l; l = l->next) {
Binding *b = (Binding *)l->data;
g_free (b->binding_str);
g_free (b->action);
g_free (b->settings_path);
g_free (b->previous_key.keycodes);
g_free (b->key.keycodes);
g_free (b);
}
g_slist_free (manager->binding_list);
manager->binding_list = NULL;
}
}
void KeybindingsManager::bindings_get_entries (KeybindingsManager *manager)
{
gchar **custom_list = NULL;
gint i;
bindings_clear(manager);
custom_list = dconf_util_list_subdirs (GSETTINGS_KEYBINDINGS_DIR, FALSE);
if (custom_list != NULL)
{
for (i = 0; custom_list[i] != NULL; i++)
{
gchar *settings_path;
settings_path = g_strdup_printf("%s%s", GSETTINGS_KEYBINDINGS_DIR, custom_list[i]);
bindings_get_entry (manager,settings_path);
g_free (settings_path);
}
g_strfreev (custom_list);
}
}
/**
* @brief same_keycode
* Is it the same key code
* 是否为相同的键码
* @return
*/
static bool
same_keycode (const Key *key, const Key *other)
{
if (key->keycodes != NULL && other->keycodes != NULL) {
unsigned int *c;
for (c = key->keycodes; *c; ++c) {
if (key_uses_keycode (other, *c))
return true;
}
}
return false;
}
/**
* @brief same_key
* Compare whether the keys are shortcuts
* 对比按键是否为快捷键
* @return
*/
static bool same_key (const Key *key, const Key *other)
{
if (key->state == other->state) {
if (key->keycodes != NULL && other->keycodes != NULL) {
unsigned int *c1, *c2;
for (c1 = key->keycodes, c2 = other->keycodes;
*c1 || *c2; ++c1, ++c2) {
if (*c1 != *c2)
return false;
}
} else if (key->keycodes != NULL || other->keycodes != NULL)
return false;
return true;
}
return false;
}
/**
* @brief KeybindingsManager::key_already_used
* @English Compare the shortcuts already used
* @简体 已经使用的快捷键 进行比对
* @return
*/
bool KeybindingsManager::key_already_used (KeybindingsManager*manager,Binding *binding)
{
GSList *li;
for (li = manager->binding_list; li != NULL; li = li->next) {
Binding *tmp_binding = (Binding*) li->data;
if (tmp_binding != binding &&
same_keycode (&tmp_binding->key, &binding->key) &&
tmp_binding->key.state == binding->key.state) {
return true;
}
}
return false;
}
/**
* @brief KeybindingsManager::binding_unregister_keys
* Unbind key
* 注销绑定按键
*/
void KeybindingsManager::binding_unregister_keys (KeybindingsManager *manager)
{
GSList *li;
bool need_flush = FALSE;
USD_LOG(LOG_DEBUG,"run here...");
gdk_x11_display_error_trap_push (gdk_display_get_default());
try {
for (li = manager->binding_list; li != NULL; li = li->next) {
Binding *binding = (Binding *) li->data;
USD_LOG(LOG_DEBUG,"run here...");
if (binding->key.keycodes) {
need_flush = TRUE;
grab_key_unsafe (&binding->key, FALSE, manager->screens);
}
}
if (need_flush)
gdk_display_flush(gdk_display_get_default());
} catch (...) {
}
gdk_x11_display_error_trap_pop_ignored(gdk_display_get_default());
}
/**
* @brief KeybindingsManager::binding_register_keys
* Bind register key
* 绑定寄存器按键
*/
void KeybindingsManager::binding_register_keys (KeybindingsManager *manager)
{
GSList *li;
bool need_flush = false;
gdk_x11_display_error_trap_push (gdk_display_get_default());
/* Now check for changes and grab new key if not already used
* 现在检查更改并获取新密钥(如果尚未使用)
*/
for (li = manager->binding_list; li != NULL; li = li->next) {
Binding *binding = (Binding *) li->data;
if (!same_key (&binding->previous_key, &binding->key)) {
/* Ungrab key if it changed and not clashing with previously set binding */
if (!key_already_used (manager,binding)) {
gint i;
need_flush = true;
if (binding->previous_key.keycodes) {
grab_key_unsafe (&binding->previous_key, FALSE, manager->screens);
}
grab_key_unsafe (&binding->key, TRUE, manager->screens);
binding->previous_key.keysym = binding->key.keysym;
binding->previous_key.state = binding->key.state;
g_free (binding->previous_key.keycodes);
for (i = 0; binding->key.keycodes&&binding->key.keycodes[i]; ++i);
binding->previous_key.keycodes = g_new0 (guint, i);
for (i = 0; binding->key.keycodes&&binding->key.keycodes[i]; ++i)
binding->previous_key.keycodes[i] = binding->key.keycodes[i];
} else
USD_LOG(LOG_DEBUG,"Key binding (%s) is already in use", binding->binding_str);
}
}
if (need_flush)
gdk_display_flush (gdk_display_get_default());
if(gdk_x11_display_error_trap_pop (gdk_display_get_default()))
USD_LOG(LOG_DEBUG,"Grab failed for some keys, another application may already have access the them.");
}
/**
* @brief keybindings_filter 键盘事件回调函数
* @param gdk_xevent GDK XEvent事件
* @param event GDK Event事件
* @param manager 类
* @return 未处理事件,请继续处理
*/
GdkFilterReturn
keybindings_filter (GdkXEvent *gdk_xevent,
GdkEvent *event,
KeybindingsManager *manager)
{
XEvent *xevent = (XEvent *) gdk_xevent;
GSList *li;
// USD_LOG(LOG_DEBUG,"had event :%d",xevent->type);
if (xevent->type != KeyPress) {
return GDK_FILTER_CONTINUE;
}
for (li = manager->binding_list; li != NULL; li = li->next) {
Binding *binding = (Binding *) li->data;
if (match_key (&binding->key, xevent)) {
GError *error = NULL;
gboolean retval;
gchar **argv = NULL;
if (binding->action == NULL)
return GDK_FILTER_CONTINUE;
if (!g_shell_parse_argv (binding->action,
NULL, &argv,
&error)) {
return GDK_FILTER_CONTINUE;
}
GDesktopAppInfo *info = g_desktop_app_info_new_from_filename(binding->action);
retval = g_app_info_launch_uris((GAppInfo *)info, NULL, NULL, NULL);
g_strfreev (argv);
/* Run failed popup
* 运行失败弹窗 */
if (!retval) {
QString strs = QObject::tr("Error while trying to run \"%1\";\n which is linked to the key \"%2\"").
arg(binding->action).arg(binding->binding_str);
QMessageBox *msgbox = new QMessageBox();
msgbox->setWindowTitle(QObject::tr("Shortcut message box"));
msgbox->setText(strs);
msgbox->setStandardButtons(QMessageBox::Yes);
msgbox->setButtonText(QMessageBox::Yes,QObject::tr("Yes"));
msgbox->exec();
delete msgbox;
}
return GDK_FILTER_REMOVE;
}
}
return GDK_FILTER_CONTINUE;
}
static void
show_path (DConfClient *client, const gchar *path)
{
if (dconf_is_key (path, NULL))
{
g_autoptr(GVariant) value = NULL;
g_autofree gchar *value_str = NULL;
value = dconf_client_read (client, path);
if (value != NULL)
value_str = g_variant_print (value, TRUE);
USD_LOG(LOG_DEBUG," %s\n", value_str != NULL ? value_str : "unset");
}
}
/**
* @brief KeybindingsManager::bindings_callback dconf监听快捷键改变回调函数
* @param client
* @param prefix
* @param changes
* @param tag
* @param manager 类
*/
void KeybindingsManager::bindings_callback (DConfClient *client,
gchar *prefix,
const gchar **changes,
gchar *tag,
KeybindingsManager *manager)
{
Q_UNUSED(client);
Q_UNUSED(changes);
if (strncmp(GSETTINGS_KEYBINDINGS_DIR,prefix,strlen(GSETTINGS_KEYBINDINGS_DIR))) {
return;
}
USD_LOG(LOG_DEBUG,"keybindings: received 'changed' signal from dconf. gchar:%s changes:%s tag:%s ",prefix, changes[0], tag);
for (const gchar **item = changes; *changes; ++changes)
{
g_autofree gchar *full = NULL;
full = g_strconcat (prefix, *item, NULL);
USD_LOG (LOG_DEBUG,"prefix%s full%s\n", prefix, full);
show_path (client, full);
}
binding_unregister_keys (manager);
bindings_get_entries (manager);
binding_register_keys (manager);
}
/**
* @brief get_screens_list 获取gdkscreen屏幕并存放链表
* @return 返回列表
*/
void KeybindingsManager::get_screens_list (void)
{
GdkScreen *screen = gdk_screen_get_default ();
screens->append(screen);
}
bool KeybindingsManager::KeybindingsManagerStart()
{
USD_LOG(LOG_DEBUG,"-- Keybindings Manager Start --");
QList::iterator l, begin, end;
GdkDisplay *dpy;
GdkScreen *screen;
GdkWindow *window;
Display *xdpy;
Window xwindow;
XWindowAttributes atts;
gdk_init(NULL,NULL);
dpy = gdk_display_get_default ();
// xdpy = GDK_DISPLAY_XDISPLAY (dpy);
xdpy = QX11Info::display();
screen = gdk_display_get_default_screen(dpy);
window = gdk_screen_get_root_window (screen);
xwindow = GDK_WINDOW_XID (window);
/* Monitor keyboard events
* 监听键盘事件
*/
gdk_window_add_filter (window,
(GdkFilterFunc) keybindings_filter,
this);
try {
/* Add KeyPressMask to the currently reportable event masks
* 将KeyPressMask添加到当前可报告的事件掩码
*/
gdk_x11_display_error_trap_push (gdk_display_get_default());
XGetWindowAttributes (xdpy, xwindow, &atts);
XSelectInput (xdpy, xwindow, atts.your_event_mask | KeyPressMask);
gdk_x11_display_error_trap_pop_ignored(gdk_display_get_default());
} catch (int) {
USD_LOG(LOG_DEBUG,"had a error in here...");
}
screens = new QList();
get_screens_list ();
binding_list = NULL;
bindings_get_entries (this);
binding_register_keys(this);
/* Link to dconf, receive a shortcut key change signal from dconf
* 链接dconf, 从dconf收到更改快捷键信号
*/
{
char ** childs;
int len;
QList vals;
client = dconf_client_new ();
dconf_client_watch_fast (client, GSETTINGS_KEYBINDINGS_DIR);
dconf_client_watch_sync (client, GSETTINGS_KEYBINDINGS_DIR);
g_signal_connect (client, "changed", G_CALLBACK (bindings_callback), this);
#if 0 //无效,无法使用gsetings的方法监控dconf
childs = dconf_client_list (client, GSETTINGS_KEYBINDINGS_DIR, &len);
for (int i = 0; childs[i] != NULL; i++){
USD_LOG(LOG_DEBUG,"val:%s",childs[i]);
if (dconf_is_rel_dir (childs[i], NULL))
{
USD_LOG(LOG_DEBUG,"val:");
char * val = g_strdup (childs[i]);
vals.append(val);
USD_LOG(LOG_DEBUG,"val:%s",val);
}
}
USD_LOG(LOG_DEBUG,"len:%d",len);
for (char * path : vals){
USD_LOG(LOG_DEBUG,"val:%s",path);
char tempbuf[128]="";
memcpy(tempbuf, GSETTINGS_KEYBINDINGS_DIR, strlen(GSETTINGS_KEYBINDINGS_DIR));
strcat(tempbuf, path);
USD_LOG(LOG_DEBUG,"path:%s, tempbuf%s",path, tempbuf);
const QByteArray ba(GSETTINGS_KEYBINDINGS_DIR,strlen(GSETTINGS_KEYBINDINGS_DIR));
const QByteArray bba(tempbuf,strlen(tempbuf));
USD_LOG(LOG_DEBUG,"ba[%s] bba[%s]",ba.data(),bba.data());
QGSettings * settings = new QGSettings(ba, bba);
connect(settings, &QGSettings::changed, this, [=] (const QString &key){
USD_LOG(LOG_DEBUG,"key=%s",key.toLatin1().data());
});
}
#endif
}
return true;
}
void KeybindingsManager::KeybindingsManagerStop()
{
USD_LOG(LOG_DEBUG,"Stopping keybindings manager");
if (client != NULL) {
g_object_unref (client);
client = NULL;
}
QList::iterator l,end;
l = screens->begin();
GdkScreen *screen = *l;
gdk_window_remove_filter (gdk_screen_get_root_window (screen),
(GdkFilterFunc) keybindings_filter,
this);
binding_unregister_keys (this);
bindings_clear (this);
screens->clear();
delete screens;
screens = NULL;
}
ukui-settings-daemon/plugins/authority/ 0000755 0001750 0001750 00000000000 14205117202 017255 5 ustar feng feng ukui-settings-daemon/plugins/authority/authorityservice.h 0000644 0001750 0001750 00000002546 14205117202 023046 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef AUTHORITYSERVICE_H
#define AUTHORITYSERVICE_H
#include
#include
#include
#include
class AuthorityService : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.ukui.authority.interface")
public:
explicit AuthorityService(QObject *parent = nullptr);
~AuthorityService(){}
public slots:
Q_SCRIPTABLE QString getCameraBusinfo();
Q_SCRIPTABLE int getCameraDeviceEnable();
Q_SCRIPTABLE QString toggleCameraDevice(QString businfo);
Q_SCRIPTABLE int setCameraKeyboardLight(bool lightup);
signals:
};
#endif // AUTHORITYSERVICE_H
ukui-settings-daemon/plugins/authority/authorityservice.cpp 0000644 0001750 0001750 00000010336 14205117202 023375 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "authorityservice.h"
extern "C" {
#include
#include
#include
}
AuthorityService::AuthorityService(QObject *parent) : QObject(parent)
{
}
QString AuthorityService::getCameraBusinfo()
{
QString path = QString("/sys/bus/usb/devices/");
QDir dir(path);
if (!dir.exists()){
return QString();
}
dir.setFilter(QDir::Dirs);
dir.setSorting(QDir::Name);
QFileInfoList fileinfoList = dir.entryInfoList();
for(QFileInfo fileinfo : fileinfoList){
if (fileinfo.fileName() == "." || fileinfo.fileName() == ".."){
continue;
}
if (fileinfo.fileName().contains(":")){
continue;
}
if (fileinfo.fileName().startsWith("usb")){
continue;
}
QDir subdir(fileinfo.absoluteFilePath());
subdir.setFilter(QDir::Files);
QFileInfoList fileinfoList2 = subdir.entryInfoList();
for (QFileInfo fileinfo2 : fileinfoList2){
if (fileinfo2.fileName() == "product"){
QFile pfile(fileinfo2.absoluteFilePath());
if (!pfile.open(QIODevice::ReadOnly | QIODevice::Text))
return QString();
QTextStream pstream(&pfile);
QString output = pstream.readAll();
if (output.contains("camera", Qt::CaseInsensitive)){
return fileinfo.fileName();
}
}
}
}
return QString();
}
int AuthorityService::getCameraDeviceEnable()
{
QString businfo = getCameraBusinfo();
if (businfo.isEmpty()){
const char cmd[] = "lsusb -t | grep 'Driver=uvcvideo'";
char output[1024] = "\0";
FILE * stream;
if ((stream = popen(cmd, "r")) == NULL){
return -1;
}
int ret;
if (fread(output, sizeof(char), 1024, stream) <= 0){
ret = 0;
} else {
ret = 1;
}
fclose(stream);
return ret;
}
int isExists = 0;
QString path = QString("/sys/bus/usb/drivers/usb/");
QDir dir(path);
if (!dir.exists()){
return -1;
}
dir.setFilter(QDir::Dirs);
dir.setSorting(QDir::Name);
QFileInfoList fileinfoList = dir.entryInfoList();
for(QFileInfo fileinfo : fileinfoList){
if (fileinfo.fileName() == "." || fileinfo.fileName() == ".."){
continue;
}
if (fileinfo.fileName().contains(":")){
continue;
}
if (fileinfo.fileName() == businfo){
isExists = 1;
}
}
return isExists;
}
QString AuthorityService::toggleCameraDevice(QString businfo)
{
QString path = QString("/sys/bus/usb/drivers/usb/");
int status = getCameraDeviceEnable();
if (status == -1){
return QString("Camera Device Not Exists!");
}
if (status){
QString cmd = QString("echo '%1' > %2/unbind").arg(businfo).arg(path);
system(cmd.toLatin1().data());
return QString("unbinded");
} else {
QString cmd = QString("echo '%1' > %2/bind").arg(businfo).arg(path);
system(cmd.toLatin1().data());
return QString("binded");
}
}
int AuthorityService::setCameraKeyboardLight(bool lightup)
{
const char target[] = "/sys/class/leds/platform::cameramute/brightness";
if (access(target, F_OK) == -1){
return -1;
}
int value = lightup ? 1 : 0;
char cmd[256];
sprintf(cmd, "echo %d > %s", value, target);
system(cmd);
return 1;
}
ukui-settings-daemon/plugins/authority/conf/ 0000755 0001750 0001750 00000000000 14205117202 020202 5 ustar feng feng ukui-settings-daemon/plugins/authority/conf/org.ukui.authority.conf 0000644 0001750 0001750 00000001561 14205117202 024646 0 ustar feng feng
ukui-settings-daemon/plugins/authority/conf/org.ukui.authority.service 0000644 0001750 0001750 00000000116 14205117202 025354 0 ustar feng feng [D-BUS Service]
Name=org.ukui.authority
Exec=/usr/bin/authoritydbus
User=root
ukui-settings-daemon/plugins/authority/authority.pro 0000644 0001750 0001750 00000002467 14205117202 022040 0 ustar feng feng QT -= gui
QT += core dbus
CONFIG += c++11 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
TEMPLATE = app
TARGET = authoritydbus
DESTDIR = .
target.source += $$TARGET
target.path = /usr/bin
service.files += conf/org.ukui.authority.service
service.path = /usr/share/dbus-1/system-services/
conffile.files += conf/org.ukui.authority.conf
conffile.path = /etc/dbus-1/system.d/
INSTALLS += \
target \
service \
conffile
SOURCES += \
authorityservice.cpp \
main.cpp
# Default rules for deployment.
#qnx: target.path = /tmp/$${TARGET}/bin
#else: unix:!android: target.path = /opt/$${TARGET}/bin
#!isEmpty(target.path): INSTALLS += target
HEADERS += \
authorityservice.h
ukui-settings-daemon/plugins/authority/main.cpp 0000644 0001750 0001750 00000002512 14205117202 020705 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include
#include
#include
#include "authorityservice.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setOrganizationName("Kylin Team");
QDBusConnection systemBus = QDBusConnection::systemBus();
if (systemBus.registerService("org.ukui.authority")){
systemBus.registerObject("/", new AuthorityService(),
QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals
);
}
return a.exec();
}
ukui-settings-daemon/plugins/auto-brightness/ 0000755 0001750 0001750 00000000000 14205117202 020343 5 ustar feng feng ukui-settings-daemon/plugins/auto-brightness/auto-brightness.pro 0000644 0001750 0001750 00000001355 14205117202 024207 0 ustar feng feng QT += gui widgets x11extras dbus sensors KConfigCore KConfigGui
TEMPLATE = lib
CONFIG += c++11 plugin link_pkgconfig
DEFINES += TABLETMODE_LIBRARY QT_DEPRECATED_WARNINGS MODULE_NAME=\\\"backGround\\\"
include($$PWD/../../common/common.pri)
INCLUDEPATH += \
-I $$PWD/../../common/ \
-I ukui-settings-daemon/ \
PKGCONFIG += \
xrandr x11 \
glib-2.0
SOURCES += \
autoBrightness-manager.cpp \
autoBrightness-plugin.cpp \
brightThread.cpp
HEADERS += \
autoBrightness-manager.h \
autoBrightness-plugin.h \
brightThread.h
auto_brightness_lib.path = $${PLUGIN_INSTALL_DIRS}
auto_brightness_lib.files = $$OUT_PWD/libauto-brightness.so
INSTALLS += auto_brightness_lib
ukui-settings-daemon/plugins/auto-brightness/brightThread.h 0000644 0001750 0001750 00000002403 14205117202 023122 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef BRIGHTTHREAD_H
#define BRIGHTTHREAD_H
#include
#include
class QGSettings;
class BrightThread : public QThread
{
Q_OBJECT
public:
BrightThread(QObject *parent = nullptr, double bright = 100.0);
// BrightThread(QObject *parent = nullptr);
~BrightThread();
void stopImmediately();
protected:
void run();
private:
double brightness;
double currentBrightness;
QGSettings *mpowerSettings;
bool m_isCanRun;
QMutex m_lock;
};
#endif // BRIGHTTHREAD_H
ukui-settings-daemon/plugins/auto-brightness/autoBrightness-plugin.h 0000644 0001750 0001750 00000002642 14205117202 025015 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef AUTOBRIGHTNESSPLUGIN_H
#define AUTOBRIGHTNESSPLUGIN_H
#include
#include "plugin-interface.h"
#include "autoBrightness-manager.h"
#include "clib-syslog.h"
class AutoBrightnessPlugin : public PluginInterface
{
private:
AutoBrightnessPlugin();
AutoBrightnessPlugin(AutoBrightnessPlugin&)=delete;
public:
~AutoBrightnessPlugin();
static PluginInterface *getInstance();
virtual void activate();
virtual void deactivate();
private:
static AutoBrightnessManager *mAutoBrightnessManager;
static PluginInterface *mInstance;
};
extern "C" Q_DECL_EXPORT PluginInterface *createSettingsPlugin();
#endif // AUTOBRIGHTNESSPLUGIN_H
ukui-settings-daemon/plugins/auto-brightness/autoBrightness-manager.cpp 0000644 0001750 0001750 00000011351 14205117202 025461 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include
#include
#include
#include "autoBrightness-manager.h"
extern "C"{
#include
#include
}
#define SETTINGS_AUTO_BRIGHTNESS_SCHEMAS "org.ukui.SettingsDaemon.plugins.auto-brightness"
#define AUTO_BRIGHTNESS_KEY "auto-brightness"
AutoBrightnessManager *AutoBrightnessManager::mAutoBrightnessManager = nullptr;
AutoBrightnessManager::AutoBrightnessManager() :
mEnabled(false)
, m_currentRunLocalThread(NULL)
, mPreLux(10.f)
{
mSensor = new QLightSensor(this);
mAutoBrightnessSettings = new QGSettings(SETTINGS_AUTO_BRIGHTNESS_SCHEMAS);
}
AutoBrightnessManager::~AutoBrightnessManager()
{
if(mAutoBrightnessManager)
delete mAutoBrightnessManager;
if(mSensor)
delete mSensor;
if(mAutoBrightnessSettings)
delete mAutoBrightnessSettings;
if(m_currentRunLocalThread)
{
m_currentRunLocalThread->stopImmediately();
m_currentRunLocalThread = NULL;
}
}
AutoBrightnessManager *AutoBrightnessManager::AutoBrightnessManagerNew()
{
if(nullptr == mAutoBrightnessManager)
mAutoBrightnessManager = new AutoBrightnessManager();
return mAutoBrightnessManager;
}
void AutoBrightnessManager::onLocalThreadDestroy(QObject* obj){
if(qobject_cast(m_currentRunLocalThread) == obj)
m_currentRunLocalThread = NULL;
}
void AutoBrightnessManager::AutoBrightnessUpdateState()
{
QLightReading * lightReading = mSensor->reading();
qreal lux = lightReading->lux();//获得具体光强
if(qAbs(lux - mPreLux) <= 4.0) // 如果传感器检测到的Lux值和上次值小于4.0Lux,则不进行亮度调整
return;
mPreLux = lux;
if(m_currentRunLocalThread) // 如果已经存在了一个线程在调节亮度值,就终止该线程
{
qDebug() << "已经有线程在运行";
m_currentRunLocalThread->stopImmediately();
m_currentRunLocalThread = NULL;
}
double brightness_ac = 0;
if(lux > 41.0){
brightness_ac = 100.0;
}
else{
brightness_ac = pow(lux, 1.2) + 13;
brightness_ac = round(brightness_ac);
}
BrightThread* thread = new BrightThread(NULL, brightness_ac);
connect(thread, &QThread::finished, thread, &QObject::deleteLater); // 线程结束后调用deleteLater来销毁分配的内存
connect(thread, &QObject::destroyed, this, &AutoBrightnessManager::onLocalThreadDestroy);
thread->start();
m_currentRunLocalThread = thread;
}
void AutoBrightnessManager::AutoBrightnessRefresh()
{
if(mSensor->isActive()){
AutoBrightnessUpdateState();
} else {
}
}
void AutoBrightnessManager::SetEnabled(bool enabled)
{
if(mEnabled == enabled)
return;
mEnabled = enabled;
if (mEnabled) {
mSensor->start();
AutoBrightnessRefresh();
} else {
if(m_currentRunLocalThread)
{
m_currentRunLocalThread->stopImmediately();
m_currentRunLocalThread = NULL;
}
mSensor->stop();
mPreLux = -4.f;
}
}
void AutoBrightnessManager::AutoBrightnessSettingsChanged(QString key)
{
bool autobright;
autobright = mAutoBrightnessSettings->get(AUTO_BRIGHTNESS_KEY).toBool();
if (key == AUTO_BRIGHTNESS_KEY) {
SetEnabled(autobright);
}
}
bool AutoBrightnessManager::AutoBrightnessManagerStart()
{
qDebug("AutoBrightnessManager Start");
bool autobright;
autobright = mAutoBrightnessSettings->get(AUTO_BRIGHTNESS_KEY).toBool();
connect(mSensor,SIGNAL(readingChanged()),this,SLOT(AutoBrightnessUpdateState()));
connect(mSensor,SIGNAL(activeChanged()),this,SLOT(AutoBrightnessRefresh()));
connect(mAutoBrightnessSettings,SIGNAL(changed(QString)),this,SLOT(AutoBrightnessSettingsChanged(QString)));
SetEnabled(autobright);
return true;
}
void AutoBrightnessManager::AutoBrightnessManagerStop()
{
SetEnabled(false);
qDebug("AutoBrightness Manager stop");
}
ukui-settings-daemon/plugins/auto-brightness/autoBrightness-plugin.cpp 0000644 0001750 0001750 00000003721 14205117202 025347 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "autoBrightness-plugin.h"
PluginInterface *AutoBrightnessPlugin::mInstance = nullptr;
AutoBrightnessManager *AutoBrightnessPlugin::mAutoBrightnessManager = nullptr;
AutoBrightnessPlugin::AutoBrightnessPlugin()
{
qDebug("AutoBrightness Plugin initializing");
if(nullptr == mAutoBrightnessManager)
mAutoBrightnessManager = AutoBrightnessManager::AutoBrightnessManagerNew();
}
AutoBrightnessPlugin::~AutoBrightnessPlugin()
{
if(mAutoBrightnessManager)
delete mAutoBrightnessManager;
if(mInstance)
delete mInstance;
}
void AutoBrightnessPlugin::activate()
{
USD_LOG(LOG_DEBUG,"Activating AutoBrightness plugins");
bool res;
res = mAutoBrightnessManager->AutoBrightnessManagerStart();
if(!res)
USD_LOG(LOG_ERR,"Unable to start AutoBrightness manager");
}
PluginInterface *AutoBrightnessPlugin::getInstance()
{
if(nullptr == mInstance)
mInstance = new AutoBrightnessPlugin();
return mInstance;
}
void AutoBrightnessPlugin::deactivate()
{
qDebug("Deactivating AutoBrightness plugin");
mAutoBrightnessManager->AutoBrightnessManagerStop();
}
PluginInterface *createSettingsPlugin()
{
return AutoBrightnessPlugin::getInstance();
}
ukui-settings-daemon/plugins/auto-brightness/brightThread.cpp 0000644 0001750 0001750 00000006430 14205117202 023461 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "brightThread.h"
#include
#include
#include
#include
extern "C"{
#include
#include
}
#define SETTINGS_POWER_MANAGER "org.ukui.power-manager"
#define BRIGHTNESS_AC "brightness-ac"
BrightThread::BrightThread(QObject *parent, double bright) : QThread(parent), brightness(bright)
//BrightThread::BrightThread(QObject *parent) : QThread(parent)
{
QByteArray id(SETTINGS_POWER_MANAGER);
if(QGSettings::isSchemaInstalled(id))
mpowerSettings = new QGSettings(SETTINGS_POWER_MANAGER);
currentBrightness = mpowerSettings->get(BRIGHTNESS_AC).toDouble();
}
void BrightThread::run(){
m_isCanRun = true;
if(qAbs(brightness - currentBrightness) <= 0.01){
mpowerSettings->set(BRIGHTNESS_AC, brightness);
return;
}
if(brightness > currentBrightness){
int interval = round(brightness-currentBrightness);
double step = (brightness-currentBrightness)/interval;
qDebug("需要调节%d次", interval);
for(int i=1; i<=interval; i++){
// qDebug() << "子线程ID:" << QThread::currentThreadId() << "m_isCanEun = " << m_isCanRun;
{
QMutexLocker locker(&m_lock);
if(!m_isCanRun){
// qDebug() << QThread::currentThreadId() << "被终止";
return;
}
}
mpowerSettings->set(BRIGHTNESS_AC, currentBrightness + i * step);
usleep(50000);
}
mpowerSettings->set(BRIGHTNESS_AC, brightness);
}
else{
int interval = round(currentBrightness-brightness);
double step = (currentBrightness-brightness)/interval;
qDebug("需要调节%d次", interval);
for(int i=1; i<=interval; i++){
// qDebug() << "子线程ID:" << QThread::currentThreadId() << "m_isCanEun = " << m_isCanRun;
{
QMutexLocker locker(&m_lock);
if(!m_isCanRun){
// qDebug() << QThread::currentThreadId() << "被终止";
return;
}
}
mpowerSettings->set(BRIGHTNESS_AC, currentBrightness - i * step);
usleep(50000);
}
mpowerSettings->set(BRIGHTNESS_AC, brightness);
}
qDebug() << "brightness = " << brightness;
}
void BrightThread::stopImmediately(){
QMutexLocker locker(&m_lock);
m_isCanRun = false;
}
BrightThread::~BrightThread()
{
if(mpowerSettings)
delete mpowerSettings;
}
ukui-settings-daemon/plugins/auto-brightness/autoBrightness-manager.h 0000644 0001750 0001750 00000003572 14205117202 025134 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef AUTOBRIGHTNESSMANAGER_H
#define AUTOBRIGHTNESSMANAGER_H
#include
#include
#include
#include
#include
#include "brightThread.h"
class AutoBrightnessManager : public QObject
{
Q_OBJECT
private:
AutoBrightnessManager();
AutoBrightnessManager(AutoBrightnessManager&)=delete;
AutoBrightnessManager&operator=(const AutoBrightnessManager&)=delete;
public:
~AutoBrightnessManager();
static AutoBrightnessManager *AutoBrightnessManagerNew();
bool AutoBrightnessManagerStart();
void AutoBrightnessManagerStop();
void SetEnabled(bool enabled);
public Q_SLOTS:
void AutoBrightnessUpdateState();
void onLocalThreadDestroy(QObject* obj);
void AutoBrightnessRefresh();
void AutoBrightnessSettingsChanged(QString);
private:
bool mEnabled;
double mPreLux;
QGSettings *mAutoBrightnessSettings;
static AutoBrightnessManager *mAutoBrightnessManager;
QLightSensor *mSensor;
KSharedConfig::Ptr mConfig;
BrightThread * m_currentRunLocalThread;
};
#endif // AUTOBRIGHTNESSMANAGER_H
ukui-settings-daemon/plugins/xinput/ 0000755 0001750 0001750 00000000000 14205117202 016554 5 ustar feng feng ukui-settings-daemon/plugins/xinput/xinputmanager.h 0000644 0001750 0001750 00000003474 14205117202 021617 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef XINPUTMANAGER_H
#define XINPUTMANAGER_H
#include
#include
#include "monitorinputtask.h"
extern "C"{
#include "clib-syslog.h"
}
class QGSettings;
class XinputManager : public QObject
{
Q_OBJECT
public:
XinputManager(QObject *parent = nullptr);
~XinputManager();
void start();
void stop();
Q_SIGNALS:
void sigStartThread();
private:
void init();
bool deviceHasProperty(XDevice *device,
const char *property_name);
private:
QThread *m_pManagerThread;
QMutex m_runningMutex;
MonitorInputTask *m_pMonitorInputTask;
QGSettings* m_penSettings = nullptr;
private Q_SLOTS:
void onSlaveAdded(int device_id);
void updateSettings(QString key);
/*!
* \brief update tablet tool button map
* It will refresh when the gsetting updates
* or receives an increased signal from the device
*/
void updateButtonMap();
private:
void SetPenRotation(int device_id);
QQueue GetPenDevice();
bool initSettings();
};
#endif // XINPUTMANAGER_H
ukui-settings-daemon/plugins/xinput/xinputplugin.cpp 0000644 0001750 0001750 00000002766 14205117202 022041 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "xinputplugin.h"
#include
#include
XinputPlugin* XinputPlugin::_instance = nullptr;
XinputPlugin* XinputPlugin::instance()
{
QMutex mutex;
mutex.lock();
if(nullptr == _instance)
_instance = new XinputPlugin;
mutex.unlock();
return _instance;
}
XinputPlugin::XinputPlugin():
m_pXinputManager(new XinputManager)
{
USD_LOG(LOG_ERR, "Loading Xinput plugins");
}
XinputPlugin::~XinputPlugin()
{
}
void XinputPlugin::activate()
{
USD_LOG(LOG_ERR,"activating Xinput plugins");
m_pXinputManager->start();
}
void XinputPlugin::deactivate()
{
m_pXinputManager->stop();
}
PluginInterface *createSettingsPlugin()
{
return dynamic_cast(XinputPlugin::instance());
}
ukui-settings-daemon/plugins/xinput/xinputplugin.h 0000644 0001750 0001750 00000002502 14205117202 021472 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef XINPUTPLUGIN_H
#define XINPUTPLUGIN_H
#include "plugin-interface.h"
#include "xinputmanager.h"
#include
extern "C"{
#include "clib-syslog.h"
}
class XinputPlugin : public PluginInterface
{
public:
XinputPlugin();
XinputPlugin(XinputPlugin&)=delete;
~XinputPlugin();
static XinputPlugin *instance();
virtual void activate();
virtual void deactivate();
private:
XinputManager *m_pXinputManager;
static XinputPlugin *_instance;
};
extern "C" Q_DECL_EXPORT PluginInterface *createSettingsPlugin();
#endif // XINPUTPLUGIN_H
ukui-settings-daemon/plugins/xinput/xinput.pro 0000644 0001750 0001750 00000001313 14205117202 020623 0 ustar feng feng QT += core gui x11extras
LIBS += -lXi -lX11
TEMPLATE = lib
DEFINES += XINPUT_LIBRARY
include($$PWD/../../common/common.pri)
CONFIG += c++11 link_pkgconfig x11extras debug
CONFIG += plugin
PKGCONFIG += x11
DEFINES += QT_DEPRECATED_WARNINGS MODULE_NAME=\\\"xinput\\\"
QMAKE_CXXFLAGS += -Wdeprecated-declarations
INCLUDEPATH += \
-I $$PWD/../../common/ \
-I ukui-settings-daemon/
SOURCES += \
monitorinputtask.cpp \
xinputmanager.cpp \
xinputplugin.cpp
HEADERS += \
monitorinputtask.h \
xinputmanager.h \
xinputplugin.h
xinput_lib.path = $${PLUGIN_INSTALL_DIRS}
xinput_lib.files = $$OUT_PWD/libxinput.so
INSTALLS += xinput_lib
ukui-settings-daemon/plugins/xinput/monitorinputtask.h 0000644 0001750 0001750 00000005571 14205117202 022367 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef MONITORINPUTTASK_H
#define MONITORINPUTTASK_H
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
extern "C"{
#include
#include "clib-syslog.h"
// #include "KylinDefine.h"
}
class MonitorInputTask : public QObject
{
Q_OBJECT
public:
bool m_running;
public:
static MonitorInputTask* instance(QObject *parent = nullptr);
public Q_SLOTS:
void StartManager();
Q_SIGNALS:
/*!
* \brief slaveAdded 从设备添加
* \param device_id
*/
void slaveAdded(int device_id);
/*!
* \brief slaveRemoved 从设备移除
* \param device_id
*/
void slaveRemoved(int device_id);
/*!
* \brief masterAdded 主分支添加
* \param device_id
*/
void masterAdded(int device_id);
/*!
* \brief masterRemoved 主分支移除
* \param device_id
*/
void masterRemoved(int device_id);
/*!
* \brief deviceEnable 设备启用
* \param device_id
*/
void deviceEnable(int device_id);
/*!
* \brief deviceDisable 设备禁用
* \param device_id
*/
void deviceDisable(int device_id);
/*!
* \brief slaveAttached 从设备附加
* \param device_id
*/
void slaveAttached(int device_id);
/*!
* \brief slaveDetached 从设备分离
* \param device_id
*/
void slaveDetached(int device_id);
private:
MonitorInputTask(QObject *parent = nullptr);
void initConnect();
/*!
* \brief ListeningToInputEvent 监听所有输入设备的事件
*/
void ListeningToInputEvent();
/*!
* \brief EventSift 筛选出发生事件的设备ID
* \param event 所有设备的事件信息
* \param flag 当前发生的事件
* \return 查找失败 return -1; 查找成功 return device_id;
*/
int EventSift(XIHierarchyEvent *event, int flag);
};
#endif // MONITORINPUTTASK_H
ukui-settings-daemon/plugins/xinput/monitorinputtask.cpp 0000644 0001750 0001750 00000013215 14205117202 022714 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "monitorinputtask.h"
#include "xinputmanager.h"
MonitorInputTask* MonitorInputTask::instance(QObject *parent)
{
static MonitorInputTask *_instance = nullptr;
QMutex mutex;
mutex.lock();
if(!_instance)
_instance = new MonitorInputTask(parent);
mutex.unlock();
return _instance;
}
MonitorInputTask::MonitorInputTask(QObject *parent):
QObject(parent),
m_running(false)
{
initConnect();
}
void MonitorInputTask::initConnect()
{
}
void MonitorInputTask::StartManager()
{
USD_LOG(LOG_DEBUG,"info: [MonitorInputTask][StartManager]: thread id =%d",QThread::currentThreadId());
QTimer::singleShot(0, this, &MonitorInputTask::ListeningToInputEvent);
}
int MonitorInputTask::EventSift(XIHierarchyEvent *event, int flag)
{
int device_id = -1;
int cnt = event->num_info;
XIHierarchyInfo *event_list = event->info;
for(int i = 0;i < cnt;i++)
{
if(event_list[i].flags & flag)
{
device_id = event_list[i].deviceid;
}
}
return device_id;
}
void MonitorInputTask::ListeningToInputEvent()
{
USD_LOG(LOG_DEBUG,"Start ListeningToInputEvent!");
Display *display = NULL;
// open display
// PEEK_XOpenDisplay(display);
display = XOpenDisplay(NULL);
// display = XOpenDisplay(NULL);
// openDisplayOK = true;
//QX11Info::display();
USD_LOG(LOG_DEBUG, "choke check pass......");
if (display == NULL)
{
USD_LOG(LOG_ERR,"OpenDisplay fail....");
return;
}
XIEventMask mask[2];
XIEventMask *m;
Window win;
USD_LOG(LOG_DEBUG, "choke check pass......");
win = DefaultRootWindow(display);
USD_LOG(LOG_DEBUG, "choke check pass......");
m = &mask[0];
m->deviceid = XIAllDevices;
m->mask_len = XIMaskLen(XI_LASTEVENT);
m->mask = (unsigned char*)calloc(m->mask_len, sizeof(char));
XISetMask(m->mask, XI_HierarchyChanged);
USD_LOG(LOG_DEBUG, "choke check pass......");
m = &mask[1];
m->deviceid = XIAllMasterDevices;
m->mask_len = XIMaskLen(XI_LASTEVENT);
m->mask = (unsigned char*)calloc(m->mask_len, sizeof(char));
XISelectEvents(display, win, &mask[0], 2);
XSync(display, False);
USD_LOG(LOG_DEBUG, "choke check pass......");
free(mask[0].mask);
free(mask[1].mask);
while(true)
{
XEvent ev;
XGenericEventCookie *cookie = (XGenericEventCookie*)&ev.xcookie;
USD_LOG(LOG_DEBUG, "choke chdeck pass......cookie->evtype:%d",cookie->evtype);
// if (cookie->type != GenericEvent){
// USD_LOG(LOG_DEBUG, "choke chdeck pass......type error:%d is't GenericEvent(%d)",cookie->evtype,GenericEvent);
// continue;
// }
XNextEvent(display, (XEvent*)&ev);//该方法会引起glib崩溃一次.下次出现记录具体的事件类型,该方法是阻塞处理。。。。
USD_LOG(LOG_DEBUG, "choke check pass......event:%d",ev.type);
// 判断当前事件监听是否还要继续
// 保证效率 m_running[*bool] 的访问不需要加锁
if(!m_running){
USD_LOG(LOG_DEBUG, "choke check pass......break");
break;
}
USD_LOG(LOG_DEBUG, "choke check pass......");
if (XGetEventData(display, cookie) &&
cookie->type == GenericEvent)
{
USD_LOG(LOG_DEBUG, "choke check pass......");
if(XI_HierarchyChanged == cookie->evtype)
{
XIHierarchyEvent *hev = (XIHierarchyEvent*)cookie->data;
if(hev->flags & XIMasterRemoved)
{
Q_EMIT masterRemoved(EventSift(hev, XIMasterRemoved));
}
else if(hev->flags & XISlaveAdded)
{
Q_EMIT slaveAdded(EventSift(hev, XISlaveAdded));
}
else if(hev->flags & XISlaveRemoved)
{
Q_EMIT slaveRemoved(EventSift(hev, XISlaveRemoved));
}
else if(hev->flags & XISlaveAttached)
{
Q_EMIT slaveAttached(EventSift(hev, XISlaveAttached));
}
else if(hev->flags & XISlaveDetached)
{
Q_EMIT slaveDetached(EventSift(hev, XISlaveDetached));
}
else if(hev->flags & XIDeviceEnabled)
{
Q_EMIT deviceEnable(EventSift(hev, XIDeviceEnabled));
}
else if(hev->flags & XIDeviceDisabled)
{
Q_EMIT deviceDisable(EventSift(hev, XIDeviceDisabled));
}
else if(hev->flags & XIMasterAdded)
{
Q_EMIT masterAdded(EventSift(hev, XIMasterAdded));
}
}
}
USD_LOG(LOG_DEBUG, "choke check pass......");
XFreeEventData(display, cookie);
}
XDestroyWindow(display, win);
}
ukui-settings-daemon/plugins/xinput/xinputmanager.cpp 0000644 0001750 0001750 00000017416 14205117202 022153 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "xinputmanager.h"
#include
#include
#include
#include
#include
#define UKUI_CONTROL_CENTER_PEN_SCHEMA "org.ukui.control-center.pen"
#define RIGHT_CLICK_KEY "right-click"
XinputManager::XinputManager(QObject *parent):
QObject(parent)
{
init();
}
void XinputManager::init()
{
// init device monitor
m_pMonitorInputTask = MonitorInputTask::instance();
connect(this, &XinputManager::sigStartThread, m_pMonitorInputTask, &MonitorInputTask::StartManager);
connect(m_pMonitorInputTask, &MonitorInputTask::slaveAdded, this, &XinputManager::onSlaveAdded);
connect(m_pMonitorInputTask, &MonitorInputTask::slaveAdded, this, &XinputManager::updateButtonMap);
m_pManagerThread = new QThread(this);
m_pMonitorInputTask->moveToThread(m_pManagerThread);
// init pen settings
if ( false == initSettings()) {
return ;
}
// init settings monitor
connect(m_penSettings, SIGNAL(changed(QString)), this, SLOT(updateSettings(QString)));
}
XinputManager::~XinputManager()
{
if (m_penSettings)
delete m_penSettings;
}
void XinputManager::start()
{
USD_LOG(LOG_DEBUG,"info: [XinputManager][StartManager]: thread id =%d",QThread::currentThreadId());
m_runningMutex.lock();
m_pMonitorInputTask->m_running = true;
m_runningMutex.unlock();
m_pManagerThread->start();
Q_EMIT sigStartThread();
}
void XinputManager::stop()
{
if(m_pManagerThread->isRunning())
{
m_runningMutex.lock();
m_pMonitorInputTask->m_running = false;
m_runningMutex.unlock();
m_pManagerThread->quit();
}
}
void XinputManager::SetPenRotation(int device_id)
{
// Q_UNUSED(device_id);
// 得到触控笔的ID
QQueue penDeviceQue;
int ndevices = 0;
Display *dpy = XOpenDisplay(NULL);
XIDeviceInfo *info = XIQueryDevice(dpy, XIAllDevices, &ndevices);
for (int i = 0; i < ndevices; i++) {
XIDeviceInfo* dev = &info[i];
if(!dev->enabled) continue;
if(device_id != dev->deviceid) {
continue;
}
if(dev->use != XISlavePointer) continue;
for (int j = 0; j < dev->num_classes; j++) {
if (dev->classes[j]->type == XITouchClass) {
// 如果当前的设备是绝对坐标映射 则认为该设备需要进行一次屏幕映射
QDBusInterface *xrandDbus = new QDBusInterface(DBUS_XRANDR_NAME,DBUS_XRANDR_PATH,DBUS_XRANDR_INTERFACE,QDBusConnection::sessionBus(),this);
if (xrandDbus->isValid()) {
//USD_LOG(LOG_DEBUG, "..");
xrandDbus->asyncCall("setScreenMap");
}
}
}
}
for (int i = 0; i < ndevices; i++) {
XIDeviceInfo* dev = &info[i];
// 判断当前设备是不是触控笔
if(dev->use != XISlavePointer) continue;
if(!dev->enabled) continue;
for (int j = 0; j < dev->num_classes; j++) {
if (dev->classes[j]->type == XIValuatorClass) {
XIValuatorClassInfo *t = (XIValuatorClassInfo*)dev->classes[j];
// 如果当前的设备是绝对坐标映射 则认为该设备需要进行一次屏幕映射
if (t->mode == XIModeAbsolute) {
penDeviceQue.enqueue(dev->deviceid);
break;
}
}
}
}
if(!penDeviceQue.size()) {
// qDebug() << "info: [XrandrManager][SetPenRotation]: Do not neet to pen device map-to-output outDevice!";
//return;
goto FREE_DPY;
}
// 设置map-to-output
while(penDeviceQue.size()) {
int pen_device_id = penDeviceQue.dequeue();
QString name = "eDP-1"; //针对该项目而言,笔记本内显固定为 eDP-1
QString cmd = QString("xinput map-to-output %1 %2").arg(pen_device_id).arg(name);
QProcess::execute(cmd);
}
FREE_DPY:
XIFreeDeviceInfo(info);
XCloseDisplay(dpy);
}
void XinputManager::onSlaveAdded(int device_id)
{
// qDebug() << "info: [XinputManager][onSlaveAdded]: Slave Device(id =" << device_id << ") Added!";
SetPenRotation(device_id);//新设备不是触控笔就不要处理了!
}
bool XinputManager::initSettings()
{
if (!QGSettings::isSchemaInstalled(UKUI_CONTROL_CENTER_PEN_SCHEMA)) {
USD_LOG(LOG_DEBUG,"Can not find schema org.ukui.control-center.pen!");
return false;
}
m_penSettings = new QGSettings(UKUI_CONTROL_CENTER_PEN_SCHEMA);
updateButtonMap();
return true;
}
void XinputManager::updateSettings(QString key)
{
if (key == RIGHT_CLICK_KEY) {
updateButtonMap();
}
}
void XinputManager::updateButtonMap()
{
QQueue deviceQue = GetPenDevice();
if (!deviceQue.size()) {
return;
}
QString command;
//! \brief The button-map default value is 1234567,
//! and the modified mapping is 1334567
//! The numbers in this refer to button 2 being mapped to button 3
while (deviceQue.size()) {
if (m_penSettings->get(RIGHT_CLICK_KEY).value()) {
command = QString("xinput set-button-map %1 1 3 3").arg(deviceQue.dequeue());
}
else {
command = QString("xinput set-button-map %1 1 2 3").arg(deviceQue.dequeue());
}
QProcess::execute(command);
}
}
QQueue XinputManager::GetPenDevice()
{
QQueue penDeviceQue;
int ndevices = 0;
Display* dpy = XOpenDisplay(NULL);
XIDeviceInfo* info = XIQueryDevice(dpy, XIAllDevices, &ndevices);
for (int i = 0; i < ndevices; i++) {
XIDeviceInfo* dev = &info[i];
if(dev->use != XISlavePointer)
continue;
if(!dev->enabled)
continue;
XDevice* device = XOpenDevice(dpy, dev->deviceid);
/*!
* \note Currently only pen devices have this property,
* but it is not certain that this property must be pen-only
*/
if (deviceHasProperty(device, "libinput Tablet Tool Pressurecurve")) {
penDeviceQue.enqueue(dev->deviceid);
}
XCloseDevice(dpy, device);
}
XIFreeDeviceInfo(info);
XCloseDisplay(dpy);
return penDeviceQue;
}
bool XinputManager::deviceHasProperty(XDevice *device,
const char *property_name)
{
Display* dpy = XOpenDisplay(NULL);
Atom realtype, prop;
int realformat;
unsigned long nitems, bytes_after;
unsigned char* data;
prop = XInternAtom (dpy, property_name, True);
if (!prop) {
XCloseDisplay(dpy);
return false;
}
try {
if ((XGetDeviceProperty(dpy, device, prop, 0, 1, False,
XA_INTEGER, &realtype, &realformat, &nitems,
&bytes_after, &data) == Success) && (realtype != None)) {
XFree (data);
XCloseDisplay(dpy);
return true;
}
} catch (int x) {
}
XCloseDisplay(dpy);
return false;
}
ukui-settings-daemon/plugins/background/ 0000755 0001750 0001750 00000000000 14205117202 017344 5 ustar feng feng ukui-settings-daemon/plugins/background/background.pro 0000644 0001750 0001750 00000001414 14205117202 022205 0 ustar feng feng #-------------------------------------------------
#
# Project created by QtCreator 2020-04-16T09:30:00
#
#-------------------------------------------------
QT += core widgets dbus x11extras gui
TEMPLATE = lib
TARGET = background
CONFIG += no_keywords c++11 create_prl plugin link_pkgconfig app_bundle debug
DEFINES += MODULE_NAME=\\\"backGround\\\"
include($$PWD/../../common/common.pri)
PKGCONFIG += \
gio-2.0 \
gtk+-3.0 \
glib-2.0 \
imlib2
SOURCES += \
$$PWD/background-plugin.cpp \
$$PWD/background-manager.cpp
HEADERS += \
$$PWD/background-plugin.h \
$$PWD/background-manager.h
background_lib.path = $${PLUGIN_INSTALL_DIRS}
background_lib.files += $$OUT_PWD/libbackground.so
INSTALLS += background_lib
ukui-settings-daemon/plugins/background/background-plugin.cpp 0000644 0001750 0001750 00000003314 14205117202 023464 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include
#include "background-plugin.h"
#include "clib-syslog.h"
PluginInterface* BackgroundPlugin::mInstance = nullptr;
BackgroundPlugin::BackgroundPlugin()
{
return;
manager = new BackgroundManager();
return;
}
BackgroundPlugin::~BackgroundPlugin()
{
USD_LOG(LOG_DEBUG, "background plugin free...");
if(manager){
delete manager;
manager = nullptr;
}
}
PluginInterface *BackgroundPlugin::getInstance()
{
if (nullptr == mInstance) {
mInstance = new BackgroundPlugin();
}
return mInstance;
}
void BackgroundPlugin::activate()
{
return;
USD_LOG (LOG_DEBUG, "Activating %s plugin compilation time:[%s] [%s]",MODULE_NAME,__DATE__,__TIME__);
manager->BackgroundManagerStart();
}
void BackgroundPlugin::deactivate()
{
USD_LOG (LOG_DEBUG, "Deactivating background plugin");
}
PluginInterface* createSettingsPlugin()
{
return BackgroundPlugin::getInstance();
}
ukui-settings-daemon/plugins/background/background-manager.cpp 0000644 0001750 0001750 00000011024 14205117202 023575 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include
#include
#include "background-manager.h"
#include
#include
#define BACKGROUND "org.mate.background"
#define PICTURE_FILE_NAME "picture-filename"
#define COLOR_FILE_NAME "primary-color"
#define CAN_DRAW_BACKGROUND "draw-background"
BackgroundManager::BackgroundManager()
{
m_screen = QApplication::screens().at(0);
}
BackgroundManager::~BackgroundManager()
{
if(bSettingOld)
delete bSettingOld;
}
void BackgroundManager::initGSettings(){
bSettingOld = new QGSettings(BACKGROUND);
Filename = bSettingOld->get(PICTURE_FILE_NAME).toString();
// QObject::connect(bSettingOld, &QGSettings::changed, this, &BackgroundManager::setup_Background);
// QObject::connect(qApp, &QApplication::screenAdded, this, &BackgroundManager::screenAddedProcess);
// QObject::connect(qApp, &QApplication::screenRemoved, this, &BackgroundManager::screenRemovedProcess);
// QObject::connect(m_screen, &QScreen::virtualGeometryChanged, this, &BackgroundManager::virtualGeometryChangedProcess);
connect(bSettingOld, SIGNAL(changed(QString)),this, SLOT(setup_Background(QString)));
connect(qApp,SIGNAL(screenAdded(QScreen *)),this, SLOT(screenAddedProcess(QScreen*)));
connect(qApp, SLOT(screenRemoved(QScreen *)),this, SLOT(screenRemovedProcess(QScreen *)));
connect(m_screen, &QScreen::virtualGeometryChanged, this,&BackgroundManager::virtualGeometryChangedProcess);
}
void BackgroundManager::SetBackground()
{
Pixmap pix;
Window root;
Screen *scn;
QScreen *screen;
Imlib_Image img;
int ScnNum, width = 0,height = 0;
dpy = gdk_x11_get_default_xdisplay();
img = imlib_load_image(Filename.toLatin1().data());
if (!img) {
USD_LOG(LOG_DEBUG,"%s:Unable to load image\n", Filename.toLatin1().data());
return ;
}
imlib_context_set_image(img);
if (!dpy)
return ;
ScnNum = QApplication::screens().length();
width = DisplayWidth(dpy, 0);
height = DisplayHeight(dpy, 0);
scn = DefaultScreenOfDisplay(dpy);
root = DefaultRootWindow(dpy);
pix = XCreatePixmap(dpy, root, width, height,
DefaultDepthOfScreen(scn));
imlib_context_set_display(dpy);
imlib_context_set_visual(DefaultVisualOfScreen(scn));
imlib_context_set_colormap(DefaultColormapOfScreen(scn));
imlib_context_set_drawable(pix);
ScnNum = QApplication::screens().length();
for(int i = 0; i < ScnNum; i++){
screen = QApplication::screens().at(i);
//qDebug()<geometry();
imlib_render_image_on_drawable_at_size(screen->geometry().x() * 2,
screen->geometry().y() * 2,
screen->geometry().width() *2,
screen->geometry().height() * 2);
}
XSetWindowBackgroundPixmap(dpy, root, pix);
XClearWindow(dpy, root);
while (XPending(dpy)) {
XEvent ev;
XNextEvent(dpy, &ev);
}
XFreePixmap(dpy, pix);
imlib_free_image();
}
void BackgroundManager::setup_Background(const QString &key)
{
if(key.compare(QString::fromLocal8Bit(PICTURE_FILE_NAME))==0)
Filename = bSettingOld->get(PICTURE_FILE_NAME).toString();
if(key.compare(QString::fromLocal8Bit(COLOR_FILE_NAME))==0)
Filename = bSettingOld->get(COLOR_FILE_NAME).toString();
SetBackground();
}
void BackgroundManager::screenAddedProcess(QScreen *screen)
{
SetBackground();
}
void BackgroundManager::screenRemovedProcess(QScreen *screen)
{
SetBackground();
}
void BackgroundManager::virtualGeometryChangedProcess(const QRect &geometry)
{
SetBackground();
}
void BackgroundManager::BackgroundManagerStart()
{
initGSettings();
//SetBackground();
}
ukui-settings-daemon/plugins/background/background-plugin.h 0000644 0001750 0001750 00000002546 14205117202 023137 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef BACKGROUNDPLUGIN_H
#define BACKGROUNDPLUGIN_H
#include "background-manager.h"
#include "plugin-interface.h"
#include
class BackgroundPlugin : public PluginInterface
{
public:
~BackgroundPlugin();
static PluginInterface* getInstance();
virtual void activate ();
virtual void deactivate ();
private:
BackgroundPlugin();
BackgroundPlugin(BackgroundPlugin&)=delete;
private:
BackgroundManager *manager;
static PluginInterface* mInstance;
};
extern "C" Q_DECL_EXPORT PluginInterface* createSettingsPlugin();
#endif // BACKGROUNDPLUGIN_H
ukui-settings-daemon/plugins/background/background-manager.h 0000644 0001750 0001750 00000003176 14205117202 023253 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#ifndef BACKGROUND_MANAGER_H
#define BACKGROUND_MANAGER_H
#include
#include
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
#include "clib-syslog.h"
#ifdef __cplusplus
}
#endif
class BackgroundManager : public QObject
{
Q_OBJECT
public:
BackgroundManager();
~BackgroundManager();
public:
void BackgroundManagerStart();
void SetBackground();
void initGSettings();
private:
void scaleBg(const QRect &geometry);
void virtualGeometryChangedProcess(const QRect &geometry);
public Q_SLOTS:
void setup_Background(const QString &key);
void screenAddedProcess(QScreen *screen);
void screenRemovedProcess(QScreen *screen);
private:
QGSettings *bSettingOld;
QScreen *m_screen;
QString Filename;
Display *dpy;
};
#endif // BACKGROUND_MANAGER_H
ukui-settings-daemon/plugins/media-keys/ 0000755 0001750 0001750 00000000000 14205117214 017260 5 ustar feng feng ukui-settings-daemon/plugins/media-keys/xEventMonitor.cpp 0000644 0001750 0001750 00000012050 14205117202 022600 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "xEventMonitor.h"
xEventMonitor::xEventMonitor(QObject *parent) : QThread(parent)
{
isPress = false;
start(QThread::LowestPriority);
}
void xEventMonitor::run()
{
Display* display = XOpenDisplay(0);
if (display == 0) {
USD_LOG(LOG_DEBUG, "unable to open display\n");
return;
}
// Receive from ALL clients, including future clients.
XRecordClientSpec clients = XRecordAllClients;
XRecordRange* range = XRecordAllocRange();
if (range == 0) {
USD_LOG(LOG_DEBUG,"unable to allocate XRecordRange\n");
return;
}
// Receive KeyPress, KeyRelease, ButtonPress, ButtonRelease and MotionNotify events.
memset(range, 0, sizeof(XRecordRange));
range->device_events.first = KeyPress;
range->device_events.last = MotionNotify;
// And create the XRECORD context.
XRecordContext context = XRecordCreateContext(display, 0, &clients, 1, &range, 1);
if (context == 0) {
USD_LOG(LOG_DEBUG,"XRecordCreateContext failed\n");//fprintf(stderr, "XRecordCreateContext failed\n");
return;
}
XFree(range);
XSync(display, True);
Display* display_datalink = XOpenDisplay(0);
if (display_datalink == 0) {
// fprintf(stderr, "unable to open second display\n");
USD_LOG(LOG_DEBUG,"unable to open second display\n");
return;
}
if (!XRecordEnableContext(display_datalink, context, callback, (XPointer) this)) {
// fprintf(stderr, "XRecordEnableContext() failed\n");
USD_LOG(LOG_DEBUG,"XRecordEnableContext() failed\n");
return;
}
XCloseDisplay(display);
XCloseDisplay(display_datalink);
}
void xEventMonitor::callback(XPointer ptr, XRecordInterceptData* data)
{
((xEventMonitor *) ptr)->handleRecordEvent(data);
}
bool xEventMonitor::getWinPressStatus()
{
return winPress;
}
bool xEventMonitor::getCtrlPressStatus()
{
return ctrlPress_l | ctrlPress_r;
}
bool xEventMonitor::getAltPressStatus()
{
return altPress_l | altPress_r;
}
bool xEventMonitor::getShiftPressStatus()
{
return shiftPress_l | shiftPress_r;
}
void xEventMonitor::handleRecordEvent(XRecordInterceptData* data)
{
int eventKeysym;
static int Bpress = 0;
if (data->category == XRecordFromServer) {
xEvent * event = (xEvent *)data->data;
if (event->u.u.type!=KeyPress && event->u.u.type!=KeyRelease){
goto ERR;
}
switch (event->u.u.type) {
case KeyPress:
switch(event->u.u.detail){
case LEFT_SHIFT:
shiftPress_l = true;
break;
case LEFT_CTRL:
ctrlPress_l = true;
Q_EMIT keyPress(event);
break;
case LEFT_ALT:
altPress_l = true;
break;
case RIGHT_SHIFT:
shiftPress_r = true;
break;
case RIGHT_ALT:
altPress_r = true;
break;
case RIGHT_CTRL:
ctrlPress_r = true;
Q_EMIT keyPress(event);
break;
case MATE_KEY:
winPress = true;
break;
default :
Q_EMIT keyPress(event);
break;
}
break;
case KeyRelease:
switch(event->u.u.detail){
case LEFT_SHIFT:
shiftPress_l = false;
break;
case LEFT_CTRL:
ctrlPress_l = false;
break;
case LEFT_ALT:
altPress_l = false;
break;
case RIGHT_SHIFT:
shiftPress_r = false;
break;
case RIGHT_ALT:
altPress_r = false;
break;
case RIGHT_CTRL:
ctrlPress_r = false;
break;
case MATE_KEY:
winPress = false;
break;
default :
Q_EMIT keyRelease(event);
break;
}
break;
default:
break;
}
}
ERR:
XRecordFreeData(data);
}
bool xEventMonitor::filterWheelEvent(int detail)
{
return detail != WheelUp && detail != WheelDown && detail != WheelLeft && detail != WheelRight;
}
ukui-settings-daemon/plugins/media-keys/mediakey-manager.cpp 0000644 0001750 0001750 00000245712 14205117202 023174 0 ustar feng feng /* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
* -*- coding: utf-8 -*-
*
* Copyright (C) 2020 KylinSoft Co., Ltd.
*
* 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 3 of the License, or
* 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, see .
*/
#include "mediakey-manager.h"
#include "eggaccelerators.h"
#include
#include "clib-syslog.h"
#include "rfkillswitch.h"
#include "usd_base_class.h"
MediaKeysManager* MediaKeysManager::mManager = nullptr;
const int VOLUMESTEP = 6;
#define midValue(x,low,high) (((x) > (high)) ? (high): (((x) < (low)) ? (low) : (x)))
#define TIME_LIMIT 2500
#define MAX_BRIGHTNESS 100
#define STEP_BRIGHTNESS 10
#define UKUI_DAEMON_NAME "ukui-settings-daemon"
#define MEDIAKEY_SCHEMA "org.ukui.SettingsDaemon.plugins.media-keys"
#define POINTER_SCHEMA "org.ukui.SettingsDaemon.plugins.mouse"
#define POINTER_KEY "locate-pointer"
#define POWER_SCHEMA "org.ukui.power-manager"
#define POWER_BUTTON_KEY "button-power"
#define SESSION_SCHEMA "org.ukui.session"
#define SESSION_WIN_KEY "win-key-release"
#define SHOT_SCHEMA "org.ukui.screenshot"
#define SHOT_RUN_KEY "isrunning"
#define PANEL_QUICK_OPERATION "org.ukui.quick-operation.panel"
#define PANEL_SOUND_STATE "soundstate"
#define PANEL_SOUND_VOLUMSIZE "volumesize"
#define GPM_SETTINGS_SCHEMA "org.ukui.power-manager"
#define GPM_SETTINGS_BRIGHTNESS_AC "brightness-ac"
typedef enum {
POWER_SUSPEND = 1,
POWER_SHUTDOWN = 2,
POWER_HIBERNATE = 3,
POWER_INTER_ACTIVE = 4
} PowerButton;
MediaKeysManager::MediaKeysManager(QObject* parent):QObject(parent)
{
mTimer = new QTimer(this);
mVolumeWindow = new VolumeWindow();
mDeviceWindow = new DeviceWindow();
powerSettings = new QGSettings(POWER_SCHEMA);
mSettings = new QGSettings(MEDIAKEY_SCHEMA);
pointSettings = new QGSettings(POINTER_SCHEMA);
sessionSettings = new QGSettings(SESSION_SCHEMA);
gdk_init(NULL,NULL);
//session bus 会话总线
QDBusConnection sessionBus = QDBusConnection::sessionBus();
if(sessionBus.registerService("org.ukui.SettingsDaemon")){
sessionBus.registerObject("/org/ukui/SettingsDaemon/MediaKeys",this,
QDBusConnection::ExportAllContents);
}
mXEventMonitor = new xEventMonitor(this);
}
MediaKeysManager::~MediaKeysManager()
{
delete mTimer;
if (mXEventMonitor) {
mXEventMonitor->deleteLater();
}
if (mSettings) {
delete mSettings;
mSettings = nullptr;
}
if (pointSettings) {
delete pointSettings;
mSettings = nullptr;
}
if (sessionSettings) {
delete sessionSettings;
sessionSettings = nullptr;
}
if (shotSettings) {
delete shotSettings;
shotSettings = nullptr;
}
// if (mExecCmd)
// delete mExecCmd;
if (mVolumeWindow) {
delete mVolumeWindow;
mVolumeWindow = nullptr;
}
if (mDeviceWindow) {
delete mDeviceWindow;
mDeviceWindow = nullptr;
}
if (powerSettings) {
delete powerSettings;
powerSettings = nullptr;
}
}
MediaKeysManager* MediaKeysManager::mediaKeysNew()
{
if(nullptr == mManager)
mManager = new MediaKeysManager();
return mManager;
}
void MediaKeysManager::sjhKeyTest()
{
QList args;
QString param = QString::fromLocal8Bit(""
"["
"{"
"\"enabled\": true,"
" \"id\": \"e3fa3cd9190f27820ab7c30a34b9f1fb\","
" \"metadata\": {"
"\"fullname\": \"xrandr-DO NOT USE - RTK-WCS Display\","
"\"name\": \"HDMI-1\""
" },"
" \"mode\": {"
" \"refresh\": 30,"
"\"size\": {"
" \"height\": 2160,"
" \"width\": 3840"
"}"
"},"
"\"pos\": {"
" \"x\": 0,"
" \"y\": 0"
"},"
"\"primary\": false,"
"\"rotation\": 1,"
"\"scale\": 1"
"},"
"{"
" \"enabled\": true,"
" \"id\": \"e2add05191c5c70db7824c9cd76e19f5\","
" \"metadata\": {"
" \"fullname\": \"xrandr-Lenovo Group Limited-LEN LI2224A-U5619HB8\","
" \"name\": \"DP-2\""
"},"
"\"mode\": {"
" \"refresh\": 59.93387985229492,"
" \"size\": {"
" \"height\": 1080,"
" \"width\": 1920"
"}"
"},"
"\"pos\": {"
" \"x\": 3840,"
" \"y\": 0"
"},"
"\"primary\": true,"
"\"rotation\": 1,"
"\"scale\": 1"
"}"
"]"
"");
QDBusMessage message = QDBusMessage::createMethodCall(DBUS_XRANDR_NAME,
DBUS_XRANDR_PATH,
DBUS_XRANDR_INTERFACE,
"setScreensParam");
args.append(param);
args.append(qAppName());
message.setArguments(args);
QDBusConnection::sessionBus().send(message);
}
bool MediaKeysManager::getScreenLockState()
{
bool res = false;
QDBusMessage response = QDBusConnection::sessionBus().call(mDbusScreensaveMessage);
if (response.type() == QDBusMessage::ReplyMessage)
{
if(response.arguments().isEmpty() == false) {
bool value = response.arguments().takeFirst().toBool();
res = value;
}
} else {
USD_LOG(LOG_DEBUG, "GetLockState called failed");
}
return res;
}
bool MediaKeysManager::mediaKeysStart(GError*)
{
// mate_mixer_init();
QList::iterator l,begin,end;
if (true == QGSettings::isSchemaInstalled(SHOT_SCHEMA)) {
shotSettings = new QGSettings(SHOT_SCHEMA);
if (nullptr != shotSettings) {
if (shotSettings->keys().contains(SHOT_RUN_KEY)) {
if (shotSettings->get(SHOT_RUN_KEY).toBool())
shotSettings->set(SHOT_RUN_KEY, false);
}
}
}
mVolumeWindow->initWindowInfo();
mDeviceWindow->initWindowInfo();
initShortcuts();
initXeventMonitor();
mDbusScreensaveMessage = QDBusMessage::createMethodCall("org.ukui.ScreenSaver",
"/",
"org.ukui.ScreenSaver",
"GetLockState");
return true;
}
int8_t MediaKeysManager::getCurrentMode()
{
QDBusMessage message = QDBusMessage::createMethodCall(DBUS_STATUSMANAGER_NAME,
DBUS_STATUSMANAGER_PATH,
DBUS_STATUSMANAGER_NAME,
DBUS_STATUSMANAGER_GET_MODE);
QDBusMessage response = QDBusConnection::sessionBus().call(message);
if (response.type() == QDBusMessage::ReplyMessage) {
if(response.arguments().isEmpty() == false) {
bool value = response.arguments().takeFirst().toBool();
USD_LOG(LOG_DEBUG, "get mode :%d", value);
return value;
}
}
return -1;
}
void MediaKeysManager::initShortcuts()
{
/* WebCam */
QAction *webCam= new QAction(this);
webCam->setObjectName(QStringLiteral("Toggle WebCam"));
webCam->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(webCam, QList{Qt::Key_WebCam});
KGlobalAccel::self()->setShortcut(webCam, QList{Qt::Key_WebCam});
connect(webCam, &QAction::triggered, this, [this]() {
doAction(WEBCAM_KEY);
});
if (false == UsdBaseClass::isUseXEventAsShutKey()) {
/* touchpad */
QAction *touchpad= new QAction(this);
touchpad->setObjectName(QStringLiteral("Toggle touchpad"));
touchpad->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(touchpad, QList{Qt::Key_TouchpadToggle});
KGlobalAccel::self()->setShortcut(touchpad, QList{Qt::Key_TouchpadToggle});
connect(touchpad, &QAction::triggered, this, [this]() {
doAction(TOUCHPAD_KEY);
});
/* Brightness Down */
QAction *brightDown= new QAction(this);
brightDown->setObjectName(QStringLiteral("Brightness down"));
brightDown->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(brightDown, QList{Qt::Key_MonBrightnessDown});
KGlobalAccel::self()->setShortcut(brightDown, QList{Qt::Key_MonBrightnessDown});
connect(brightDown, &QAction::triggered, this, [this]() {
USD_LOG(LOG_DEBUG,"Brightness down...............");
doAction(BRIGHT_DOWN_KEY);
});
/* Brightness Up */
QAction *brightUp = new QAction(this);
brightUp->setObjectName(QStringLiteral("Brightness Up"));
brightUp->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(brightUp, QList{Qt::Key_MonBrightnessUp});
KGlobalAccel::self()->setShortcut(brightUp, QList{Qt::Key_MonBrightnessUp});
connect(brightUp, &QAction::triggered, this, [this]() {
USD_LOG(LOG_DEBUG,"Brightness Up ..................");
doAction(BRIGHT_UP_KEY);
});
/* sound mute*/
QAction *volumeMute= new QAction(this);
volumeMute->setObjectName(QStringLiteral("Volume mute"));
volumeMute->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(volumeMute, QList{Qt::Key_VolumeMute});
KGlobalAccel::self()->setShortcut(volumeMute, QList{Qt::Key_VolumeMute});
connect(volumeMute, &QAction::triggered, this, [this]() {
doAction(MUTE_KEY);
});
/*sound down*/
QAction *volumeDown= new QAction(this);
volumeDown->setObjectName(QStringLiteral("Volume down"));
volumeDown->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(volumeDown, QList{Qt::Key_VolumeDown});
KGlobalAccel::self()->setShortcut(volumeDown, QList{Qt::Key_VolumeDown});
connect(volumeDown, &QAction::triggered, this, [this]() {
doAction(VOLUME_DOWN_KEY);
});
/*sound up*/
QAction *volumeUp= new QAction(this);
volumeUp->setObjectName(QStringLiteral("Volume up"));
volumeUp->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(volumeUp, QList{Qt::Key_VolumeUp});
KGlobalAccel::self()->setShortcut(volumeUp, QList{Qt::Key_VolumeUp});
connect(volumeUp, &QAction::triggered, this, [this]() {
doAction(VOLUME_UP_KEY);
});
/*screenshot*/
QAction *screenshot= new QAction(this);
screenshot->setObjectName(QStringLiteral("Take a screenshot"));
screenshot->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(screenshot, QList{Qt::Key_Print});
KGlobalAccel::self()->setShortcut(screenshot, QList{Qt::Key_Print});
connect(screenshot, &QAction::triggered, this, [this]() {
if(!mTimer->isActive()){
mTimer->singleShot(1000, this, [=]() {
doAction(SCREENSHOT_KEY);
});
}
});
/*mic mute*/
QAction *micMute= new QAction(this);
micMute->setObjectName(QStringLiteral("Mic mute"));
micMute->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(micMute, QList{Qt::Key_MicMute});
KGlobalAccel::self()->setShortcut(micMute, QList{Qt::Key_MicMute});
connect(micMute, &QAction::triggered, this, [this]() {
doAction(MIC_MUTE_KEY);
});
/*window screenshot*/
QAction *wScreenshot= new QAction(this);
wScreenshot->setObjectName(QStringLiteral("Take a screenshot of a window"));
wScreenshot->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(wScreenshot, QList{Qt::CTRL + Qt::Key_Print});
KGlobalAccel::self()->setShortcut(wScreenshot, QList{Qt::CTRL + Qt::Key_Print});
connect(wScreenshot, &QAction::triggered, this, [this]() {
if(!mTimer->isActive()){
mTimer->singleShot(1000, this, [=]() {
doAction(WINDOW_SCREENSHOT_KEY);
});
}
});
/*area screenshot*/
QAction *aScreenshot= new QAction(this);
aScreenshot->setObjectName(QStringLiteral("Take a screenshot of an area"));
aScreenshot->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(aScreenshot, QList{Qt::SHIFT + Qt::Key_Print});
KGlobalAccel::self()->setShortcut(aScreenshot, QList{Qt::SHIFT + Qt::Key_Print});
connect(aScreenshot, &QAction::triggered, this, [this]() {
if(!mTimer->isActive()){
mTimer->singleShot(1000, this, [=]() {
doAction(AREA_SCREENSHOT_KEY);
});
}
});
/* WLAN */
QAction *wlan= new QAction(this);
wlan->setObjectName(QStringLiteral("Toggle wlan"));
wlan->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(wlan, QList{Qt::Key_WLAN});
KGlobalAccel::self()->setShortcut(wlan, QList{Qt::Key_WLAN});
connect(wlan, &QAction::triggered, this, [this]() {
doAction(WLAN_KEY);
});
/* POWEROFF */
QAction *logout2 = new QAction(this);
logout2->setObjectName(QStringLiteral("open shutdown interface"));
logout2->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(logout2, QList{Qt::Key_PowerOff});
KGlobalAccel::self()->setShortcut(logout2, QList{Qt::Key_PowerOff});
connect(logout2, &QAction::triggered, this, [this]() {
doAction(POWER_OFF_KEY);
});
}
/*shutdown*/
QAction *powerDown= new QAction(this);
powerDown->setObjectName(QStringLiteral("Shut down"));
powerDown->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(powerDown, QList{Qt::Key_PowerDown});
KGlobalAccel::self()->setShortcut(powerDown, QList{Qt::Key_PowerDown});
connect(powerDown, &QAction::triggered, this, [this]() {
USD_LOG(LOG_DEBUG,"press key powerdown !");
doAction(POWER_DOWN_KEY);
});
/*TODO eject*/
QAction *eject= new QAction(this);
eject->setObjectName(QStringLiteral("Eject"));
eject->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(eject, QList{Qt::Key_Eject});
KGlobalAccel::self()->setShortcut(eject, QList{Qt::Key_Eject});
connect(eject, &QAction::triggered, this, [this]() {
doAction(EJECT_KEY);
});
/*home*/
QAction *home= new QAction(this);
home->setObjectName(QStringLiteral("Home folder"));
home->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(home, QList{Qt::Key_Explorer});
KGlobalAccel::self()->setShortcut(home, QList{Qt::Key_Explorer});
connect(home, &QAction::triggered, this, [this]() {
doAction(HOME_KEY);
});
/*media*/
QAction *media= new QAction(this);
media->setObjectName(QStringLiteral("Launch media player"));
media->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(media, QList{Qt::Key_LaunchMedia});
KGlobalAccel::self()->setShortcut(media, QList{Qt::Key_LaunchMedia});
connect(media, &QAction::triggered, this, [this]() {
doAction(MEDIA_KEY);
});
/*calculator*/
QAction *cal= new QAction(this);
cal->setObjectName(QStringLiteral("Open calculator"));
cal->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(cal, QList{Qt::Key_Calculator});
KGlobalAccel::self()->setShortcut(cal, QList{Qt::Key_Calculator});
connect(cal, &QAction::triggered, this, [this]() {
doAction(CALCULATOR_KEY);
});
/*search*/
QAction *search= new QAction(this);
search->setObjectName(QStringLiteral("Open search"));
search->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(search, QList{Qt::Key_Search});
KGlobalAccel::self()->setShortcut(search, QList{Qt::Key_Search});
connect(search, &QAction::triggered, this, [this]() {
doAction(GLOBAL_SEARCH_KEY);
});
/*email*/
QAction *mail= new QAction(this);
mail->setObjectName(QStringLiteral("Launch email client"));
mail->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(mail, QList{Qt::Key_MailForward});
KGlobalAccel::self()->setShortcut(mail, QList{Qt::Key_MailForward});
connect(mail, &QAction::triggered, this, [this]() {
doAction(EMAIL_KEY);
});
if (false == UsdBaseClass::isTablet()) {
/*screensaver*/
QAction *screensaver= new QAction(this);
screensaver->setObjectName(QStringLiteral("Lock screen"));
screensaver->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(screensaver, QList{Qt::CTRL + Qt::ALT + Qt::Key_L});
KGlobalAccel::self()->setShortcut(screensaver, QList{Qt::CTRL + Qt::ALT + Qt::Key_L});
connect(screensaver, &QAction::triggered, this, [this]() {
doAction(SCREENSAVER_KEY);
});
/*peony2*/
QAction *peony2= new QAction(this);
peony2->setObjectName(QStringLiteral("Open File manager "));
peony2->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(peony2, QList{Qt::CTRL + Qt::ALT + Qt::Key_E});
KGlobalAccel::self()->setShortcut(peony2, QList{Qt::CTRL + Qt::ALT + Qt::Key_E});
connect(peony2, &QAction::triggered, this, [this]() {
doAction(FILE_MANAGER_KEY_2);
});
/*terminal*/
QAction *terminal= new QAction(this);
terminal->setObjectName(QStringLiteral("Open terminal"));
terminal->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(terminal, QList{Qt::CTRL + Qt::ALT + Qt::Key_T});
KGlobalAccel::self()->setShortcut(terminal, QList{Qt::CTRL + Qt::ALT + Qt::Key_T});
connect(terminal, &QAction::triggered, this, [this]() {
doAction(TERMINAL_KEY);
});
}
/*screensaver2*/
QAction *screensaver2= new QAction(this);
screensaver2->setObjectName(QStringLiteral("Lock screens"));
screensaver2->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(screensaver2, QList{Qt::META + Qt::Key_L});
KGlobalAccel::self()->setShortcut(screensaver2, QList{Qt::META + Qt::Key_L});
connect(screensaver2, &QAction::triggered, this, [this]() {
doAction(SCREENSAVER_KEY_2);
});
/*ukui-control-center*/
QAction *ukuiControlCenter= new QAction(this);
ukuiControlCenter->setObjectName(QStringLiteral("Open system setting"));
ukuiControlCenter->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(ukuiControlCenter, QList{Qt::META + Qt::Key_I});
KGlobalAccel::self()->setShortcut(ukuiControlCenter, QList{Qt::META + Qt::Key_I});
connect(ukuiControlCenter, &QAction::triggered, this, [this]() {
doAction(SETTINGS_KEY);
});
/*ukui-control-center2*/
QAction *ukuiControlCenter2= new QAction(this);
ukuiControlCenter2->setObjectName(QStringLiteral("Open system settings"));
ukuiControlCenter2->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(ukuiControlCenter2, QList{Qt::Key_Tools});
KGlobalAccel::self()->setShortcut(ukuiControlCenter2, QList{Qt::Key_Tools});
connect(ukuiControlCenter2, &QAction::triggered, this, [this]() {
doAction(SETTINGS_KEY_2);
});
/*peony*/
QAction *peony= new QAction(this);
peony->setObjectName(QStringLiteral("Open file manager"));
peony->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(peony, QList{Qt::META + Qt::Key_E});
KGlobalAccel::self()->setShortcut(peony, QList{Qt::META + Qt::Key_E});
connect(peony, &QAction::triggered, this, [this]() {
doAction(FILE_MANAGER_KEY);
});
/*help*/
QAction *help= new QAction(this);
help->setObjectName(QStringLiteral("Launch help browser"));
help->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(help, QList{Qt::Key_Help});
KGlobalAccel::self()->setShortcut(help, QList{Qt::Key_Help});
connect(help, &QAction::triggered, this, [this]() {
doAction(HELP_KEY);
});
/*www*/
QAction *www= new QAction(this);
www->setObjectName(QStringLiteral("Launch help browser2"));
www->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(www, QList{Qt::Key_WWW});
KGlobalAccel::self()->setShortcut(www, QList{Qt::Key_WWW});
connect(www, &QAction::triggered, this, [this]() {
doAction(WWW_KEY);
});
/*media play*/
QAction *mediaPlay= new QAction(this);
mediaPlay->setObjectName(QStringLiteral("Play/Pause"));
mediaPlay->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(mediaPlay, QList{Qt::Key_MediaPlay});
KGlobalAccel::self()->setShortcut(mediaPlay, QList{Qt::Key_MediaPlay});
connect(mediaPlay, &QAction::triggered, this, [this]() {
doAction(PLAY_KEY);
});
/*media pause*/
QAction *mediaPause= new QAction(this);
mediaPause->setObjectName(QStringLiteral("Pause playback"));
mediaPause->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(mediaPause, QList{Qt::Key_MediaPause});
KGlobalAccel::self()->setShortcut(mediaPause, QList{Qt::Key_MediaPause});
connect(mediaPause, &QAction::triggered, this, [this]() {
doAction(PAUSE_KEY);
});
/*media stop*/
QAction *mediaStop= new QAction(this);
mediaStop->setObjectName(QStringLiteral("Stop playback"));
mediaStop->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(mediaStop, QList{Qt::Key_MediaStop});
KGlobalAccel::self()->setShortcut(mediaStop, QList{Qt::Key_MediaStop});
connect(mediaStop, &QAction::triggered, this, [this]() {
USD_LOG(LOG_DEBUG,"stop_key...");
doAction(STOP_KEY);
});
/*media preious*/
QAction *mediaPre= new QAction(this);
mediaPre->setObjectName(QStringLiteral("Previous track"));
mediaPre->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(mediaPre, QList{Qt::Key_MediaPrevious});
KGlobalAccel::self()->setShortcut(mediaPre, QList{Qt::Key_MediaPrevious});
connect(mediaPre, &QAction::triggered, this, [this]() {
USD_LOG(LOG_DEBUG,"PREVIOUS_KEY...");
doAction(PREVIOUS_KEY);
});
/*media next*/
QAction *mediaNext= new QAction(this);
mediaNext->setObjectName(QStringLiteral("Next track"));
mediaNext->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(mediaNext, QList{Qt::Key_MediaNext});
KGlobalAccel::self()->setShortcut(mediaNext, QList{Qt::Key_MediaNext});
connect(mediaNext, &QAction::triggered, this, [this]() {
doAction(NEXT_KEY);
USD_LOG(LOG_DEBUG,"NEXT_KEY...");
});
/*audio Rewind*/
QAction *audioRewind= new QAction(this);
audioRewind->setObjectName(QStringLiteral("Audio Rewind"));
audioRewind->setProperty("componentName",QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(audioRewind, QList{Qt::Key_AudioRewind});
KGlobalAccel::self()->setShortcut(audioRewind, QList{Qt::Key_AudioRewind});
connect(audioRewind, &QAction::triggered, this, [this]() {
doAction(REWIND_KEY);
});
/*audio Forward*/
QAction *audioForward= new QAction(this);
audioForward->setObjectName(QStringLiteral("Audio Forward"));
audioForward->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(audioForward, QList{Qt::Key_AudioForward});
KGlobalAccel::self()->setShortcut(audioForward, QList{Qt::Key_AudioForward});
connect(audioForward, &QAction::triggered, this, [this]() {
doAction(FORWARD_KEY);
});
/*audio Repeat*/
QAction *audioRepeat= new QAction(this);
audioRepeat->setObjectName(QStringLiteral("Audio Repeat"));
audioRepeat->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(audioRepeat, QList{Qt::Key_AudioRepeat});
KGlobalAccel::self()->setShortcut(audioRepeat, QList{Qt::Key_AudioRepeat});
connect(audioRepeat, &QAction::triggered, this, [this]() {
doAction(REPEAT_KEY);
});
/*audio random*/
QAction *audioRandom= new QAction(this);
audioRandom->setObjectName(QStringLiteral("Audio Random"));
audioRandom->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(audioRandom, QList{Qt::Key_AudioRandomPlay});
KGlobalAccel::self()->setShortcut(audioRandom, QList{Qt::Key_AudioRandomPlay});
connect(audioRandom, &QAction::triggered, this, [this]() {
doAction(RANDOM_KEY);
});
/*TODO magnifier*/
QAction *magnifier= new QAction(this);
magnifier->setObjectName(QStringLiteral("Toggle Magnifier"));
magnifier->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(magnifier, QList{});
KGlobalAccel::self()->setShortcut(magnifier, QList{});
connect(magnifier, &QAction::triggered, this, [this]() {
doAction(MAGNIFIER_KEY);
});
/*TODO screen reader*/
QAction *screenReader= new QAction(this);
screenReader->setObjectName(QStringLiteral("Toggle Screen Reader"));
screenReader->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(screenReader, QList{});
KGlobalAccel::self()->setShortcut(screenReader, QList{});
connect(screenReader, &QAction::triggered, this, [this]() {
doAction(SCREENREADER_KEY);
});
/*TODO on-screen keyboard*/
QAction *onScreenKeyboard= new QAction(this);
onScreenKeyboard->setObjectName(QStringLiteral("Toggle On-screen Keyboard"));
onScreenKeyboard->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(onScreenKeyboard, QList{});
KGlobalAccel::self()->setShortcut(onScreenKeyboard, QList{});
connect(onScreenKeyboard, &QAction::triggered, this, [this]() {
doAction(ON_SCREEN_KEYBOARD_KEY);
});
/*logout*/
QAction *logout= new QAction(this);
logout->setObjectName(QStringLiteral("Open shutdown interface"));
logout->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(logout, QList{Qt::CTRL + Qt::ALT + Qt::Key_Delete});
KGlobalAccel::self()->setShortcut(logout, QList{Qt::CTRL + Qt::ALT + Qt::Key_Delete });
connect(logout, &QAction::triggered, this, [this]() {
doAction(LOGOUT_KEY);
});
QAction *logout1= new QAction(this);
logout1->setObjectName(QStringLiteral("Open shutdown Interface "));
logout1->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(logout1, QList{Qt::CTRL + Qt::ALT + Qt::Key_Period});
KGlobalAccel::self()->setShortcut(logout1, QList{Qt::CTRL + Qt::ALT + Qt::Key_Period });
connect(logout1, &QAction::triggered, this, [this]() {
doAction(LOGOUT_KEY);
});
//sideBar
QAction *sideBar= new QAction(this);
sideBar->setObjectName(QStringLiteral("Open sideBar "));
sideBar->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(sideBar, QList{Qt::META + Qt::Key_A});
KGlobalAccel::self()->setShortcut(sideBar, QList{Qt::META + Qt::Key_A});
connect(sideBar, &QAction::triggered, this, [this]() {
doAction(UKUI_SIDEBAR);
});
/*terminal2*/
QAction *terminal2= new QAction(this);
terminal2->setObjectName(QStringLiteral("Open Terminal"));
terminal2->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(terminal2, QList{Qt::META + Qt::Key_T});
KGlobalAccel::self()->setShortcut(terminal2, QList{Qt::META + Qt::Key_T});
connect(terminal2, &QAction::triggered, this, [this]() {
doAction(TERMINAL_KEY);
});
/*window switch*/
QAction *wSwitch= new QAction(this);
wSwitch->setObjectName(QStringLiteral("open windows switch"));
wSwitch->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(wSwitch, QList{Qt::CTRL + Qt::ALT + Qt::Key_W});
KGlobalAccel::self()->setShortcut(wSwitch, QList{Qt::CTRL + Qt::ALT + Qt::Key_W});
connect(wSwitch, &QAction::triggered, this, [this]() {
doAction(WINDOWSWITCH_KEY);
});
/*window switch2*/
QAction *wSwitch2= new QAction(this);
wSwitch2->setObjectName(QStringLiteral("Open Windows switch"));
wSwitch2->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(wSwitch2, QList{Qt::META + Qt::Key_W});
KGlobalAccel::self()->setShortcut(wSwitch2, QList{Qt::META + Qt::Key_W});
connect(wSwitch2, &QAction::triggered, this, [this]() {
doAction(WINDOWSWITCH_KEY_2);
});
/*system monitor*/
QAction *monitor= new QAction(this);
monitor->setObjectName(QStringLiteral("Open the system monitor"));
monitor->setProperty("componentName", QStringLiteral(UKUI_DAEMON_NAME));
KGlobalAccel::self()->setDefaultShortcut(monitor, QList