summaryrefslogtreecommitdiff
path: root/settings-backend
diff options
context:
space:
mode:
authoronestone <onestone>2006-12-07 00:54:55 +0000
committeronestone <onestone>2006-12-07 00:54:55 +0000
commite02162a4315bc27567a195b3851de10ada6e184f (patch)
treef661d934cbcaf28db2a141cabd82fc17820e6730 /settings-backend
parent367f29f773d711747a76facbf5335cbafda73826 (diff)
downloadaquamarine-e02162a4315bc27567a195b3851de10ada6e184f.tar.gz
aquamarine-e02162a4315bc27567a195b3851de10ada6e184f.tar.bz2
aquamarine: removed kde integration
kconfig-backend: added kde integrated settings reading
Diffstat (limited to 'settings-backend')
-rw-r--r--settings-backend/kconfig_backend.cpp356
1 files changed, 339 insertions, 17 deletions
diff --git a/settings-backend/kconfig_backend.cpp b/settings-backend/kconfig_backend.cpp
index 8e900be..a4154ec 100644
--- a/settings-backend/kconfig_backend.cpp
+++ b/settings-backend/kconfig_backend.cpp
@@ -1,9 +1,3 @@
-#include <kconfig.h>
-#include <ksimpleconfig.h>
-#include <kdebug.h>
-#include <kinstance.h>
-#include <stdlib.h>
-
/*
* Aquamarine the KDE window decorator
*
@@ -25,6 +19,13 @@
*
*/
+#include <kconfig.h>
+#include <ksimpleconfig.h>
+#include <kdebug.h>
+#include <kinstance.h>
+#include <kshortcut.h>
+#include <stdlib.h>
+
extern "C" {
#include <beryl-settings-backend.h>
}
@@ -42,9 +43,300 @@ const static char *edgeName[] = {
"BottomRight"
};
+const static char *fspLevel[] = {
+ "None",
+ "Low",
+ "Normal",
+ "High",
+ "Extreme"
+};
+
+typedef struct _ConfigFiles {
+ KSimpleConfig *beryl;
+ KConfig *kwin;
+ KConfig *global;
+} ConfigFiles;
+
+typedef enum {
+ OptionInt,
+ OptionBool,
+ OptionKey,
+ OptionSpecial
+} SpecialOptionType;
+
+struct _SpecialOption {
+ QString berylName;
+ QString berylPlugin;
+ QString kdeName;
+ bool global;
+ SpecialOptionType type;
+} const specialOptions[] = {
+ {"close_window", NULL, "Window Close", true, OptionKey},
+ {"run", NULL, "Run Command", true, OptionKey},
+ {"main_menu", NULL, "Popup Launch Menu", true, OptionKey},
+ {"lower_window", NULL, "Window Lower", true, OptionKey},
+ {"toggle_window_maximized", NULL, "Window Maximize", true, OptionKey},
+ {"minimize_window", NULL, "Window Minimize", true, OptionKey},
+ {"toggle_maximize_window_horizontally", NULL, "Window Maximize Horizontal", true, OptionKey},
+ {"toggle_maximize_window_vertically", NULL, "Window Maximize Vertical", true, OptionKey},
+ {"show_desktop", NULL, "Toggle Showing Desktop", true, OptionKey},
+ {"run_command_screenshot", NULL, "Desktop Screenshot", true, OptionKey},
+ {"run_command_window_screenshot", NULL, "Window Screenshot", true, OptionKey},
+ {"window_menu", NULL, "Window Operations Menu", true, OptionKey},
+ {"toggle_window_shaded", NULL, "Window Shade", true, OptionKey},
+ {"raise_window", NULL, "Window Raise", true, OptionKey},
+ {"toggle_window_fullscreen", NULL, "Window Fullscreen", true, OptionKey},
+ {"run_command11", NULL, "Kill Window", true, OptionKey},
+ {"initiate", "move", "Window Move", true, OptionKey},
+ {"initiate", "resize", "Window Resize", true, OptionKey},
+ {"rotate_right", "rotate", "Switch to Next Desktop", true, OptionKey},
+ {"rotate_left", "rotate", "Switch to Previous Desktop", true, OptionKey},
+ {"rotate_to_1", "rotate", "Switch to Desktop 1", true, OptionKey},
+ {"rotate_to_2", "rotate", "Switch to Desktop 2", true, OptionKey},
+ {"rotate_to_3", "rotate", "Switch to Desktop 3", true, OptionKey},
+ {"rotate_to_4", "rotate", "Switch to Desktop 4", true, OptionKey},
+ {"rotate_to_5", "rotate", "Switch to Desktop 5", true, OptionKey},
+ {"rotate_to_6", "rotate", "Switch to Desktop 6", true, OptionKey},
+ {"rotate_to_7", "rotate", "Switch to Desktop 7", true, OptionKey},
+ {"rotate_to_8", "rotate", "Switch to Desktop 8", true, OptionKey},
+ {"rotate_to_9", "rotate", "Switch to Desktop 9", true, OptionKey},
+ {"rotate_to_10", "rotate", "Switch to Desktop 10", true, OptionKey},
+ {"rotate_to_11", "rotate", "Switch to Desktop 11", true, OptionKey},
+ {"rotate_to_12", "rotate", "Switch to Desktop 12", true, OptionKey},
+
+ {"rotate_right_window", "rotate", "Window to Next Desktop", true, OptionKey},
+ {"rotate_left_window", "rotate", "Window to Previous Desktop", true, OptionKey},
+ {"rotate_to_1_window", "rotate", "Window to Desktop 1", true, OptionKey},
+ {"rotate_to_2_window", "rotate", "Window to Desktop 2", true, OptionKey},
+ {"rotate_to_3_window", "rotate", "Window to Desktop 3", true, OptionKey},
+ {"rotate_to_4_window", "rotate", "Window to Desktop 4", true, OptionKey},
+ {"rotate_to_5_window", "rotate", "Window to Desktop 5", true, OptionKey},
+ {"rotate_to_6_window", "rotate", "Window to Desktop 6", true, OptionKey},
+ {"rotate_to_7_window", "rotate", "Window to Desktop 7", true, OptionKey},
+ {"rotate_to_8_window", "rotate", "Window to Desktop 8", true, OptionKey},
+ {"rotate_to_9_window", "rotate", "Window to Desktop 9", true, OptionKey},
+ {"rotate_to_10_window", "rotate", "Window to Desktop 10", true, OptionKey},
+ {"rotate_to_11_window", "rotate", "Window to Desktop 11", true, OptionKey},
+ {"rotate_to_12_window", "rotate", "Window to Desktop 12", true, OptionKey},
+
+ {"plane_up", "plane", "Switch One Desktop Up", true, OptionKey},
+ {"plane_down", "plane", "Switch One Desktop Down", true, OptionKey},
+ {"plane_left", "plane", "Switch One Desktop to the Left", true, OptionKey},
+ {"plane_right", "plane", "Switch One Desktop to the Right", true, OptionKey},
+
+ {"plane_to_1", "plane", "Switch to Desktop 1", true, OptionKey},
+ {"plane_to_2", "plane", "Switch to Desktop 2", true, OptionKey},
+ {"plane_to_3", "plane", "Switch to Desktop 3", true, OptionKey},
+ {"plane_to_4", "plane", "Switch to Desktop 4", true, OptionKey},
+ {"plane_to_5", "plane", "Switch to Desktop 5", true, OptionKey},
+ {"plane_to_6", "plane", "Switch to Desktop 6", true, OptionKey},
+ {"plane_to_7", "plane", "Switch to Desktop 7", true, OptionKey},
+ {"plane_to_8", "plane", "Switch to Desktop 8", true, OptionKey},
+ {"plane_to_9", "plane", "Switch to Desktop 9", true, OptionKey},
+ {"plane_to_10", "plane", "Switch to Desktop 10", true, OptionKey},
+ {"plane_to_11", "plane", "Switch to Desktop 11", true, OptionKey},
+ {"plane_to_12", "plane", "Switch to Desktop 12", true, OptionKey},
+
+ {"next", "switcher", "Walk Through Windows", true, OptionKey},
+ {"prev", "switcher", "Walk Through Windows (Reverse)", true, OptionKey},
+
+ {"autoraise", NULL, "AutoRaise", false, OptionBool},
+ {"raise_on_click", NULL, "ClickRaise", false, OptionBool},
+ {"snapoff_maximized", "move", "MoveResizeMaximizedWindows", false, OptionBool},
+
+ {"autoraise_delay", NULL, "AutoRaiseInterval", false, OptionInt},
+
+ {"command_screenshot", NULL, NULL, true, OptionSpecial},
+ {"command_window_screenshot", NULL, NULL, true, OptionSpecial},
+ {"unmaximize_window", NULL, NULL, true, OptionSpecial},
+ {"maximize_window", NULL, NULL, true, OptionSpecial},
+ {"maximize_window_horizontally", NULL, NULL, true, OptionSpecial},
+ {"maximize_window_vertically", NULL, NULL, true, OptionSpecial},
+ {"command11", NULL, NULL, true, OptionSpecial},
+ {"click_to_focus", NULL, NULL, false, OptionSpecial},
+ {"focus_stealing_prevention_level", NULL, NULL, false, OptionSpecial},
+ {"number_of_desktops", NULL, "Number", false, OptionSpecial},
+ {"resize_mode", "resize", NULL, true, OptionSpecial},
+};
+
+#define N_SOPTIONS (sizeof (specialOptions) / sizeof (struct _SpecialOption))
+
+static bool isIntegratedOption(BerylSetting * setting)
+{
+
+ for (unsigned int i = 0; i < N_SOPTIONS; i++)
+ {
+ if (setting->name == specialOptions[i].berylName &&
+ QString(setting->parent->name) == specialOptions[i].berylPlugin)
+ return true;
+ }
+ return false;
+}
+
+static void KdeIntToBeryl (ConfigFiles *cFiles, BerylSetting * setting, int num)
+{
+ KConfig *cfg = (specialOptions[num].global)?cFiles->global:cFiles->kwin;
+
+ int val = cfg->readNumEntry(specialOptions[num].kdeName);
+
+ beryl_setting_value_set_int(&setting->value,&val);
+}
+
+static void KdeBoolToBeryl (ConfigFiles *cFiles, BerylSetting * setting, int num)
+{
+ KConfig *cfg = (specialOptions[num].global)?cFiles->global:cFiles->kwin;
+
+ Bool val = (cfg->readBoolEntry(specialOptions[num].kdeName))?TRUE:FALSE;
+
+ beryl_setting_value_set_bool(&setting->value,&val);
+}
+
+static void KdeKeyToBeryl (ConfigFiles *cFiles, BerylSetting * setting, int num)
+{
+ KConfig *cfg = (specialOptions[num].global)?cFiles->global:cFiles->kwin;
+
+ KKey key(cfg->readEntry(specialOptions[num].kdeName));
+
+ gboolean kde_enabled = !key.isNull();
+
+ int kde_keysym = key.sym();
+ int kde_keymod = 0;
+
+ if (key.modFlags() & KKey::SHIFT)
+ kde_keymod |= ShiftMask;
+ if (key.modFlags() & KKey::CTRL)
+ kde_keymod |= ControlMask;
+ if (key.modFlags() & KKey::ALT)
+ kde_keymod |= CompAltMask;
+ if (key.modFlags() & KKey::WIN)
+ kde_keymod |= CompSuperMask;
+
+
+ if (kde_enabled)
+ {
+ beryl_setting_value_set_keysym(&setting->value,&kde_keysym);
+ beryl_setting_value_set_keymods(&setting->value,&kde_keymod);
+ beryl_setting_value_set_key_enabled(&setting->value,&kde_enabled);
+ }
+ else
+ {
+ char * sval = NULL;
+ if (cFiles->beryl->hasKey(specialOptions[num].berylName + "_key (Integrated)"))
+ sval = strdup(cFiles->beryl->readEntry(specialOptions[num].berylName + "_key (Integrated)").ascii());
+
+ int keysym = 0;
+ int keymods = 0;
+ gchar * spos = NULL;
+ if (sval) keymods = beryl_settings_get_mods_and_endptr(sval,&spos);
+ if (spos && *spos)
+ {
+ keysym=XStringToKeysym(spos);
+ }
+ beryl_setting_value_set_keysym(&setting->value,&keysym);
+ beryl_setting_value_set_keymods(&setting->value,&keymods);
+ beryl_setting_value_set_key_enabled(&setting->value,&kde_enabled);
+ delete sval;
+ }
+}
+
+static void readIntegratedOption(ConfigFiles *cFiles, BerylSetting * setting)
+{
+ int option = 0;
+ for (unsigned int i = 0; i < N_SOPTIONS; i++)
+ {
+ if (setting->name == specialOptions[i].berylName &&
+ QString(setting->parent->name) == specialOptions[i].berylPlugin)
+ {
+ option = i;
+ break;
+ }
+ }
+ setting->is_default=FALSE;
+ switch (specialOptions[option].type)
+ {
+ case OptionInt:
+ KdeIntToBeryl (cFiles, setting, option);
+ break;
+ case OptionBool:
+ KdeBoolToBeryl (cFiles, setting, option);
+ break;
+ case OptionKey:
+ KdeKeyToBeryl (cFiles, setting, option);
+ break;
+ case OptionSpecial:
+ if (specialOptions[option].berylName == "command_screenshot")
+ {
+ setting->value.value.as_string =
+ g_strdup("ksnapshot");
+ }
+ if (specialOptions[option].berylName == "command_window_screenshot")
+ {
+ setting->value.value.as_string =
+ g_strdup("ksnapshot -c");
+ }
+ if (specialOptions[option].berylName == "command11")
+ {
+ setting->value.value.as_string =
+ g_strdup("xkill");
+ }
+ if (specialOptions[option].berylName == "unmaximize_window"
+ || specialOptions[option].berylName == "maximize_window"
+ || specialOptions[option].berylName == "maximize_window_horizontally"
+ || specialOptions[option].berylName == "maximize_window_vertically")
+ {
+ int val = 0;
+ beryl_setting_value_set_keysym(&setting->value,&val);
+ beryl_setting_value_set_keymods(&setting->value,&val);
+ beryl_setting_value_set_key_enabled(&setting->value,&val);
+ }
+ if (specialOptions[option].berylName == "click_to_focus")
+ {
+ setting->value.value.as_string = g_strdup("xkill");
+ }
+ if (specialOptions[option].berylName == "focus_stealing_prevention_level")
+ {
+ int level = cFiles->kwin->readNumEntry("FocusStealingPreventionLevel");
+ level = MAX(0,MIN(4,level));
+ setting->value.value.as_string = g_strdup(fspLevel[level]);
+ }
+ if (specialOptions[option].berylName == "number_of_desktops")
+ {
+ cFiles->kwin->setGroup("Desktops");
+ KdeIntToBeryl (cFiles, setting, option);
+ cFiles->kwin->setGroup("Windows");
+ }
+ if (specialOptions[option].berylName == "resize_mode")
+ {
+ QString mode = cFiles->kwin->readEntry("ResizeMode");
+ QString imode;
+ QString result = "Normal";
+ if (cFiles->beryl->hasKey(specialOptions[option].berylName + " (Integrated)"))
+ imode = cFiles->beryl->readEntry(specialOptions[option].berylName + " (Integrated)");
+
+ if (mode == "Opaque")
+ {
+ result = "Normal";
+ if (imode == "Stretch")
+ result = "Stretch";
+ }
+ else if (mode == "Transparent")
+ {
+ result = "Outline";
+ if (imode == "Filled Outline")
+ result = "Filled Outline";
+ }
+ setting->value.value.as_string = g_strdup(result.ascii());
+ }
+ break;
+ default:
+ break;
+ }
+}
+
void read_setting(BerylSettingsContext * c, BerylSetting * setting)
{
- KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+ ConfigFiles *cFiles = (ConfigFiles *)c->backend_private_ptr;
+ KSimpleConfig *cfg = cFiles->beryl;
QString key(setting->name);
QString group(setting->parent->name);
@@ -52,6 +344,12 @@ void read_setting(BerylSettingsContext * c, BerylSetting * setting)
group += "_screen0";
cfg->setGroup(group);
+ if (isIntegratedOption(setting))
+ {
+ readIntegratedOption(cFiles, setting);
+ return;
+ }
+
if (setting->type != BERYL_SETTING_TYPE_BINDING && !cfg->hasKey(key))
return;
@@ -350,7 +648,8 @@ static void copy_color(BerylSettingValue * value, QStringList *list)
void write_setting(BerylSettingsContext * c, BerylSetting * setting)
{
- KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+ ConfigFiles *cFiles = (ConfigFiles *)c->backend_private_ptr;
+ KSimpleConfig *cfg = cFiles->beryl;
QString key(setting->name);
QString group(setting->parent->name);
@@ -358,6 +657,11 @@ void write_setting(BerylSettingsContext * c, BerylSetting * setting)
group += "_screen0";
cfg->setGroup(group);
+ if (isIntegratedOption(setting))
+ {
+ return;
+ }
+
if (setting->is_default)
{
if (cfg->hasKey(key))
@@ -523,16 +827,25 @@ gboolean read_init(BerylSettingsContext * c)
if (!instance)
instance = new KInstance("beryl-kconfig");
- KSimpleConfig *cfg = new KSimpleConfig("berylrc",true);
- c->backend_private_ptr=(void *)cfg;
+ ConfigFiles *cFiles = new ConfigFiles;
+ cFiles->beryl = new KSimpleConfig("berylrc",true);
+ cFiles->kwin = new KConfig("kwinrc",true);
+ cFiles->global = new KConfig("kdeglobals",true);
+ cFiles->kwin->setGroup("Windows");
+ cFiles->global->setGroup("Global Shortcuts");
+
+ c->backend_private_ptr=(void *)cFiles;
return TRUE;
}
void read_done(BerylSettingsContext * c)
{
- KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+ ConfigFiles *cFiles = (ConfigFiles *)c->backend_private_ptr;
+ delete cFiles->beryl;
+ delete cFiles->kwin;
+ delete cFiles->global;
+ delete cFiles;
c->backend_private_ptr=NULL;
- delete cfg;
}
gboolean write_init(BerylSettingsContext * c)
@@ -540,17 +853,26 @@ gboolean write_init(BerylSettingsContext * c)
if (!instance)
instance = new KInstance("beryl-kconfig");
- KSimpleConfig *cfg = new KSimpleConfig("berylrc");
- c->backend_private_ptr=(void *)cfg;
+ ConfigFiles *cFiles = new ConfigFiles;
+ cFiles->beryl = new KSimpleConfig("berylrc");
+ cFiles->kwin = new KConfig("kwinrc");
+ cFiles->global = new KConfig("kdeglobals");
+ cFiles->kwin->setGroup("Windows");
+ cFiles->global->setGroup("Global Shortcuts");
+
+ c->backend_private_ptr=(void *)cFiles;
return TRUE;
}
void write_done(BerylSettingsContext * c)
{
- KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+ ConfigFiles *cFiles = (ConfigFiles *)c->backend_private_ptr;
+ cFiles->beryl->sync();
+ delete cFiles->beryl;
+ delete cFiles->kwin;
+ delete cFiles->global;
+ delete cFiles;
c->backend_private_ptr=NULL;
- cfg->sync();
- delete cfg;
}