diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ddd099120d509bb7fbcc6ed5fae349b3286c43a..3989f1d74a9f8ec366e221937d6be443eb0b3cd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${COMPIZ_CMAKE_MODULE_PATH}) include (CTest) +set (MEMORYCHECK_COMMAND_OPTIONS --trace-children=yes) set (MEMORYCHECK_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR}/tests/experimental-memcheck/compiz.supp CACHE FILEPATH "" FORCE) include (Dart) diff --git a/cmake/CompizCommon.cmake b/cmake/CompizCommon.cmake index f2f93be39a9e371c6e237824edab2110fb1aaeeb..d1e339b473913ea2e90e2be0d84ab5b7084264c9 100644 --- a/cmake/CompizCommon.cmake +++ b/cmake/CompizCommon.cmake @@ -457,14 +457,29 @@ function (compiz_translate_xml _src _dst) find_program (INTLTOOL_MERGE_EXECUTABLE intltool-merge) mark_as_advanced (FORCE INTLTOOL_MERGE_EXECUTABLE) + set (_additional_arg + -x + -u + ${COMPIZ_I18N_DIR}) + + foreach (_arg ${ARGN}) + if ("${_arg}" STREQUAL "NOTRANSLATIONS") + set (_additional_arg + --no-translations + -x + -u) + endif ("${_arg}" STREQUAL "NOTRANSLATIONS") + endforeach (_arg ${ARGN}) + if (INTLTOOL_MERGE_EXECUTABLE AND COMPIZ_I18N_DIR AND EXISTS ${COMPIZ_I18N_DIR}) add_custom_command ( OUTPUT ${_dst} - COMMAND ${INTLTOOL_MERGE_EXECUTABLE} -x -u -c + COMMAND ${INTLTOOL_MERGE_EXECUTABLE} + -c ${CMAKE_BINARY_DIR}/.intltool-merge-cache - ${COMPIZ_I18N_DIR} + ${_additional_arg} ${_src} ${_dst} DEPENDS ${_src} diff --git a/compizconfig/CMakeLists.txt b/compizconfig/CMakeLists.txt index 939aa0178b9f4c33f0403fb05055d1ebe0f63ab3..10446e73a50bd10795c8b70f684b65d1f7037ec7 100644 --- a/compizconfig/CMakeLists.txt +++ b/compizconfig/CMakeLists.txt @@ -4,11 +4,24 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LIBCOMPIZCONFIG_CMAKE_MODULE_PATH} set (COMPIZCONFIG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/libcompizconfig/include) set (COMPIZCONFIG_LIBRARY_DIRS ${CMAKE_CURRENT_BINARY_DIR}/libcompizconfig) +option (USE_GCONF "Enable legacy GNOME 2.x option integration with GConf" ON) + add_subdirectory (libcompizconfig) add_subdirectory (compizconfig-python) +add_subdirectory (integration) add_subdirectory (ccsm) -add_subdirectory (gconf) -add_subdirectory (gsettings) + +if (USE_GCONF) + add_subdirectory (gconf) +endif (USE_GCONF) + +if (USE_GSETTINGS) + add_subdirectory (gsettings) +endif (USE_GSETTINGS) + +if (COMPIZ_BUILD_TESTING) + add_subdirectory (mocks) +endif (COMPIZ_BUILD_TESTING) add_custom_target (pyclean) diff --git a/compizconfig/compizconfig-python/CMakeLists.txt b/compizconfig/compizconfig-python/CMakeLists.txt index 98bd4a86b4385858a321602f20939d7fb3e1e2fc..9614d98ad5523cbffd0b91d45df2847a02852edf 100644 --- a/compizconfig/compizconfig-python/CMakeLists.txt +++ b/compizconfig/compizconfig-python/CMakeLists.txt @@ -62,17 +62,25 @@ add_dependencies (compizconfig_wrapper compizconfig) if (COMPIZ_BUILD_TESTING) + find_program (BASH_EXECUTABLE bash) find_program (PYTHON_EXECUTABLE python) mark_as_advanced (FORCE PYTHON_EXECUTABLE) file (GLOB PYTHON_TESTS "tests/test_*.py") - if (PYTHON_EXECUTABLE) + if (PYTHON_EXECUTABLE AND + BASH_EXECUTABLE) foreach (PYTHON_TEST_FILE ${PYTHON_TESTS}) get_filename_component (PYTHON_TEST ${PYTHON_TEST_FILE} NAME_WE) message (STATUS "Adding test " ${PYTHON_TEST}) - add_test (NAME CompizConfigPython.${PYTHON_TEST} WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_TEST_FILE}) + add_test (NAME CompizConfigPython.${PYTHON_TEST} + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" + COMMAND ${BASH_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/tests/util/run_with_ld_library_path.sh + ${CMAKE_BINARY_DIR}/compizconfig/libcompizconfig/src + ${PYTHON_EXECUTABLE} ${PYTHON_TEST_FILE}) endforeach (PYTHON_TEST_FILE) - endif (PYTHON_EXECUTABLE) + endif (PYTHON_EXECUTABLE AND + BASH_EXECUTABLE) endif (COMPIZ_BUILD_TESTING) diff --git a/compizconfig/compizconfig-python/setup.py b/compizconfig/compizconfig-python/setup.py index 27cd5ced78054bbf297604c28969d50e1d3ba978..fd4414f7e2eb1b75a577714a24e1225e78bd190b 100644 --- a/compizconfig/compizconfig-python/setup.py +++ b/compizconfig/compizconfig-python/setup.py @@ -31,8 +31,6 @@ def pkgconfig(*packages, **kw): for t in tokens: if '-L' in t[:2]: kw.setdefault (flag_map.get ("-L"), []).append (t[2:]) - if not os.getenv ("COMPIZ_DISABLE_RPATH") is "1": - kw.setdefault (flag_map.get ("-R"), []).append (t[2:]) elif '-I' in t[:2]: kw.setdefault (flag_map.get ("-I"), []).append (t[2:]) elif '-l' in t[:2]: diff --git a/compizconfig/compizconfig-python/src/compizconfig.pyx b/compizconfig/compizconfig-python/src/compizconfig.pyx index b580fe8064a1ed43407ebb275432b6ed794fa643..b90df988fb5f8c8f37468ff3e52b059d3e3b3d66 100644 --- a/compizconfig/compizconfig-python/src/compizconfig.pyx +++ b/compizconfig/compizconfig-python/src/compizconfig.pyx @@ -315,7 +315,7 @@ cdef extern void ccsSetProfile (CCSContext * context, char * name) cdef extern char* ccsGetProfile (CCSContext * context) '''Backends''' -cdef extern CCSBackendInfoList * ccsGetExistingBackends () +cdef extern CCSBackendInfoList * ccsGetExistingBackends (CCSContext *) cdef extern void ccsBackendInfoListFree (CCSBackendInfoList *, Bool freeObj) cdef extern Bool ccsSetBackend (CCSContext * context, char * name) cdef extern char* ccsGetBackend (CCSContext * context) @@ -603,6 +603,13 @@ cdef object DecodeValue (CCSSettingValue * value): return "Unhandled" cdef class Setting: + """A python representation of a CCSSetting. + + You should not construct this object directly. + Use plugin.Screen['settingname'] instead + + """ + cdef CCSSetting * ccsSetting cdef object info cdef Plugin plugin @@ -723,6 +730,13 @@ cdef class SSGroup: self.screen = value cdef class Plugin: + """A python representation of a CCSPlugin. + + You should not construct this object directly. + Use context.Plugins['pluginname'] instead + + """ + cdef CCSPlugin * ccsPlugin cdef Context context cdef object screen @@ -1104,6 +1118,19 @@ cdef class Backend: return self.profileSupport cdef class Context: + """A python representation of a CCSContext. + + This is the main entry-point into the compizconfig module. + Typical usage: + + >>> context = Context() + >>> plugin = context.Plugins['core'] + >>> setting = plugin.Screen['number_of_desktops'] + >>> print setting.Value + 1 + + """ + cdef CCSContext * ccsContext cdef object plugins cdef object categories @@ -1207,7 +1234,7 @@ cdef class Context: cdef CCSBackendInfoList * backendList cdef CCSBackendInfoList * origBackendList cdef CCSBackendInfo * backendInfo - origBackendList = backendList = ccsGetExistingBackends () + origBackendList = backendList = ccsGetExistingBackends (self.ccsContext) while backendList != NULL: backendInfo = backendList.data info = (backendInfo.name, backendInfo.shortDesc, diff --git a/compizconfig/compizconfig-python/tests/compiz_config_test.py b/compizconfig/compizconfig-python/tests/compiz_config_test.py index 56205be725da3f8f1cbd0e0b81f0d9e01284db69..d211c93ae3005e09a021c6a5716c41e059e4baf6 100644 --- a/compizconfig/compizconfig-python/tests/compiz_config_test.py +++ b/compizconfig/compizconfig-python/tests/compiz_config_test.py @@ -1,16 +1,16 @@ import os +import sys +import subprocess + +arch = subprocess.Popen (["uname", "-p"], stdout=subprocess.PIPE).communicate ()[0][:-1] os.environ["G_SLICE"] = "always-malloc" -os.environ["COMPIZ_CONFIG_PROFILE"] = "" os.environ["COMPIZ_METADATA_PATH"] = "generated/" +os.environ["COMPIZ_CONFIG_PROFILE"] = "" +os.environ["XDG_CONFIG_HOME"] = "compizconfig/libcompizconfig/config" os.environ["LIBCOMPIZCONFIG_BACKEND_PATH"] = "compizconfig/libcompizconfig/backend/" os.environ["XDG_DATA_DIRS"] = "generated/" -import sys -import subprocess - -arch = subprocess.Popen (["uname", "-p"], stdout=subprocess.PIPE).communicate ()[0][:-1] - sys.path.insert (0, "compizconfig/compizconfig-python/build/lib.linux-%s-%s.%s/" % (arch, sys.version_info[0], sys.version_info[1])) import unittest diff --git a/compizconfig/gconf/CMakeLists.txt b/compizconfig/gconf/CMakeLists.txt index 7df81939f32e76d9e8e18eefbef7b7f36e2fd852..c8fa4025f6ba351bee2322d3d258be6ebd375fac 100644 --- a/compizconfig/gconf/CMakeLists.txt +++ b/compizconfig/gconf/CMakeLists.txt @@ -1,7 +1,16 @@ -project (compizconfig-backend-gconf) +if (USE_GCONF) -find_package (CompizConfig REQUIRED) + find_package (CompizConfig REQUIRED) -include (LibCompizConfigCommon) + include (LibCompizConfigCommon) -compizconfig_backend (gconf PKGDEPS glib-2.0 gconf-2.0) + include_directories (${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/include + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/gconf/include) + link_directories (${CMAKE_BINARY_DIR}/compizconfig/integration/gnome + ${CMAKE_BINARY_DIR}/compizconfig/integration/gnome/gconf) + + compizconfig_backend (gconf PKGDEPS glib-2.0 gconf-2.0 LIBRARIES + compizconfig_gnome_integration + compizconfig_gnome_integration_gconf_setting_factory + compizconfig_gnome_integration_gconf_integrated_setting) +endif (USE_GCONF) diff --git a/compizconfig/gconf/src/gconf.c b/compizconfig/gconf/src/gconf.c index e730231f9635b37ebd3586c20e507fe06c2bab2f..7eb8dc6faa9c767050de37207678c97da60b5d5b 100644 --- a/compizconfig/gconf/src/gconf.c +++ b/compizconfig/gconf/src/gconf.c @@ -44,15 +44,9 @@ #include #include -#define CompAltMask (1 << 16) -#define CompMetaMask (1 << 17) -#define CompSuperMask (1 << 18) -#define CompHyperMask (1 << 19) -#define CompModeSwitchMask (1 << 20) -#define CompNumLockMask (1 << 21) -#define CompScrollLockMask (1 << 22) - -#define METACITY "/apps/metacity" +#include "ccs_gnome_integration.h" +#include "ccs_gnome_integration_gconf_integrated_setting_factory.h" + #define COMPIZ "/apps/compiz-1" #define COMPIZCONFIG "/apps/compizconfig-1" #define PROFILEPATH COMPIZCONFIG "/profiles" @@ -75,364 +69,54 @@ "%s/plugins/%s/%s/options/%s", COMPIZ, \ ccsPluginGetName (ccsSettingGetParent (setting)), keyName, ccsSettingGetName (setting)); -static const char* watchedGnomeDirectories[] = { - METACITY, - "/desktop/gnome/applications/terminal", - "/apps/panel/applets/window_list/prefs" -}; -#define NUM_WATCHED_DIRS 3 - static GConfClient *client = NULL; static GConfEngine *conf = NULL; static guint compizNotifyId; -static guint gnomeNotifyIds[NUM_WATCHED_DIRS]; static char *currentProfile = NULL; +static CCSGNOMEValueChangeData valueChangeData = +{ + NULL, + NULL, + NULL, + NULL +}; /* some forward declarations */ -static Bool readInit (CCSContext * context); -static void readSetting (CCSContext * context, CCSSetting * setting); +static Bool readInit (CCSBackend *backend, CCSContext * context); +static void readSetting (CCSBackend *backend, CCSContext * context, CCSSetting * setting); static Bool readOption (CCSSetting * setting); -static Bool writeInit (CCSContext * context); -static void writeIntegratedOption (CCSContext *context, CCSSetting *setting, - int index); - -typedef enum { - OptionInt, - OptionBool, - OptionKey, - OptionBell, - OptionString, - OptionSpecial, -} SpecialOptionType; - -typedef struct _SpecialOption { - const char* settingName; - const char* pluginName; - Bool screen; - const char* gnomeName; - SpecialOptionType type; -} SpecialOption; - -const SpecialOption specialOptions[] = { - {"run_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/panel_run_dialog", OptionKey}, - {"main_menu_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/panel_main_menu", OptionKey}, - {"run_command_screenshot_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/run_command_screenshot", OptionKey}, - {"run_command_window_screenshot_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/run_command_window_screenshot", OptionKey}, - {"run_command_terminal_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/run_command_terminal", OptionKey}, - - {"toggle_window_maximized_key", "core", FALSE, - METACITY "/window_keybindings/toggle_maximized", OptionKey}, - {"minimize_window_key", "core", FALSE, - METACITY "/window_keybindings/minimize", OptionKey}, - {"maximize_window_key", "core", FALSE, - METACITY "/window_keybindings/maximize", OptionKey}, - {"unmaximize_window_key", "core", FALSE, - METACITY "/window_keybindings/unmaximize", OptionKey}, - {"maximize_window_horizontally_key", "core", FALSE, - METACITY "/window_keybindings/maximize_horizontally", OptionKey}, - {"maximize_window_vertically_key", "core", FALSE, - METACITY "/window_keybindings/maximize_vertically", OptionKey}, - {"raise_window_key", "core", FALSE, - METACITY "/window_keybindings/raise", OptionKey}, - {"lower_window_key", "core", FALSE, - METACITY "/window_keybindings/lower", OptionKey}, - {"close_window_key", "core", FALSE, - METACITY "/window_keybindings/close", OptionKey}, - {"toggle_window_shaded_key", "core", FALSE, - METACITY "/window_keybindings/toggle_shaded", OptionKey}, - - {"show_desktop_key", "core", FALSE, - METACITY "/global_keybindings/show_desktop", OptionKey}, - - {"initiate_key", "move", FALSE, - METACITY "/window_keybindings/begin_move", OptionKey}, - {"initiate_key", "resize", FALSE, - METACITY "/window_keybindings/begin_resize", OptionKey}, - {"window_menu_key", "core", FALSE, - METACITY "/window_keybindings/activate_window_menu", OptionKey}, - - /* integration of Metacity's mouse_button_modifier option */ - {"initiate_button", "move", FALSE, - METACITY "/window_keybindings/begin_move", OptionSpecial}, - {"initiate_button", "resize", FALSE, - METACITY "/window_keybindings/begin_resize", OptionSpecial}, - {"window_menu_button", "core", FALSE, - METACITY "/window_keybindings/activate_window_menu", OptionSpecial}, - {"mouse_button_modifier", NULL, FALSE, - METACITY "/general/mouse_button_modifier", OptionSpecial}, - /* integration of the Metacity's option to swap mouse buttons */ - {"resize_with_right_button", NULL, FALSE, - METACITY "/general/resize_with_right_button", OptionSpecial}, - - {"visual_bell", "fade", TRUE, - METACITY "/general/visual_bell", OptionBell}, - {"fullscreen_visual_bell", "fade", TRUE, - METACITY "/general/visual_bell_type", OptionSpecial}, - - {"next_key", "staticswitcher", FALSE, - METACITY "/global_keybindings/switch_windows", OptionKey}, - {"prev_key", "staticswitcher", FALSE, - METACITY "/global_keybindings/switch_windows_backward", OptionKey}, - - {"toggle_sticky_key", "extrawm", FALSE, - METACITY "/window_keybindings/toggle_on_all_workspaces", OptionKey}, - {"toggle_fullscreen_key", "extrawm", FALSE, - METACITY "/window_keybindings/toggle_fullscreen", OptionKey}, - - {"command0", "commands", FALSE, - METACITY "/keybinding_commands/command_1", OptionString}, - {"command1", "commands", FALSE, - METACITY "/keybinding_commands/command_2", OptionString}, - {"command2", "commands", FALSE, - METACITY "/keybinding_commands/command_3", OptionString}, - {"command3", "commands", FALSE, - METACITY "/keybinding_commands/command_4", OptionString}, - {"command4", "commands", FALSE, - METACITY "/keybinding_commands/command_5", OptionString}, - {"command5", "commands", FALSE, - METACITY "/keybinding_commands/command_6", OptionString}, - {"command6", "commands", FALSE, - METACITY "/keybinding_commands/command_7", OptionString}, - {"command7", "commands", FALSE, - METACITY "/keybinding_commands/command_8", OptionString}, - {"command8", "commands", FALSE, - METACITY "/keybinding_commands/command_9", OptionString}, - {"command9", "commands", FALSE, - METACITY "/keybinding_commands/command_10", OptionString}, - {"command10", "commands", FALSE, - METACITY "/keybinding_commands/command_11", OptionString}, - {"command11", "commands", FALSE, - METACITY "/keybinding_commands/command_12", OptionString}, - - {"run_command0_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_1", OptionKey}, - {"run_command1_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_2", OptionKey}, - {"run_command2_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_3", OptionKey}, - {"run_command3_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_4", OptionKey}, - {"run_command4_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_5", OptionKey}, - {"run_command5_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_6", OptionKey}, - {"run_command6_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_7", OptionKey}, - {"run_command7_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_8", OptionKey}, - {"run_command8_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_9", OptionKey}, - {"run_command9_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_10", OptionKey}, - {"run_command10_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_11", OptionKey}, - {"run_command11_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_12", OptionKey}, - - {"rotate_to_1_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_1", OptionKey}, - {"rotate_to_2_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_2", OptionKey}, - {"rotate_to_3_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_3", OptionKey}, - {"rotate_to_4_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_4", OptionKey}, - {"rotate_to_5_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_5", OptionKey}, - {"rotate_to_6_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_6", OptionKey}, - {"rotate_to_7_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_7", OptionKey}, - {"rotate_to_8_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_8", OptionKey}, - {"rotate_to_9_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_9", OptionKey}, - {"rotate_to_10_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_10", OptionKey}, - {"rotate_to_11_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_11", OptionKey}, - {"rotate_to_12_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_12", OptionKey}, - - {"rotate_left_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_left", OptionKey}, - {"rotate_right_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_right", OptionKey}, - - {"switch_to_1_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_1", OptionKey}, - {"switch_to_2_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_2", OptionKey}, - {"switch_to_3_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_3", OptionKey}, - {"switch_to_4_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_4", OptionKey}, - {"switch_to_5_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_5", OptionKey}, - {"switch_to_6_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_6", OptionKey}, - {"switch_to_7_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_7", OptionKey}, - {"switch_to_8_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_8", OptionKey}, - {"switch_to_9_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_9", OptionKey}, - {"switch_to_10_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_10", OptionKey}, - {"switch_to_11_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_11", OptionKey}, - {"switch_to_12_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_12", OptionKey}, - - {"up_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_up", OptionKey}, - {"down_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_down", OptionKey}, - {"left_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_left", OptionKey}, - {"right_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_right", OptionKey}, - {"left_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_left", OptionKey}, - {"right_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_right", OptionKey}, - {"up_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_up", OptionKey}, - {"down_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_down", OptionKey}, - - {"put_topleft_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_nw", OptionKey}, - {"put_topright_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_ne", OptionKey}, - {"put_bottomleft_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_sw", OptionKey}, - {"put_bottomright_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_se", OptionKey}, - {"put_left_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_w", OptionKey}, - {"put_right_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_e", OptionKey}, - {"put_top_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_n", OptionKey}, - {"put_bottom_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_s", OptionKey}, - - {"rotate_to_1_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_1", OptionKey}, - {"rotate_to_2_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_2", OptionKey}, - {"rotate_to_3_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_3", OptionKey}, - {"rotate_to_4_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_4", OptionKey}, - {"rotate_to_5_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_5", OptionKey}, - {"rotate_to_6_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_6", OptionKey}, - {"rotate_to_7_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_7", OptionKey}, - {"rotate_to_8_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_8", OptionKey}, - {"rotate_to_9_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_9", OptionKey}, - {"rotate_to_10_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_10", OptionKey}, - {"rotate_to_11_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_11", OptionKey}, - {"rotate_to_12_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_12", OptionKey}, - - {"rotate_left_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_left", OptionKey}, - {"rotate_right_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_right", OptionKey}, - - {"command_screenshot", "gnomecompat", FALSE, - METACITY "/keybinding_commands/command_screenshot", OptionString}, - {"command_window_screenshot", "gnomecompat", FALSE, - METACITY "/keybinding_commands/command_window_screenshot", OptionString}, - {"command_terminal", "gnomecompat", FALSE, - "/desktop/gnome/applications/terminal/exec", OptionString}, - - {"current_viewport", "thumbnail", TRUE, - "/apps/panel/applets/window_list/prefs/display_all_workspaces", - OptionSpecial}, - - {"autoraise", "core", FALSE, - METACITY "/general/auto_raise", OptionBool}, - {"autoraise_delay", "core", FALSE, - METACITY "/general/auto_raise_delay", OptionInt}, - {"raise_on_click", "core", FALSE, - METACITY "/general/raise_on_click", OptionBool}, - {"click_to_focus", "core", FALSE, - METACITY "/general/focus_mode", OptionSpecial}, - - {"audible_bell", "core", FALSE, - METACITY "/general/audible_bell", OptionBool}, - /*{"hsize", "core", TRUE, - METACITY "/general/num_workspaces", OptionInt},*/ -}; - -#define N_SOPTIONS (sizeof (specialOptions) / sizeof (struct _SpecialOption)) +static Bool writeInit (CCSBackend *backend, CCSContext * context); +static void writeIntegratedOption (CCSContext *context, CCSSetting *setting, CCSIntegratedSetting *integrated); -static CCSSetting * -findDisplaySettingForPlugin (CCSContext *context, - const char *plugin, - const char *setting) +static Bool +isIntegratedOption (CCSSetting *setting, + CCSIntegratedSetting **integrated) { - CCSPlugin *p; - CCSSetting *s; - - p = ccsFindPlugin (context, plugin); - if (!p) - return NULL; + CCSPlugin *plugin = ccsSettingGetParent (setting); + const char *pluginName = ccsPluginGetName (plugin); + const char *settingName = ccsSettingGetName (setting); + CCSIntegratedSetting *tmp = ccsIntegrationGetIntegratedSetting (valueChangeData.integration, pluginName, settingName); - s = ccsFindSetting (p, setting); - if (!s) - return NULL; + if (integrated) + *integrated = tmp; - return s; + return tmp != NULL; } -static Bool -isIntegratedOption (CCSSetting *setting, - int *index) +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { - unsigned int i; + CCSIntegratedSetting *integrated; + readInit (backend, context); + if (!readOption (setting)) + ccsResetToDefault (setting, TRUE); - for (i = 0; i < N_SOPTIONS; i++) + if (ccsGetIntegrationEnabled (context) && + isIntegratedOption (setting, &integrated)) { - const SpecialOption *opt = &specialOptions[i]; - - if (strcmp (ccsSettingGetName (setting), opt->settingName) != 0) - continue; - - if (ccsPluginGetName (ccsSettingGetParent (setting))) - { - if (!opt->pluginName) - continue; - if (strcmp (ccsPluginGetName (ccsSettingGetParent (setting)), opt->pluginName) != 0) - continue; - } - else - { - if (opt->pluginName) - continue; - } - - if (index) - *index = i; - - return TRUE; + writeInit (backend, context); + writeIntegratedOption (context, setting, integrated); } - - return FALSE; } static void @@ -445,7 +129,6 @@ valueChanged (GConfClient *client, char *keyName = (char*) gconf_entry_get_key (entry); char *pluginName; char *token; - int index; unsigned int screenNum; CCSPlugin *plugin; CCSSetting *setting; @@ -490,135 +173,35 @@ valueChanged (GConfClient *client, if (!setting) return; - readInit (context); - if (!readOption (setting)) - ccsResetToDefault (setting, TRUE); - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - writeInit (context); - writeIntegratedOption (context, setting, index); - } + /* Passing null here is not optimal, but we are not + * maintaining gconf actively here */ + updateSetting (NULL, context, plugin, setting); } static void -gnomeValueChanged (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer user_data) +initClient (CCSBackend *backend, CCSContext *context) { - CCSContext *context = (CCSContext *)user_data; - char *keyName = (char*) gconf_entry_get_key (entry); - int i, last = 0, num = 0; - Bool needInit = TRUE; - - if (!ccsGetIntegrationEnabled (context)) - return; - - /* we have to loop multiple times here, because one Gnome - option may be integrated with multiple Compiz options */ - - while (1) - { - for (i = last, num = -1; i < N_SOPTIONS; i++) - { - if (strcmp (specialOptions[i].gnomeName, keyName) == 0) - { - num = i; - last = i + 1; - break; - } - } - - if (num < 0) - break; - - if ((strcmp (specialOptions[num].settingName, - "mouse_button_modifier") == 0) || - (strcmp (specialOptions[num].settingName, - "resize_with_right_button") == 0)) - { - CCSSetting *s; - - if (needInit) - { - readInit (context); - needInit = FALSE; - } - - s = findDisplaySettingForPlugin (context, "core", - "window_menu_button"); - if (s) - readSetting (context, s); - - s = findDisplaySettingForPlugin (context, "move", - "initiate_button"); - if (s) - readSetting (context, s); - - s = findDisplaySettingForPlugin (context, "resize", - "initiate_button"); - if (s) - readSetting (context, s); - } - else - { - CCSPlugin *plugin = NULL; - CCSSetting *setting; - SpecialOption *opt = (SpecialOption *) &specialOptions[num]; - - plugin = ccsFindPlugin (context, (char*) opt->pluginName); - if (plugin) - { - for (i = 0; i < 1; i++) - { - setting = ccsFindSetting (plugin, (char*) opt->settingName); - - if (setting) - { - if (needInit) - { - readInit (context); - needInit = FALSE; - } - readSetting (context, setting); - } - - /* do not read display settings multiple - times for multiscreen environments */ - } - } - } - } -} + client = gconf_client_get_for_engine (conf); -static void -initClient (CCSContext *context) -{ - int i; + valueChangeData.context = context; + valueChangeData.storage = ccsIntegratedSettingsStorageDefaultImplNew (&ccsDefaultObjectAllocator); + valueChangeData.factory = ccsGConfIntegratedSettingFactoryNew (client, &valueChangeData, &ccsDefaultObjectAllocator); - client = gconf_client_get_for_engine (conf); + valueChangeData.integration = ccsGNOMEIntegrationBackendNew (backend, + context, + valueChangeData.factory, + valueChangeData.storage, + &ccsDefaultObjectAllocator); compizNotifyId = gconf_client_notify_add (client, COMPIZ, valueChanged, context, NULL, NULL); gconf_client_add_dir (client, COMPIZ, GCONF_CLIENT_PRELOAD_NONE, NULL); - - for (i = 0; i < NUM_WATCHED_DIRS; i++) - { - gnomeNotifyIds[i] = gconf_client_notify_add (client, - watchedGnomeDirectories[i], - gnomeValueChanged, context, - NULL, NULL); - gconf_client_add_dir (client, watchedGnomeDirectories[i], - GCONF_CLIENT_PRELOAD_NONE, NULL); - } } static void finiClient (void) { - int i; + ccsIntegrationUnref (valueChangeData.integration); if (compizNotifyId) { @@ -626,21 +209,12 @@ finiClient (void) compizNotifyId = 0; } gconf_client_remove_dir (client, COMPIZ, NULL); - - for (i = 0; i < NUM_WATCHED_DIRS; i++) - { - if (gnomeNotifyIds[i]) - { - gconf_client_notify_remove (client, gnomeNotifyIds[0]); - gnomeNotifyIds[i] = 0; - } - gconf_client_remove_dir (client, watchedGnomeDirectories[i], NULL); - } - gconf_client_suggest_sync (client, NULL); g_object_unref (client); client = NULL; + + memset (&valueChangeData, 0, sizeof (CCSGNOMEValueChangeData)); } static void @@ -759,7 +333,8 @@ copyGconfRecursively (GConfEngine *conf, } static void -copyGconfTree (CCSContext *context, +copyGconfTree (CCSBackend *backend, + CCSContext *context, const gchar *from, const gchar *to, Bool associate, @@ -778,7 +353,7 @@ copyGconfTree (CCSContext *context, gconf_engine_suggest_sync (conf, NULL); - initClient (context); + initClient (backend, context); } static Bool @@ -868,17 +443,17 @@ readListValue (CCSSetting *setting, case TypeString: case TypeMatch: { - char **array = malloc (nItems * sizeof (char*)); + gchar **array = malloc ((nItems + 1) * sizeof (char*)); if (!array) break; for (; valueList; valueList = valueList->next, i++) array[i] = strdup (gconf_value_get_string (valueList->data)); - list = ccsGetValueListFromStringArray (array, nItems, setting); - for (i = 0; i < nItems; i++) - if (array[i]) - free (array[i]); - free (array); + + array[nItems] = NULL; + + list = ccsGetValueListFromStringArray ((const char **) array, nItems, setting); + g_strfreev (array); } break; case TypeColor: @@ -912,224 +487,13 @@ readListValue (CCSSetting *setting, return FALSE; } -static unsigned int -getGnomeMouseButtonModifier(void) -{ - unsigned int modMask = 0; - GError *err = NULL; - char *value; - - value = gconf_client_get_string (client, - METACITY "/general/mouse_button_modifier", - &err); - - if (err) - { - g_error_free (err); - return 0; - } - - if (!value) - return 0; - - modMask = ccsStringToModifiers (value); - g_free (value); - - return modMask; -} - -static unsigned int -getButtonBindingForSetting (CCSContext *context, - const char *plugin, - const char *setting) -{ - CCSSetting *s; - - s = findDisplaySettingForPlugin (context, plugin, setting); - if (!s) - return 0; - - if (ccsSettingGetType (s) != TypeButton) - return 0; - - return ccsSettingGetValue (s)->value.asButton.button; -} - static Bool readIntegratedOption (CCSContext *context, CCSSetting *setting, - int index) + CCSIntegratedSetting *integrated) { - GConfValue *gconfValue; - GError *err = NULL; - Bool ret = FALSE; - - gconfValue = gconf_client_get (client, - specialOptions[index].gnomeName, - &err); - - if (err) - { - g_error_free (err); - return FALSE; - } - - if (!gconfValue) - return FALSE; - - switch (specialOptions[index].type) { - case OptionInt: - if (gconfValue->type == GCONF_VALUE_INT) - { - guint value; - - value = gconf_value_get_int (gconfValue); - ccsSetInt (setting, value, TRUE); - ret = TRUE; - } - break; - case OptionBool: - if (gconfValue->type == GCONF_VALUE_BOOL) - { - gboolean value; - - value = gconf_value_get_bool (gconfValue); - ccsSetBool (setting, value ? TRUE : FALSE, TRUE); - ret = TRUE; - } - break; - case OptionBell: - if (gconfValue->type == GCONF_VALUE_BOOL) - { - gboolean value; - - value = gconf_value_get_bool (gconfValue); - ccsSetBell (setting, value ? TRUE : FALSE, TRUE); - - ret = TRUE; - } - break; - case OptionString: - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *value; - - value = gconf_value_get_string (gconfValue); - if (value) - { - ccsSetString (setting, value, TRUE); - ret = TRUE; - } - } - break; - case OptionKey: - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *value; - - value = gconf_value_get_string (gconfValue); - if (value) - { - CCSSettingKeyValue key; - - memset (&key, 0, sizeof (CCSSettingKeyValue)); - ccsGetKey (setting, &key); - if (ccsStringToKeyBinding (value, &key)) - { - ccsSetKey (setting, key, TRUE); - ret = TRUE; - } - } - } - break; - case OptionSpecial: - { - const char *settingName = specialOptions[index].settingName; - const char *pluginName = specialOptions[index].pluginName; - - if (strcmp (settingName, "current_viewport") == 0) - { - if (gconfValue->type == GCONF_VALUE_BOOL) - { - gboolean showAll; - - showAll = gconf_value_get_bool (gconfValue); - ccsSetBool (setting, !showAll, TRUE); - ret = TRUE; - } - } - else if (strcmp (settingName, "fullscreen_visual_bell") == 0) - { - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *value; - - value = gconf_value_get_string (gconfValue); - if (value) - { - Bool fullscreen; - - fullscreen = strcmp (value, "fullscreen") == 0; - ccsSetBool (setting, fullscreen, TRUE); - ret = TRUE; - } - } - } - else if (strcmp (settingName, "click_to_focus") == 0) - { - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *focusMode; - - focusMode = gconf_value_get_string (gconfValue); - - if (focusMode) - { - Bool clickToFocus = (strcmp (focusMode, "click") == 0); - ccsSetBool (setting, clickToFocus, TRUE); - ret = TRUE; - } - } - } - else if (((strcmp (settingName, "initiate_button") == 0) && - ((strcmp (pluginName, "move") == 0) || - (strcmp (pluginName, "resize") == 0))) || - ((strcmp (settingName, "window_menu_button") == 0) && - (strcmp (pluginName, "core") == 0))) - { - gboolean resizeWithRightButton; - CCSSettingButtonValue button; - - memset (&button, 0, sizeof (CCSSettingButtonValue)); - ccsGetButton (setting, &button); - - button.buttonModMask = getGnomeMouseButtonModifier (); - - resizeWithRightButton = - gconf_client_get_bool (client, METACITY - "/general/resize_with_right_button", - &err); - - if (strcmp (settingName, "window_menu_button") == 0) - button.button = resizeWithRightButton ? 2 : 3; - else if (strcmp (pluginName, "resize") == 0) - button.button = resizeWithRightButton ? 3 : 2; - else - button.button = 1; - - ccsSetButton (setting, button, TRUE); - ret = TRUE; - } - } - break; - default: - break; - } - - gconf_value_free (gconfValue); - - return ret; + return ccsIntegrationReadOptionIntoSetting (valueChangeData.integration, context, setting, integrated); } static Bool @@ -1430,267 +794,12 @@ writeListValue (CCSSetting *setting, g_slist_free (valueList); } -static Bool -setGnomeMouseButtonModifier (unsigned int modMask) -{ - char *modifiers, *currentValue; - GError *err = NULL; - - modifiers = ccsModifiersToString (modMask); - if (!modifiers) - return FALSE; - - currentValue = gconf_client_get_string (client, - METACITY - "/general/mouse_button_modifier", - &err); - if (err) - { - free (modifiers); - g_error_free (err); - return FALSE; - } - - if (!currentValue || (strcmp (currentValue, modifiers) != 0)) - gconf_client_set_string (client, - METACITY "/general/mouse_button_modifier", - modifiers, NULL); - if (currentValue) - g_free (currentValue); - - free (modifiers); - - return TRUE; -} - -static void -setButtonBindingForSetting (CCSContext *context, - const char *plugin, - const char *setting, - unsigned int button, - unsigned int buttonModMask) -{ - CCSSetting *s; - CCSSettingButtonValue value; - - s = findDisplaySettingForPlugin (context, plugin, setting); - if (!s) - return; - - if (ccsSettingGetType (s) != TypeButton) - return; - - value = ccsSettingGetValue (s)->value.asButton; - - if ((value.button != button) || (value.buttonModMask != buttonModMask)) - { - value.button = button; - value.buttonModMask = buttonModMask; - - ccsSetButton (s, value, TRUE); - } -} - static void writeIntegratedOption (CCSContext *context, CCSSetting *setting, - int index) + CCSIntegratedSetting *integrated) { - GError *err = NULL; - const char *optionName = specialOptions[index].gnomeName; - - switch (specialOptions[index].type) - { - case OptionInt: - { - int newValue, currentValue; - if (!ccsGetInt (setting, &newValue)) - break; - currentValue = gconf_client_get_int (client, optionName, &err); - - if (!err && (currentValue != newValue)) - gconf_client_set_int(client, specialOptions[index].gnomeName, - newValue, NULL); - } - break; - case OptionBool: - { - Bool newValue; - gboolean currentValue; - if (!ccsGetBool (setting, &newValue)) - break; - currentValue = gconf_client_get_bool (client, optionName, &err); - - if (!err && ((currentValue && !newValue) || - (!currentValue && newValue))) - gconf_client_set_bool (client, specialOptions[index].gnomeName, - newValue, NULL); - } - break; - case OptionBell: - { - Bool newValue; - gboolean currentValue; - if (!ccsGetBell (setting, &newValue)) - break; - currentValue = gconf_client_get_bool (client, optionName, &err); - - if (!err && ((currentValue && !newValue) || - (!currentValue && newValue))) - gconf_client_set_bool (client, specialOptions[index].gnomeName, - newValue, NULL); - } - break; - case OptionString: - { - char *newValue; - gchar *currentValue; - if (!ccsGetString (setting, &newValue)) - break; - currentValue = gconf_client_get_string (client, optionName, &err); - - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - } - break; - case OptionKey: - { - char *newValue; - gchar *currentValue; - - newValue = ccsKeyBindingToString (&ccsSettingGetValue (setting)->value.asKey); - if (newValue) - { - if (strcmp (newValue, "Disabled") == 0) - { - /* Metacity doesn't like "Disabled", it wants "disabled" */ - newValue[0] = 'd'; - } - - currentValue = gconf_client_get_string (client, - optionName, &err); - - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - free (newValue); - } - } - break; - case OptionSpecial: - { - const char *settingName = specialOptions[index].settingName; - const char *pluginName = specialOptions[index].pluginName; - - if (strcmp (settingName, "current_viewport") == 0) - { - Bool currentViewport; - - if (!ccsGetBool (setting, ¤tViewport)) - break; - - gconf_client_set_bool (client, optionName, - !currentViewport, NULL); - } - else if (strcmp (settingName, "fullscreen_visual_bell") == 0) - { - Bool fullscreen; - gchar *currentValue, *newValue; - if (!ccsGetBool (setting, &fullscreen)) - break; - - newValue = fullscreen ? "fullscreen" : "frame_flash"; - currentValue = gconf_client_get_string (client, - optionName, &err); - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - } - else if (strcmp (settingName, "click_to_focus") == 0) - { - Bool clickToFocus; - gchar *newValue, *currentValue; - if (!ccsGetBool (setting, &clickToFocus)) - break; - - newValue = clickToFocus ? "click" : "sloppy"; - currentValue = gconf_client_get_string (client, - optionName, &err); - - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - } - else if (((strcmp (settingName, "initiate_button") == 0) && - ((strcmp (pluginName, "move") == 0) || - (strcmp (pluginName, "resize") == 0))) || - ((strcmp (settingName, "window_menu_button") == 0) && - (strcmp (pluginName, "core") == 0))) - { - unsigned int modMask; - Bool resizeWithRightButton = FALSE; - gboolean currentValue; - - if ((getButtonBindingForSetting (context, "resize", - "initiate_button") == 3) || - (getButtonBindingForSetting (context, "core", - "window_menu_button") == 2)) - { - resizeWithRightButton = TRUE; - } - - currentValue = - gconf_client_get_bool (client, METACITY - "/general/resize_with_right_button", - &err); - - if (!err && ((currentValue && !resizeWithRightButton) || - (!currentValue && resizeWithRightButton))) - { - gconf_client_set_bool (client, - METACITY - "/general/resize_with_right_button", - resizeWithRightButton, NULL); - } - - modMask = ccsSettingGetValue (setting)->value.asButton.buttonModMask; - if (setGnomeMouseButtonModifier (modMask)) - { - setButtonBindingForSetting (context, "move", - "initiate_button", 1, modMask); - setButtonBindingForSetting (context, "resize", - "initiate_button", - resizeWithRightButton ? 3 : 2, - modMask); - setButtonBindingForSetting (context, "core", - "window_menu_button", - resizeWithRightButton ? 2 : 3, - modMask); - } - } - } - break; - } - - if (err) - g_error_free (err); + ccsIntegrationWriteSettingIntoOption (valueChangeData.integration, context, setting, integrated); } static void @@ -1883,17 +992,19 @@ getCurrentProfileName (void) } static Bool -checkProfile (CCSContext *context) +checkProfile (CCSBackend *backend, + CCSContext *context) { - char *profile, *lastProfile; + const char *profileCCS; + char *lastProfile; lastProfile = currentProfile; - profile = ccsGetProfile (context); - if (!profile || !strlen (profile)) + profileCCS = ccsGetProfile (context); + if (!profileCCS || !strlen (profileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (profile); + currentProfile = strdup (profileCCS); if (!lastProfile || strcmp (lastProfile, currentProfile) != 0) { @@ -1907,7 +1018,8 @@ checkProfile (CCSContext *context) if (pathName) { - copyGconfTree (context, COMPIZ, pathName, + copyGconfTree (backend, + context, COMPIZ, pathName, TRUE, "/schemas" COMPIZ); free (pathName); } @@ -1922,11 +1034,11 @@ checkProfile (CCSContext *context) if (pathName) { - copyGconfTree (context, pathName, COMPIZ, FALSE, NULL); + copyGconfTree (backend, context, pathName, COMPIZ, FALSE, NULL); /* delete the new profile tree in /apps/compizconfig-1 to avoid user modification in the wrong tree */ - copyGconfTree (context, pathName, NULL, TRUE, NULL); + copyGconfTree (backend, context, pathName, NULL, TRUE, NULL); free (pathName); } @@ -1941,7 +1053,7 @@ checkProfile (CCSContext *context) } static void -processEvents (unsigned int flags) +processEvents (CCSBackend *backend, unsigned int flags) { if (!(flags & ProcessEventsNoGlibMainLoopMask)) { @@ -1951,12 +1063,12 @@ processEvents (unsigned int flags) } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { g_type_init (); conf = gconf_engine_get_default (); - initClient (context); + initClient (backend, context); currentProfile = getCurrentProfileName (); @@ -1964,7 +1076,7 @@ initBackend (CCSContext * context) } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend *backend) { gconf_client_clear_cache (client); finiClient (); @@ -1982,22 +1094,23 @@ finiBackend (CCSContext * context) } static Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, CCSContext * context) { - return checkProfile (context); + return checkProfile (backend, context); } static void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status; - int index; + CCSIntegratedSetting *integrated; if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) + isIntegratedOption (setting, &integrated)) { - status = readIntegratedOption (context, setting, index); + status = readIntegratedOption (context, setting, integrated); } else status = readOption (setting); @@ -2007,21 +1120,22 @@ readSetting (CCSContext *context, } static Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { - return checkProfile (context); + return checkProfile (backend, context); } static void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { - int index; + CCSIntegratedSetting *integrated; if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) + isIntegratedOption (setting, &integrated)) { - writeIntegratedOption (context, setting, index); + writeIntegratedOption (context, setting, integrated); } else if (ccsSettingGetIsDefault (setting)) { @@ -2033,7 +1147,7 @@ writeSetting (CCSContext *context, } static Bool -getSettingIsIntegrated (CCSSetting * setting) +getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { if (!ccsGetIntegrationEnabled (ccsPluginGetContext (ccsSettingGetParent (setting)))) return FALSE; @@ -2045,14 +1159,14 @@ getSettingIsIntegrated (CCSSetting * setting) } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; } static CCSStringList -getExistingProfiles (CCSContext *context) +getExistingProfiles (CCSBackend *backend, CCSContext *context) { GSList *data, *tmp; CCSStringList ret = NULL; @@ -2090,13 +1204,14 @@ getExistingProfiles (CCSContext *context) } static Bool -deleteProfile (CCSContext *context, +deleteProfile (CCSBackend *backend, + CCSContext *context, char *profile) { char path[BUFSIZE]; gboolean status = FALSE; - checkProfile (context); + checkProfile (backend, context); snprintf (path, BUFSIZE, "%s/%s", PROFILEPATH, profile); @@ -2112,12 +1227,24 @@ deleteProfile (CCSContext *context, return status; } -static CCSBackendVTable gconfVTable = { +const CCSBackendInfo gconfBackendInfo = +{ "gconf", "GConf Configuration Backend", "GConf Configuration Backend for libccs", TRUE, TRUE, + 1 +}; + +static const CCSBackendInfo * +getInfo (CCSBackend *backend) +{ + return &gconfBackendInfo; +} + +static CCSBackendInterface gconfVTable = { + getInfo, processEvents, initBackend, finiBackend, @@ -2127,13 +1254,14 @@ static CCSBackendVTable gconfVTable = { writeInit, writeSetting, 0, + updateSetting, getSettingIsIntegrated, getSettingIsReadOnly, getExistingProfiles, deleteProfile }; -CCSBackendVTable * +CCSBackendInterface * getBackendInfo (void) { return &gconfVTable; diff --git a/compizconfig/gsettings/CMakeLists.txt b/compizconfig/gsettings/CMakeLists.txt index 95aad029ba94fcaa8bc74f647ef260df408d2f64..4e96f71cc37155a409d0a65ab492598f1e482b3d 100644 --- a/compizconfig/gsettings/CMakeLists.txt +++ b/compizconfig/gsettings/CMakeLists.txt @@ -8,8 +8,6 @@ include (CompizGSettings) set (_deps glib-2.0>=2.20.0 gio-2.0>=2.25.0) -option (USE_GCONF "Enable legacy GNOME 2.x option integration with GConf" ON) - if (USE_GCONF) list (APPEND _deps gconf-2.0>=2.31.1) @@ -18,9 +16,10 @@ endif (USE_GCONF) add_subdirectory (gsettings_backend_shared) -include_directories (${CMAKE_CURRENT_SOURCE_DIR}/gsettings_backend_shared) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/gsettings_backend_shared + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/gsettings/include) -compizconfig_backend (gsettings PKGDEPS ${_deps} LIBRARIES gsettings_backend_shared) +compizconfig_backend (gsettings PKGDEPS ${_deps} LIBRARIES compizconfig_gsettings_backend) find_program (GLIB_COMPILE_SCHEMAS glib-compile-schemas) @@ -30,6 +29,7 @@ if (GLIB_COMPILE_SCHEMAS) set (_top_gschema_file ${_top_gschema}.gschema.xml) set (_top_gschema_src ${CMAKE_CURRENT_SOURCE_DIR}/${_top_gschema_file}) set (_top_gschema_dest ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/${_top_gschema_file}) + set (_top_gschema_inst ${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas/) configure_file (${_top_gschema_src} ${_top_gschema_dest}) @@ -39,10 +39,18 @@ if (GLIB_COMPILE_SCHEMAS) ${CMAKE_BINARY_DIR}/glib-2.0/schemas/ ) - add_gsettings_schema_to_recompilation_list (compizconfig) + add_custom_command (OUTPUT ${_top_gschema_dest} + COMMAND cp -r ${_top_gschema_src} ${_top_gschema_dest} + DEPENDS ${_top_gschema_src} + VERBATIM) + + add_custom_target (compiz_gsettings_schema + DEPENDS ${_top_gschema_dest}) + + add_gsettings_schema_to_recompilation_list (compiz_gsettings_schema) compiz_install_gsettings_schema (${_top_gschema_dest} - ${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas) + ${_top_gschema_inst}) endif (GLIB_COMPILE_SCHEMAS) diff --git a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt index 51a26d3f9857032a00c82015130dde3e2990a366..020501501fbb1b86eec8e8b3f765e430d809d2f1 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt +++ b/compizconfig/gsettings/gsettings_backend_shared/CMakeLists.txt @@ -1,11 +1,13 @@ include (FindPkgConfig) -pkg_check_modules (GSETTINGS_UTIL glib-2.0>=2.28 - gio-2.0>=2.25.0) +compiz_pkg_check_modules (GSETTINGS_UTIL ${_deps}) if (GSETTINGS_UTIL_FOUND) set (GSETTINGS_UTIL_LIB_INCLUDES + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/include + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/gconf/include + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/gsettings/include ${compiz_SOURCE_DIR}/compizconfig/libcompizconfig/include ${GSETTINGS_UTIL_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/../src) @@ -13,14 +15,66 @@ if (GSETTINGS_UTIL_FOUND) include_directories (${GSETTINGS_UTIL_LIB_INCLUDES}) link_directories (${GSETTINGS_UTIL_LIBRARY_DIRS} - ${compiz_BINARY_DIR}/compizconfig/libcompizconfig) + ${compiz_BINARY_DIR}/compizconfig/libcompizconfig + ${compiz_BINARY_DIR}/compizconfig/integration/gnome + ${CMAKE_BINARY_DIR}/compizconfig/integration/gnome/gconf + ${CMAKE_BINARY_DIR}/compizconfig/integration/gnome/gsettings) - add_library (gsettings_backend_shared STATIC - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_constants.c - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_util.c) + add_library (compizconfig_gsettings_backend_interface STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_interface.c) - target_link_libraries (gsettings_backend_shared - ${GSETTINGS_UTIL_LIBRARIES} - compizconfig) + add_library (compizconfig_gsettings_wrapper_interface STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_interface.c) + + add_library (compizconfig_gsettings_wrapper STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_interface_wrapper.c) + + target_link_libraries (compizconfig_gsettings_wrapper + compizconfig + ${GSETTINGS_UTIL_LIBRARIES}) + + add_library (compizconfig_gsettings_util STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_constants.c + ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_util.c) + + target_link_libraries (compizconfig_gsettings_util + compizconfig_gsettings_backend_interface + compizconfig_gsettings_wrapper_interface + compizconfig + compizconfig + ${GSETTINGS_UTIL_LIBRARIES}) + + add_library (compizconfig_gsettings_backend SHARED + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend.c) + + set (GSETTINGS_BACKEND_SHARED_ADDITIONAL_LIBRARIES + compizconfig_gsettings_backend_interface + compizconfig_gsettings_util + compizconfig_gsettings_wrapper + compizconfig_gnome_integration + compizconfig_gnome_integration_gsettings_setting_factory + compizconfig) + + if (USE_GCONF) + list (APPEND GSETTINGS_BACKEND_SHARED_ADDITIONAL_LIBRARIES + compizconfig_gnome_integration_gconf_setting_factory) + list (APPEND GSETTINGS_BACKEND_SHARED_ADDITIONAL_LIBRARIES + compizconfig_gnome_integration_gconf_integrated_setting) + endif (USE_GCONF) + + target_link_libraries (compizconfig_gsettings_backend + ${GSETTINGS_BACKEND_SHARED_ADDITIONAL_LIBRARIES} + ${GSETTINGS_UTIL_LIBRARIES}) + + install (TARGETS compizconfig_gsettings_backend + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) + + # + # Tell CMake that targets using compizconfig_gsettings_backend should NOT re-import the + # libraries that compizconfig_gsettings_backend depends on (contains). + # + set_target_properties (compizconfig_gsettings_backend PROPERTIES + LINK_INTERFACE_LIBRARIES "" + ) endif (GSETTINGS_UTIL_FOUND) diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend.c new file mode 100644 index 0000000000000000000000000000000000000000..be9a8a569405076eb26b6917a758852818a11335 --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend.c @@ -0,0 +1,488 @@ +#include +#include + +#include +#include + +#include "ccs_gsettings_backend.h" +#include "ccs_gsettings_backend_interface.h" +#include "ccs_gsettings_interface.h" +#include "ccs_gsettings_interface_wrapper.h" +#include "ccs_gnome_integration.h" +#include "ccs_gnome_integration_gsettings_integrated_setting_factory.h" +#include "gsettings_shared.h" + +struct _CCSGSettingsBackendPrivate +{ + GList *settingsList; + CCSGSettingsWrapper *compizconfigSettings; + CCSGSettingsWrapper *currentProfileSettings; + + char *currentProfile; + CCSContext *context; + + CCSIntegration *integration; + + CCSGNOMEValueChangeData valueChangeData; +}; + +void +ccsGSettingsSetIntegration (CCSBackend *backend, CCSIntegration *integration) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + if (priv->integration) + ccsIntegrationUnref (priv->integration); + + priv->integration = integration; + ccsIntegrationRef (integration); +} + +CCSStringList +ccsGSettingsGetExistingProfiles (CCSBackend *backend, CCSContext *context) +{ + GVariant *value; + char *profile; + GVariantIter iter; + CCSStringList ret = NULL; + + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + ccsGSettingsBackendUpdateProfile (backend, context); + + value = ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "existing-profiles"); + g_variant_iter_init (&iter, value); + while (g_variant_iter_loop (&iter, "s", &profile)) + { + CCSString *str = calloc (1, sizeof (CCSString)); + str->value = strdup (profile); + + ccsStringRef (str); + ret = ccsStringListAppend (ret, str); + } + + g_variant_unref (value); + + return ret; +} + +void +ccsGSettingsValueChanged (GSettings *settings, + gchar *keyName, + gpointer user_data) +{ + CCSBackend *backend = (CCSBackend *)user_data; + GValue schemaNameValue = G_VALUE_INIT; + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + CCSBackendInterface *backendInterface = (CCSBackendInterface *) GET_INTERFACE (CCSBackendInterface, backend); + + + g_value_init (&schemaNameValue, G_TYPE_STRING); + g_object_get_property (G_OBJECT (settings), "schema-id", &schemaNameValue); + + const char *schemaName = g_value_get_string (&schemaNameValue); + CCSGSettingsWrapper *wrapper = findCCSGSettingsWrapperBySchemaName (schemaName, priv->settingsList); + + g_value_unset (&schemaNameValue); + + updateSettingWithGSettingsKeyName (backend, wrapper, keyName, backendInterface->updateSetting); +} + +static CCSGSettingsWrapper * +ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) +{ + CCSGSettingsWrapper *settingsObj = NULL; + gchar *schemaName = getSchemaNameForPlugin (plugin); + GVariant *writtenPlugins; + gsize newWrittenPluginsSize; + gchar **newWrittenPlugins; + + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + settingsObj = findCCSGSettingsWrapperBySchemaName (schemaName, priv->settingsList); + + if (settingsObj) + { + g_free (schemaName); + return settingsObj; + } + + /* No existing settings object found for this schema, create one */ + + settingsObj = ccsGSettingsWrapperNewForSchemaWithPath (schemaName, path, &ccsDefaultObjectAllocator); + ccsGSettingsBackendConnectToChangedSignal (backend, settingsObj); + priv->settingsList = g_list_append (priv->settingsList, (void *) settingsObj); + + /* Also write the plugin name to the list of modified plugins so + * that when we delete the profile the keys for that profile are also + * unset FIXME: This could be a little more efficient, like we could + * store keys that have changed from their defaults ... though + * gsettings doesn't seem to give you a way to get all of the schemas */ + + writtenPlugins = ccsGSettingsWrapperGetValue (priv->currentProfileSettings, "plugins-with-set-keys"); + + appendToPluginsWithSetKeysList (plugin, writtenPlugins, &newWrittenPlugins, &newWrittenPluginsSize); + + GVariant *newWrittenPluginsVariant = g_variant_new_strv ((const gchar * const *) newWrittenPlugins, newWrittenPluginsSize); + + ccsGSettingsWrapperSetValue (priv->currentProfileSettings, "plugins-with-set-keys", newWrittenPluginsVariant); + + g_variant_unref (writtenPlugins); + g_free (schemaName); + g_strfreev (newWrittenPlugins); + + return settingsObj; +} + +gboolean +ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, const char *profile) +{ + GVariant *profiles; + gboolean ret = FALSE; + + profiles = ccsGSettingsBackendGetExistingProfiles (backend); + if (appendStringToVariantIfUnique (&profiles, profile)) + { + ret = TRUE; + ccsGSettingsBackendSetExistingProfiles (backend, profiles); + } + else + g_variant_unref (profiles); + + return ret; +} + +void +ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile) +{ + ccsGSettingsBackendAddProfile (backend, profile); + ccsGSettingsBackendSetCurrentProfile (backend, profile); +} + +gboolean +ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context) +{ + const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); + const char *ccsProfile = ccsGetProfile (context); + char *profile = NULL; + + if (!ccsProfile) + profile = strdup (DEFAULTPROF); + else + profile = strdup (ccsProfile); + + if (!strlen (profile)) + { + free (profile); + profile = strdup (DEFAULTPROF); + } + + if (g_strcmp0 (profile, currentProfile)) + ccsGSettingsBackendUpdateCurrentProfileName (backend, profile); + + free (profile); + + return TRUE; +} + +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, + CCSContext *context, + GVariant *pluginsWithChangedKeys, + const char * profile) +{ + GVariantIter iter; + char *plugin; + + g_variant_iter_init (&iter, pluginsWithChangedKeys); + while (g_variant_iter_loop (&iter, "s", &plugin)) + { + CCSGSettingsWrapper *settings; + gchar *pathName = makeCompizPluginPath (profile, plugin); + + settings = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, plugin, pathName, context); + g_free (pathName); + + /* The GSettings documentation says not to use this API + * because we should know our own schema ... though really + * we don't because we autogenerate schemas ... */ + if (settings) + { + char **keys = ccsGSettingsWrapperListKeys (settings); + char **key_ptr; + + /* Unset all the keys */ + for (key_ptr = keys; *key_ptr; key_ptr++) + ccsGSettingsWrapperResetKey (settings, *key_ptr); + + g_strfreev (keys); + } + } +} + +CCSContext * +ccsGSettingsBackendGetContext (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetContext) (backend); +} + + +void +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, + CCSGSettingsWrapper *object) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendConnectToChangedSignal) (backend, object); +} + +CCSGSettingsWrapper * +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetSettingsObjectForPluginWithPath) (backend, plugin, path, context); +} + +static CCSContext * +ccsGSettingsBackendGetContextDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return priv->context; +} + +static void +ccsGSettingsBackendConnectToValueChangedSignalDefault (CCSBackend *backend, CCSGSettingsWrapper *wrapper) +{ + ccsGSettingsWrapperConnectToChangedSignal (wrapper, (GCallback) ccsGSettingsValueChanged, (gpointer) backend); +} + +static const char * +ccsGSettingsBackendGetCurrentProfileDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return priv->currentProfile; +} + +static GVariant * +ccsGSettingsBackendGetExistingProfilesDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "existing-profiles"); +} + +static void +ccsGSettingsBackendSetExistingProfilesDefault (CCSBackend *backend, GVariant *value) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "existing-profiles", value); +} + +static void +ccsGSettingsBackendSetCurrentProfileDefault (CCSBackend *backend, const gchar *value) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + gchar *profilePath = makeCompizProfilePath (value); + + /* Change the current profile and current profile settings */ + if (priv->currentProfile) + free (priv->currentProfile); + + if (priv->currentProfileSettings) + ccsGSettingsWrapperUnref (priv->currentProfileSettings); + + priv->currentProfile = strdup (value); + priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, + profilePath, + backend->object.object_allocation); + + GVariant *currentProfileVariant = g_variant_new ("s", value, NULL); + + ccsGSettingsWrapperSetValue (priv->compizconfigSettings, "current-profile", currentProfileVariant); + + g_free (profilePath); +} + +GVariant * +ccsGSettingsBackendGetPluginsWithSetKeysDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + return ccsGSettingsWrapperGetValue (priv->currentProfileSettings, "plugins-with-set-keys"); +} + +void +ccsGSettingsBackendClearPluginsWithSetKeysDefault (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + ccsGSettingsWrapperResetKey (priv->currentProfileSettings, "plugins-with-set-keys"); +} + +CCSIntegratedSetting * +ccsGSettingsBackendGetIntegratedOptionIndexDefault (CCSBackend *backend, CCSSetting *setting) +{ + CCSPlugin *plugin = ccsSettingGetParent (setting); + const char *pluginName = ccsPluginGetName (plugin); + const char *settingName = ccsSettingGetName (setting); + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return ccsIntegrationGetIntegratedSetting (priv->integration, pluginName, settingName); +} + +Bool +ccsGSettingsBackendReadIntegratedOptionDefault (CCSBackend *backend, CCSSetting *setting, CCSIntegratedSetting *integrated) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + return ccsIntegrationReadOptionIntoSetting (priv->integration, + priv->context, + setting, + integrated); +} + +void +ccsGSettingsBackendWriteIntegratedOptionDefault (CCSBackend *backend, CCSSetting *setting, CCSIntegratedSetting *integrated) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + ccsIntegrationWriteSettingIntoOption (priv->integration, + priv->context, + setting, + integrated); +} + +static CCSGSettingsBackendInterface gsettingsAdditionalDefaultInterface = { + ccsGSettingsBackendGetContextDefault, + ccsGSettingsBackendConnectToValueChangedSignalDefault, + ccsGSettingsBackendGetSettingsObjectForPluginWithPathDefault, + ccsGSettingsBackendGetCurrentProfileDefault, + ccsGSettingsBackendGetExistingProfilesDefault, + ccsGSettingsBackendSetExistingProfilesDefault, + ccsGSettingsBackendSetCurrentProfileDefault, + ccsGSettingsBackendGetPluginsWithSetKeysDefault, + ccsGSettingsBackendClearPluginsWithSetKeysDefault, + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault, + ccsGSettingsBackendUpdateProfileDefault, + ccsGSettingsBackendUpdateCurrentProfileNameDefault, + ccsGSettingsBackendAddProfileDefault, + ccsGSettingsBackendGetIntegratedOptionIndexDefault, + ccsGSettingsBackendReadIntegratedOptionDefault, + ccsGSettingsBackendWriteIntegratedOptionDefault +}; + +static CCSGSettingsBackendPrivate * +addPrivateToBackend (CCSBackend *backend, CCSObjectAllocationInterface *ai) +{ + CCSGSettingsBackendPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsBackendPrivate)); + + if (!priv) + { + ccsObjectRemoveInterface (backend, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + return NULL; + } + + ccsObjectSetPrivate (backend, (CCSPrivate *) priv); + return priv; +} + +static char* +getCurrentProfileName (CCSBackend *backend) +{ + GVariant *value; + char *ret = NULL; + + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + value = ccsGSettingsWrapperGetValue (priv->compizconfigSettings, "current-profile"); + + if (value) + ret = strdup (g_variant_get_string (value, NULL)); + else + ret = strdup (DEFAULTPROF); + + g_variant_unref (value); + + return ret; +} + +static void +ccsGSettingsWrapperDestroyNotify (gpointer o) +{ + ccsGSettingsWrapperUnref ((CCSGSettingsWrapper *) o); +} + +void +ccsGSettingsBackendDetachFromBackend (CCSBackend *backend) +{ + CCSGSettingsBackendPrivate *priv = (CCSGSettingsBackendPrivate *) ccsObjectGetPrivate (backend); + + if (priv->currentProfile) + { + free (priv->currentProfile); + priv->currentProfile = NULL; + } + + g_list_free_full (priv->settingsList, ccsGSettingsWrapperDestroyNotify); + priv->settingsList = NULL; + + if (priv->currentProfileSettings) + { + ccsGSettingsWrapperUnref (priv->currentProfileSettings); + priv->currentProfileSettings = NULL; + } + + ccsGSettingsWrapperUnref (priv->compizconfigSettings); + + priv->compizconfigSettings = NULL; + + ccsIntegrationUnref (priv->integration); + + free (priv); + ccsObjectSetPrivate (backend, NULL); + +} + +Bool +ccsGSettingsBackendAttachNewToBackend (CCSBackend *backend, CCSContext *context) +{ + char *currentProfilePath; + + ccsObjectAddInterface (backend, (CCSInterface *) &gsettingsAdditionalDefaultInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + + CCSGSettingsBackendPrivate *priv = addPrivateToBackend (backend, backend->object.object_allocation); + + priv->compizconfigSettings = ccsGSettingsWrapperNewForSchema (COMPIZCONFIG_SCHEMA_ID, + backend->object.object_allocation); + priv->currentProfile = getCurrentProfileName (backend); + currentProfilePath = makeCompizProfilePath (priv->currentProfile); + priv->currentProfileSettings = ccsGSettingsWrapperNewForSchemaWithPath (PROFILE_SCHEMA_ID, + currentProfilePath, + backend->object.object_allocation); + priv->context = context; + + CCSGNOMEIntegrationGSettingsWrapperFactory *wrapperFactory = ccsGNOMEIntegrationGSettingsWrapperDefaultImplNew (&ccsDefaultObjectAllocator); + CCSIntegratedSettingsStorage *storage = ccsIntegratedSettingsStorageDefaultImplNew (&ccsDefaultObjectAllocator); + + priv->valueChangeData.storage = storage; + priv->valueChangeData.context = priv->context; + + CCSIntegratedSettingFactory *factory = ccsGSettingsIntegratedSettingFactoryNew (wrapperFactory, + &priv->valueChangeData, + &ccsDefaultObjectAllocator); + + priv->valueChangeData.factory = factory; + + priv->integration = ccsGNOMEIntegrationBackendNew (backend, context, factory, storage, backend->object.object_allocation); + + + + priv->valueChangeData.integration = priv->integration; + + g_free (currentProfilePath); + return TRUE; +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend.h new file mode 100644 index 0000000000000000000000000000000000000000..06e463fd96c81bd8c9cbf433d7745c821d25d86a --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend.h @@ -0,0 +1,41 @@ +#ifndef _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_H +#define _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_H + +#include +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSBackend CCSBackend; +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; + +Bool +ccsGSettingsBackendAttachNewToBackend (CCSBackend *backend, CCSContext *context); + +void +ccsGSettingsBackendDetachFromBackend (CCSBackend *backend); + +/* Default implementations, should be moved */ + +void +ccsGSettingsBackendUpdateCurrentProfileNameDefault (CCSBackend *backend, const char *profile); + +gboolean +ccsGSettingsBackendUpdateProfileDefault (CCSBackend *backend, CCSContext *context); + +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (CCSBackend *backend, + CCSContext *context, + GVariant *pluginsWithChangedKeys, + const char * profile); + +gboolean ccsGSettingsBackendAddProfileDefault (CCSBackend *backend, + const char *profile); + +void ccsGSettingsSetIntegration (CCSBackend *backend, + CCSIntegration *integration); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend_interface.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend_interface.c new file mode 100644 index 0000000000000000000000000000000000000000..13dea03d7c24616f2d31fb0eeb4ae52bd2e6806c --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend_interface.c @@ -0,0 +1,89 @@ +#include +#include "ccs_gsettings_backend_interface.h" + +INTERFACE_TYPE (CCSGSettingsBackendInterface); + +const char * +ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetCurrentProfile) (backend); +} + +GVariant * +ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetExistingProfiles) (backend); +} + +void +ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendSetExistingProfiles) (backend, value); +} + +void +ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendSetCurrentProfile) (backend, value); +} + +GVariant * +ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetPluginsWithSetKeys) (backend); +} + +void +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendClearPluginsWithSetKeys) (backend); +} + +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, + CCSContext *context, + GVariant *pluginKeys, + const char *profile) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUnsetAllChangedPluginKeysInProfile) (backend, context, pluginKeys, profile); +} + +gboolean +ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUpdateProfile) (backend, context); +} + +void +ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendUpdateCurrentProfileName) (backend, profile); +} + +void +ccsGSettingsBackendAddProfile (CCSBackend *backend, const char *profile) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendAddProfile) (backend, profile); +} + +CCSIntegratedSetting * ccsGSettingsBackendGetIntegratedSetting (CCSBackend *backend, + CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendGetIntegratedSetting) (backend, setting); +} + +Bool +ccsGSettingsBackendReadIntegratedOption (CCSBackend *backend, + CCSSetting *setting, + CCSIntegratedSetting *integrated) +{ + return (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendReadIntegratedOption) (backend, setting, integrated); +} + +void +ccsGSettingsBackendWriteIntegratedOption (CCSBackend *backend, + CCSSetting *setting, + CCSIntegratedSetting *integrated) +{ + (*(GET_INTERFACE (CCSGSettingsBackendInterface, backend))->gsettingsBackendWriteIntegratedOption) (backend, setting, integrated); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend_interface.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..45c45fc982468d9516d312c12a86cc24a0606b43 --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_backend_interface.h @@ -0,0 +1,142 @@ +#ifndef _COMPIZCONFIG_GSETTINGS_BACKEND_INTERFACE_H +#define _COMPIZCONFIG_GSETTINGS_BACKEND_INTERFACE_H + +#include +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSBackend CCSBackend; +typedef struct _CCSGSettingsBackend CCSGSettingsBackend; +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; +typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; +typedef struct _CCSSetting CCSSetting; +typedef struct _CCSIntegratedSetting CCSIntegratedSetting; +typedef struct _CCSContext CCSContext; + +typedef CCSContext * (*CCSGSettingsBackendGetContext) (CCSBackend *); +typedef void (*CCSGSettingsBackendConnectToChangedSignal) (CCSBackend *, CCSGSettingsWrapper *); +typedef CCSGSettingsWrapper * (*CCSGSettingsBackendGetSettingsObjectForPluginWithPath) (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context); + +typedef const char * (*CCSGSettingsBackendGetCurrentProfile) (CCSBackend *backend); + +typedef GVariant * (*CCSGSettingsBackendGetExistingProfiles) (CCSBackend *backend); +typedef void (*CCSGSettingsBackendSetExistingProfiles) (CCSBackend *backend, GVariant *value); +typedef void (*CCSGSettingsBackendSetCurrentProfile) (CCSBackend *backend, const gchar *value); + +typedef GVariant * (*CCSGSettingsBackendGetPluginsWithSetKeys) (CCSBackend *backend); +typedef void (*CCSGSettingsBackendClearPluginsWithSetKeys) (CCSBackend *backend); + +typedef void (*CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile) (CCSBackend *backend, CCSContext *, GVariant *, const char *); + +typedef gboolean (*CCSGSettingsBackendUpdateProfile) (CCSBackend *, CCSContext *); +typedef void (*CCSGSettingsBackendUpdateCurrentProfileName) (CCSBackend *backend, const char *profile); + +typedef gboolean (*CCSGSettingsBackendAddProfile) (CCSBackend *backend, const char *profile); + +typedef CCSIntegratedSetting * (*CCSGSettingsBackendGetIntegratedSetting) (CCSBackend *backend, CCSSetting *setting); +typedef Bool (*CCSGSettingsBackendReadIntegratedOption) (CCSBackend *backend, CCSSetting *setting, CCSIntegratedSetting *); +typedef void (*CCSGSettingsBackendWriteIntegratedOption) (CCSBackend *backend, CCSSetting *setting, CCSIntegratedSetting *); + +/** + * @brief The _CCSGSettingsBackendInterface struct + * + * This interface represents a loaded CCSGSettingsBackend and some of the + * special operations that go with it. It is mainly an interface that + * exists for testing purposes - there are some operations which we + * want to mock out or replace since they can't be done in testing mode. + * + * CCSGSettingsBackendInterface isn't an interface that is implemented + * by any objects itself - it is attached to an existing CCSBackend + * at runtime, and the CCSBackend is passed to any utility functions in + * the GSettings backend. + */ +struct _CCSGSettingsBackendInterface +{ + CCSGSettingsBackendGetContext gsettingsBackendGetContext; + CCSGSettingsBackendConnectToChangedSignal gsettingsBackendConnectToChangedSignal; + CCSGSettingsBackendGetSettingsObjectForPluginWithPath gsettingsBackendGetSettingsObjectForPluginWithPath; + CCSGSettingsBackendGetCurrentProfile gsettingsBackendGetCurrentProfile; + CCSGSettingsBackendGetExistingProfiles gsettingsBackendGetExistingProfiles; + CCSGSettingsBackendSetExistingProfiles gsettingsBackendSetExistingProfiles; + CCSGSettingsBackendSetCurrentProfile gsettingsBackendSetCurrentProfile; + CCSGSettingsBackendGetPluginsWithSetKeys gsettingsBackendGetPluginsWithSetKeys; + CCSGSettingsBackendClearPluginsWithSetKeys gsettingsBackendClearPluginsWithSetKeys; + CCSGSettingsBackendUnsetAllChangedPluginKeysInProfile gsettingsBackendUnsetAllChangedPluginKeysInProfile; + CCSGSettingsBackendUpdateProfile gsettingsBackendUpdateProfile; + CCSGSettingsBackendUpdateCurrentProfileName gsettingsBackendUpdateCurrentProfileName; + CCSGSettingsBackendAddProfile gsettingsBackendAddProfile; + CCSGSettingsBackendGetIntegratedSetting gsettingsBackendGetIntegratedSetting; + CCSGSettingsBackendReadIntegratedOption gsettingsBackendReadIntegratedOption; + CCSGSettingsBackendWriteIntegratedOption gsettingsBackendWriteIntegratedOption; +}; + +unsigned int ccsCCSGSettingsBackendInterfaceGetType (); + +gboolean +ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context); + +void +ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile); + +CCSContext * +ccsGSettingsBackendGetContext (CCSBackend *backend); + +void +ccsGSettingsBackendConnectToChangedSignal (CCSBackend *backend, CCSGSettingsWrapper *object); + +CCSGSettingsWrapper * +ccsGSettingsGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context); + +const char * +ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend); + +GVariant * +ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend); + +void +ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value); + +void +ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value); + +GVariant * +ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend); + +void +ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend); + +void +ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, + CCSContext *context, + GVariant *pluginKeys, + const char *profile); + +void +ccsGSettingsBackendAddProfile (CCSBackend *backend, + const char *profile); + + +CCSIntegratedSetting * +ccsGSettingsBackendGetIntegratedSetting (CCSBackend *backend, + CCSSetting *setting); + +Bool +ccsGSettingsBackendReadIntegratedOption (CCSBackend *backend, + CCSSetting *setting, + CCSIntegratedSetting *integrated); +void +ccsGSettingsBackendWriteIntegratedOption (CCSBackend *backend, + CCSSetting *setting, + CCSIntegratedSetting *integrated); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c new file mode 100644 index 0000000000000000000000000000000000000000..a93efd0e8c9f173deb8a62d767d46b5d8bf3c9cb --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.c @@ -0,0 +1,65 @@ +#include +#include "ccs_gsettings_interface.h" + +INTERFACE_TYPE (CCSGSettingsWrapperInterface); +CCSREF_OBJ (GSettingsWrapper, CCSGSettingsWrapper); + +void +ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *wrapper, + const char *key, + GVariant *value) +{ + (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperSetValue) (wrapper, key, value); +} + +GVariant * +ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *wrapper, + const char *key) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetValue) (wrapper, key); +} + +void +ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *wrapper, + const char *key) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperResetKey) (wrapper, key); +} + +char ** +ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperListKeys) (wrapper); +} + +GSettings * +ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetGSettings) (wrapper); +} + +const char * +ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetSchemaName) (wrapper); +} + +const char * +ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperGetPath) (wrapper); +} + +void +ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *wrapper, + GCallback callback, + gpointer data) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperConnectToChangedSignal) (wrapper, callback, data); +} + +void +ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) +{ + return (*(GET_INTERFACE (CCSGSettingsWrapperInterface, wrapper))->gsettingsWrapperFree) (wrapper); +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..c96c97c0a776c00cbed9c44cb7caf40dc93d9605 --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface.h @@ -0,0 +1,69 @@ +#ifndef _CCS_GSETTINGS_INTERFACE_H +#define _CCS_GSETTINGS_INTERFACE_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +#include +#include +#include + +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; +typedef struct _CCSGSettingsWrapperInterface CCSGSettingsWrapperInterface; + +typedef void (*CCSGSettingsWrapperSetValue) (CCSGSettingsWrapper *, const char *, GVariant *); +typedef GVariant * (*CCSGSettingsWrapperGetValue) (CCSGSettingsWrapper *, const char *); +typedef void (*CCSGSettingsWrapperResetKey) (CCSGSettingsWrapper *, const char *); +typedef char ** (*CCSGSettingsWrapperListKeys) (CCSGSettingsWrapper *); +typedef GSettings * (*CCSGSettingsWrapperGetGSettings) (CCSGSettingsWrapper *); +typedef const char * (*CCSGSettingsWrapperGetSchemaName) (CCSGSettingsWrapper *); +typedef const char * (*CCSGSettingsWrapperGetPath) (CCSGSettingsWrapper *); +typedef void (*CCSGSettingsWrapperConnectToChangedSignal) (CCSGSettingsWrapper *, GCallback, gpointer); +typedef void (*CCSGSettingsWrapperFree) (CCSGSettingsWrapper *); + +struct _CCSGSettingsWrapperInterface +{ + CCSGSettingsWrapperSetValue gsettingsWrapperSetValue; + CCSGSettingsWrapperGetValue gsettingsWrapperGetValue; + CCSGSettingsWrapperResetKey gsettingsWrapperResetKey; + CCSGSettingsWrapperListKeys gsettingsWrapperListKeys; + CCSGSettingsWrapperGetGSettings gsettingsWrapperGetGSettings; + CCSGSettingsWrapperGetSchemaName gsettingsWrapperGetSchemaName; + CCSGSettingsWrapperGetPath gsettingsWrapperGetPath; + CCSGSettingsWrapperConnectToChangedSignal gsettingsWrapperConnectToChangedSignal; + CCSGSettingsWrapperFree gsettingsWrapperFree; +}; + +/** + * @brief The _CCSGSettingsWrapper struct + * + * A wrapper around GSettings. + * + * This wrapper exists for testing purposes and presents the subset + * of interface that we wish to use from GSettings anways. It does not + * have any of the typed functions and it is the programmer's responsibility + * to supply a GVariant to setValue and getValue that is valid. + */ +struct _CCSGSettingsWrapper +{ + CCSObject object; +}; + +void ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *, const char *, GVariant *); +GVariant * ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *, const char *); +void ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *, const char *); +char **ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *); +GSettings * ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *); +const char * ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *); +const char * ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *); +void ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *, GCallback, gpointer); +void ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper); + +unsigned int ccsCCSGSettingsWrapperInterfaceGetType (); + +CCSREF_HDR (GSettingsWrapper, CCSGSettingsWrapper); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c new file mode 100644 index 0000000000000000000000000000000000000000..b07e75c6f643028a03c61182631d7c8506af4cd8 --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.c @@ -0,0 +1,260 @@ +#include +#include "ccs_gsettings_interface_wrapper.h" + +typedef struct _CCSGSettingsWrapperPrivate CCSGSettingsWrapperPrivate; + +struct _CCSGSettingsWrapperPrivate +{ + GSettings *settings; + char *schema; + char *path; +}; + +#define GSETTINGS_WRAPPER_PRIVATE(w) \ + CCSGSettingsWrapperPrivate *gswPrivate = (CCSGSettingsWrapperPrivate *) ccsObjectGetPrivate (w); + +static GVariant * ccsGSettingsWrapperGetValueDefault (CCSGSettingsWrapper *wrapper, const char *key) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return g_settings_get_value (gswPrivate->settings, key); +} + +static void ccsGSettingsWrapperSetValueDefault (CCSGSettingsWrapper *wrapper, const char *key, GVariant *variant) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + g_settings_set_value (gswPrivate->settings, key, variant); +} + +static void ccsGSettingsWrapperResetKeyDefault (CCSGSettingsWrapper *wrapper, const char *key) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + g_settings_reset (gswPrivate->settings, key); +} + +static char ** ccsGSettingsWrapperListKeysDefault (CCSGSettingsWrapper *wrapper) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return g_settings_list_keys (gswPrivate->settings); +} + +static GSettings * ccsGSettingsWrapperGetGSettingsDefault (CCSGSettingsWrapper *wrapper) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return gswPrivate->settings; +} + +static const char * +ccsGSettingsWrapperGetSchemaNameDefault (CCSGSettingsWrapper *wrapper) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return gswPrivate->schema; +} + +static const char * +ccsGSettingsWrapperGetPathDefault (CCSGSettingsWrapper *wrapper) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + return gswPrivate->path; +} + +void +ccsGSettingsWrapperConnectToChangedSignalDefault (CCSGSettingsWrapper *wrapper, + GCallback callback, + gpointer data) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + g_signal_connect (gswPrivate->settings, "changed", callback, data); +} + +static void +ccsFreeGSettingsWrapperDefault (CCSGSettingsWrapper *wrapper) +{ + GSETTINGS_WRAPPER_PRIVATE (wrapper); + + if (gswPrivate->settings) + g_object_unref (gswPrivate->settings); + + if (gswPrivate->path) + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + gswPrivate->path); + + if (gswPrivate->schema) + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + gswPrivate->schema); + + ccsObjectFinalize (wrapper); + + (*wrapper->object.object_allocation->free_) (wrapper->object.object_allocation->allocator, + wrapper); +} + +const CCSGSettingsWrapperInterface interface = +{ + ccsGSettingsWrapperSetValueDefault, + ccsGSettingsWrapperGetValueDefault, + ccsGSettingsWrapperResetKeyDefault, + ccsGSettingsWrapperListKeysDefault, + ccsGSettingsWrapperGetGSettingsDefault, + ccsGSettingsWrapperGetSchemaNameDefault, + ccsGSettingsWrapperGetPathDefault, + ccsGSettingsWrapperConnectToChangedSignalDefault, + ccsFreeGSettingsWrapperDefault +}; + +static CCSGSettingsWrapperPrivate * +allocatePrivateWrapper (CCSObjectAllocationInterface *ai, CCSGSettingsWrapper *wrapper) +{ + CCSGSettingsWrapperPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsWrapper)); + + if (!priv) + { + (*ai->free_) (ai->allocator, wrapper); + return NULL; + } + + return priv; +} + +static CCSGSettingsWrapper * +allocateWrapper (CCSObjectAllocationInterface *ai) +{ + CCSGSettingsWrapper *wrapper = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsWrapper)); + + if (!wrapper) + return NULL; + + return wrapper; +} + +static void +freeWrapperAndPriv (CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + (*ai->free_) (ai->allocator, priv); + (*ai->free_) (ai->allocator, wrapper); +} + +static GSettings * +newGSettingsWithPath (const char *schema, + const char *path, + CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + GSettings *settings = g_settings_new_with_path (schema, path); + + if (!settings) + { + freeWrapperAndPriv (wrapper, priv, ai); + return NULL; + } + + return settings; +} + +static GSettings * +newGSettings (const char *schema, + CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + GSettings *settings = g_settings_new (schema); + + if (!settings) + { + freeWrapperAndPriv (wrapper, priv, ai); + return NULL; + } + + return settings; +} + +static Bool +allocateWrapperData (CCSObjectAllocationInterface *ai, + CCSGSettingsWrapper **wrapper, + CCSGSettingsWrapperPrivate **priv) +{ + *wrapper = allocateWrapper (ai); + + if (!*wrapper) + return FALSE; + + *priv = allocatePrivateWrapper (ai, *wrapper); + + if (!*priv) + return FALSE; + + return TRUE; +} + +static void +initCCSGSettingsWrapperObject (CCSGSettingsWrapper *wrapper, + CCSGSettingsWrapperPrivate *priv, + CCSObjectAllocationInterface *ai) +{ + ccsObjectInit (wrapper, ai); + ccsObjectAddInterface (wrapper, (const CCSInterface *) &interface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); + ccsObjectSetPrivate (wrapper, (CCSPrivate *) priv); + ccsGSettingsWrapperRef (wrapper); +} + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, + const char *path, + CCSObjectAllocationInterface *ai) +{ + CCSGSettingsWrapper *wrapper = NULL; + CCSGSettingsWrapperPrivate *priv = NULL; + + if (!allocateWrapperData (ai, &wrapper, &priv)) + return NULL; + + priv->schema = g_strdup (schema); + priv->path = g_strdup (path); + priv->settings = newGSettingsWithPath (schema, path, wrapper, priv, ai); + + if (!priv->settings) + return NULL; + + initCCSGSettingsWrapperObject (wrapper, priv, ai); + + return wrapper; +} + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchema (const char *schema, + CCSObjectAllocationInterface *ai) +{ + CCSGSettingsWrapper *wrapper = NULL; + CCSGSettingsWrapperPrivate *priv = NULL; + + if (!allocateWrapperData (ai, &wrapper, &priv)) + return NULL; + + priv->schema = g_strdup (schema); + priv->settings = newGSettings (schema, wrapper, priv, ai); + + if (!priv->settings) + return NULL; + + GValue pathValue = G_VALUE_INIT; + g_value_init (&pathValue, G_TYPE_STRING); + g_object_get_property (G_OBJECT (priv->settings), "path", &pathValue); + + priv->path = g_value_dup_string (&pathValue); + + g_value_unset (&pathValue); + + initCCSGSettingsWrapperObject (wrapper, priv, ai); + + return wrapper; +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..4535f10eed950de28596f23aee736ec705cc7c05 --- /dev/null +++ b/compizconfig/gsettings/gsettings_backend_shared/ccs_gsettings_interface_wrapper.h @@ -0,0 +1,21 @@ +#ifndef _CCS_GSETTINGS_INTERFACE_WRAPPER_H +#define _CCS_GSETTINGS_INTERFACE_WRAPPER_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +#include "ccs_gsettings_interface.h" + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchemaWithPath (const char *schema, + const char *path, + CCSObjectAllocationInterface *ai); + +CCSGSettingsWrapper * +ccsGSettingsWrapperNewForSchema (const char *schema, + CCSObjectAllocationInterface *ai); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_constants.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_constants.c index 775a1cf509622853f6a2b605f46912228367ea49..ff0109b67a8af69e4391ec1fe422f07661de22a0 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_constants.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_constants.c @@ -1,5 +1,7 @@ #include "gsettings_shared.h" +const unsigned int BUFSIZE = 512; + const char * const COMPIZCONFIG_SCHEMA_ID = "org.compiz"; const char * const COMPIZCONFIG_PATH = "/org/compiz/"; diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_shared.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_shared.h index cde68025d8d7d5077762cade489b7d7cce3e63fd..02ad806a916f52b419019bbd738e0162a52fad00 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_shared.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_shared.h @@ -5,16 +5,22 @@ G_BEGIN_DECLS +#include +#include +#include +#include +#include +#include #include "gsettings_util.h" extern const char * const PLUGIN_SCHEMA_ID_PREFIX; extern const char * const COMPIZCONFIG_SCHEMA_ID; extern const char * const COMPIZCONFIG_PATH; extern const char * const PROFILE_SCHEMA_ID; -#define METACITY "/apps/metacity" extern const char * const PROFILE_PATH_PREFIX; extern const char * const DEFAULTPROF; extern const unsigned int MAX_GSETTINGS_KEY_SIZE; +extern const unsigned int BUFSIZE; G_END_DECLS diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c index 688771918981e4323112021edfe74672f2cefd73..080915c2cb38304c65ddfa9ff1bafea6126c6bdc 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.c @@ -1,7 +1,22 @@ #define CCS_LOG_DOMAIN "gsettings" #include +#include #include #include "gsettings_shared.h" +#include "ccs_gsettings_backend.h" +#include "ccs_gsettings_backend_interface.h" +#include "ccs_gsettings_interface.h" +#include "ccs_gsettings_interface_wrapper.h" + +const CCSBackendInfo gsettingsBackendInfo = +{ + "gsettings", + "GSettings Configuration Backend", + "GSettings Configuration Backend for libccs", + TRUE, + TRUE, + 1 +}; GList * variantTypeToPossibleSettingType (const gchar *vt) @@ -38,23 +53,18 @@ variantTypeToPossibleSettingType (const gchar *vt) return possibleTypesList; } -GObject * -findObjectInListWithPropertySchemaName (const gchar *schemaName, - GList *iter) +CCSGSettingsWrapper * +findCCSGSettingsWrapperBySchemaName (const gchar *schemaName, + GList *iter) { while (iter) { - GObject *obj = (GObject *) iter->data; - gchar *name = NULL; + CCSGSettingsWrapper *obj = iter->data; + const gchar *name = ccsGSettingsWrapperGetSchemaName (obj); - g_object_get (obj, - "schema", - &name, NULL); if (g_strcmp0 (name, schemaName) != 0) obj = NULL; - g_free (name); - if (obj) return obj; else @@ -227,6 +237,42 @@ variantIsValidForCCSType (GVariant *gsettingsValue, return valid; } +Bool +updateSettingWithGSettingsKeyName (CCSBackend *backend, + CCSGSettingsWrapper *settings, + const gchar *keyName, + CCSBackendUpdateFunc updateSetting) +{ + CCSContext *context = ccsGSettingsBackendGetContext (backend); + char *uncleanKeyName = NULL; + char *pathOrig; + CCSPlugin *plugin; + CCSSetting *setting; + Bool ret = TRUE; + + pathOrig = strdup (ccsGSettingsWrapperGetPath (settings)); + + if (findSettingAndPluginToUpdateFromPath (settings, pathOrig, keyName, context, &plugin, &setting, &uncleanKeyName)) + (*updateSetting) (backend, context, plugin, setting); + else + { + /* We hit a situation where either the key stored in GSettings couldn't be + * matched at all to a key in the xml file, or where there were multiple matches. + * Unfortunately, there isn't much we can do about this, other than try + * and warn the user and bail out. It just means that if the key was updated + * externally we won't know about the change until the next reload of settings */ + ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, pathOrig); + ret = FALSE; + } + + g_free (pathOrig); + + if (uncleanKeyName) + g_free (uncleanKeyName); + + return ret; +} + Bool appendToPluginsWithSetKeysList (const gchar *plugin, GVariant *writtenPlugins, @@ -327,6 +373,65 @@ attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *l return found; } +Bool +findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, + const char *path, + const gchar *keyName, + CCSContext *context, + CCSPlugin **plugin, + CCSSetting **setting, + char **uncleanKeyName) +{ + char *pluginName; + unsigned int screenNum; + + if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) + return FALSE; + + *plugin = ccsFindPlugin (context, pluginName); + + if (*plugin) + { + *uncleanKeyName = translateKeyForCCS (keyName); + + *setting = ccsFindSetting (*plugin, *uncleanKeyName); + if (!*setting) + { + /* Couldn't find setting straight off the bat, + * try and find the best match */ + GVariant *value = ccsGSettingsWrapperGetValue (settings, keyName); + + if (value) + { + GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); + GList *iter = possibleSettingTypes; + + while (iter) + { + *setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (*plugin), + keyName, + (CCSSettingType) GPOINTER_TO_INT (iter->data)); + + if (*setting) + break; + + iter = iter->next; + } + + g_list_free (possibleSettingTypes); + g_variant_unref (value); + } + } + } + + g_free (pluginName); + + if (!*plugin || !*setting) + return FALSE; + + return TRUE; +} + gchar * makeCompizProfilePath (const gchar *profilename) { @@ -340,3 +445,653 @@ makeCompizPluginPath (const gchar *profileName, const gchar *pluginName) "plugins", pluginName, "/", NULL); } +gchar * +getNameForCCSSetting (CCSSetting *setting) +{ + return translateKeyForGSettings (ccsSettingGetName (setting)); +} + +Bool +checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName) +{ + /* first check if the key is set */ + if (!gsettingsValue) + { + ccsWarning ("There is no key at the path %s. " + "Settings from this path won't be read. Try to remove " + "that value so that operation can continue properly.", + pathName); + return FALSE; + } + + if (!variantIsValidForCCSType (gsettingsValue, type)) + { + ccsWarning ("There is an unsupported value at path %s. " + "Settings from this path won't be read. Try to remove " + "that value so that operation can continue properly.", + pathName); + return FALSE; + } + + return TRUE; +} + +GVariant * +getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pathName, CCSSettingType type) +{ + GVariant *gsettingsValue = ccsGSettingsWrapperGetValue (settings, key); + + if (!checkReadVariantIsValid (gsettingsValue, type, pathName)) + { + g_variant_unref (gsettingsValue); + return NULL; + } + + return gsettingsValue; +} + +CCSSettingValueList +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) +{ + CCSSettingValueList list = NULL; + Bool *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (Bool)); + Bool *arrayCounter = array; + gboolean value; + + if (!array) + return NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (iter, "b", &value)) + *arrayCounter++ = value ? TRUE : FALSE; + + list = ccsGetValueListFromBoolArray (array, nItems, setting); + free (array); + + return list; +} + +CCSSettingValueList +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) +{ + CCSSettingValueList list = NULL; + int *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (int)); + int *arrayCounter = array; + gint value; + + if (!array) + return NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (iter, "i", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromIntArray (array, nItems, setting); + free (array); + + return list; +} + +CCSSettingValueList +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) +{ + CCSSettingValueList list = NULL; + float *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (float)); + float *arrayCounter = array; + gdouble value; + + if (!array) + return NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_loop (iter, "d", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromFloatArray (array, nItems, setting); + free (array); + + return list; +} + +CCSSettingValueList +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) +{ + CCSSettingValueList list = NULL; + gchar **array = (*ai->calloc_) (ai->allocator, 1, (nItems + 1) * sizeof (gchar *)); + gchar **arrayCounter = array; + gchar *value; + + if (!array) + return NULL; + + array[nItems] = NULL; + + /* Reads each item from the variant into arrayCounter */ + while (g_variant_iter_next (iter, "s", &value)) + *arrayCounter++ = value; + + list = ccsGetValueListFromStringArray ((const gchar **) array, nItems, setting); + g_strfreev (array); + + return list; +} + +CCSSettingValueList +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *ai) +{ + CCSSettingValueList list = NULL; + char *colorValue; + CCSSettingColorValue *array = (*ai->calloc_) (ai->allocator, 1, nItems * sizeof (CCSSettingColorValue)); + unsigned int i = 0; + + if (!array) + return NULL; + + while (g_variant_iter_loop (iter, "s", &colorValue)) + { + ccsStringToColor (colorValue, + &array[i]); + i++; + } + + list = ccsGetValueListFromColorArray (array, nItems, setting); + free (array); + + return list; +} + +CCSSettingValueList +readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *ai) +{ + CCSSettingType listType = ccsSettingGetInfo (setting)->forList.listType; + gboolean hasVariantType; + unsigned int nItems; + CCSSettingValueList list = NULL; + GVariantIter iter; + + hasVariantType = compizconfigTypeHasVariantType (listType); + + if (!hasVariantType) + return NULL; + + g_variant_iter_init (&iter, gsettingsValue); + nItems = g_variant_iter_n_children (&iter); + + switch (listType) + { + case TypeBool: + list = readBoolListValue (&iter, nItems, setting, ai); + break; + case TypeInt: + list = readIntListValue (&iter, nItems, setting, ai); + break; + case TypeFloat: + list = readFloatListValue (&iter, nItems, setting, ai); + break; + case TypeString: + case TypeMatch: + list = readStringListValue (&iter, nItems, setting, ai); + break; + case TypeColor: + list = readColorListValue (&iter, nItems, setting, ai); + break; + default: + break; + } + + return list; +} + +const char * readStringFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_string (gsettingsValue, NULL); +} + +int readIntFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_int32 (gsettingsValue); +} + +Bool readBoolFromVariant (GVariant *gsettingsValue) +{ + return g_variant_get_boolean (gsettingsValue) ? TRUE : FALSE; +} + +float readFloatFromVariant (GVariant *gsettingsValue) +{ + return (float) g_variant_get_double (gsettingsValue); +} + +CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingColorValue color; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToColor (value, &color); + else + *success = FALSE; + + return color; +} + +CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingKeyValue key; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToKeyBinding (value, &key); + else + *success = FALSE; + + return key; +} + +CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success) +{ + const char *value; + CCSSettingButtonValue button; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + *success = ccsStringToButtonBinding (value, &button); + else + *success = FALSE; + + return button; +} + +unsigned int readEdgeFromVariant (GVariant *gsettingsValue) +{ + const char *value; + value = g_variant_get_string (gsettingsValue, NULL); + + if (value) + return ccsStringToEdges (value); + + return 0; +} + +GVariant * +writeBoolListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); + while (list) + { + g_variant_builder_add (builder, "b", list->data->value.asBool); + list = list->next; + } + value = g_variant_new ("ab", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeIntListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); + while (list) + { + g_variant_builder_add (builder, "i", list->data->value.asInt); + list = list->next; + } + value = g_variant_new ("ai", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeFloatListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); + while (list) + { + g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); + list = list->next; + } + value = g_variant_new ("ad", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeStringListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + while (list) + { + g_variant_builder_add (builder, "s", list->data->value.asString); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeMatchListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + while (list) + { + g_variant_builder_add (builder, "s", list->data->value.asMatch); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + + return value; +} + +GVariant * +writeColorListValue (CCSSettingValueList list) +{ + GVariant *value = NULL; + GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); + char *item; + while (list) + { + item = ccsColorToString (&list->data->value.asColor); + g_variant_builder_add (builder, "s", item); + g_free (item); + list = list->next; + } + value = g_variant_new ("as", builder); + g_variant_builder_unref (builder); + + return value; +} + +Bool +writeListValue (CCSSettingValueList list, + CCSSettingType listType, + GVariant **gsettingsValue) +{ + GVariant *value = NULL; + + switch (listType) + { + case TypeBool: + value = writeBoolListValue (list); + break; + case TypeInt: + value = writeIntListValue (list); + break; + case TypeFloat: + value = writeFloatListValue (list); + break; + case TypeString: + value = writeStringListValue (list); + break; + case TypeMatch: + value = writeMatchListValue (list); + break; + case TypeColor: + value = writeColorListValue (list); + break; + default: + ccsWarning ("Attempt to write unsupported list type %d!", + listType); + return FALSE; + break; + } + + *gsettingsValue = value; + return TRUE; +} + +Bool writeStringToVariant (const char *value, GVariant **variant) +{ + *variant = g_variant_new_string (value); + return TRUE; +} + +Bool writeFloatToVariant (float value, GVariant **variant) +{ + *variant = g_variant_new_double ((double) value); + return TRUE; +} + +Bool writeIntToVariant (int value, GVariant **variant) +{ + *variant = g_variant_new_int32 (value); + return TRUE; +} + +Bool writeBoolToVariant (Bool value, GVariant **variant) +{ + *variant = g_variant_new_boolean (value); + return TRUE; +} + +Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant) +{ + char *colString; + + colString = ccsColorToString (&value); + if (!colString) + return FALSE; + + *variant = g_variant_new_string (colString); + free (colString); + + return TRUE; +} + +Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant) +{ + char *keyString; + + keyString = ccsKeyBindingToString (&key); + if (!keyString) + return FALSE; + + *variant = g_variant_new_string (keyString); + free (keyString); + + return TRUE; +} + +Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant) +{ + char *buttonString; + + buttonString = ccsButtonBindingToString (&button); + if (!buttonString) + return FALSE; + + *variant = g_variant_new_string (buttonString); + free (buttonString); + return TRUE; +} + +Bool writeEdgeToVariant (unsigned int edges, GVariant **variant) +{ + char *edgeString; + + edgeString = ccsEdgesToString (edges); + if (!edgeString) + return FALSE; + + *variant = g_variant_new_string (edgeString); + free (edgeString); + return TRUE; +} + +void +writeVariantToKey (CCSGSettingsWrapper *settings, + const char *key, + GVariant *value) +{ + ccsGSettingsWrapperSetValue (settings, key, value); +} + +typedef void (*VariantItemCheckAndInsertFunc) (GVariantBuilder *, const char *item, void *userData); + +typedef struct _FindItemInVariantData +{ + gboolean found; + const char *item; +} FindItemInVariantData; + +typedef struct _InsertIfNotEqualData +{ + gboolean skipped; + const char *item; +} InsertIfNotEqualData; + +static void +insertIfNotEqual (GVariantBuilder *builder, const char *item, void *userData) +{ + InsertIfNotEqualData *data = (InsertIfNotEqualData *) userData; + + if (g_strcmp0 (item, data->item)) + g_variant_builder_add (builder, "s", item); + else + data->skipped = TRUE; +} + +static void +findItemForVariantData (GVariantBuilder *builder, const char *item, void *userData) +{ + FindItemInVariantData *data = (FindItemInVariantData *) userData; + + if (!data->found) + data->found = g_str_equal (data->item, item); + + g_variant_builder_add (builder, "s", item); +} + +static void +rebuildVariant (GVariantBuilder *builder, + GVariant *originalVariant, + VariantItemCheckAndInsertFunc checkAndInsert, + void *userData) +{ + GVariantIter iter; + char *str; + + g_variant_iter_init (&iter, originalVariant); + while (g_variant_iter_loop (&iter, "s", &str)) + { + (*checkAndInsert) (builder, str, userData); + } +} + +gboolean +appendStringToVariantIfUnique (GVariant **variant, + const char *string) +{ + GVariantBuilder newVariantBuilder; + FindItemInVariantData findItemData; + + memset (&findItemData, 0, sizeof (FindItemInVariantData)); + g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as")); + + findItemData.item = string; + + rebuildVariant (&newVariantBuilder, *variant, findItemForVariantData, &findItemData); + + if (!findItemData.found) + g_variant_builder_add (&newVariantBuilder, "s", string); + + g_variant_unref (*variant); + *variant = g_variant_builder_end (&newVariantBuilder); + + return !findItemData.found; +} + +gboolean removeItemFromVariant (GVariant **variant, + const char *string) +{ + GVariantBuilder newVariantBuilder; + + InsertIfNotEqualData data = + { + FALSE, + string + }; + + g_variant_builder_init (&newVariantBuilder, G_VARIANT_TYPE ("as")); + + rebuildVariant (&newVariantBuilder, *variant, insertIfNotEqual, (void *) &data); + + g_variant_unref (*variant); + *variant = g_variant_builder_end (&newVariantBuilder); + + return data.skipped; +} + +void +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting) +{ + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); + char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); + + ccsGSettingsWrapperResetKey (settings, cleanSettingName); + + free (cleanSettingName); +} + +gchar * +makeSettingPath (const char *currentProfile, CCSSetting *setting) +{ + return makeCompizPluginPath (currentProfile, + ccsPluginGetName (ccsSettingGetParent (setting))); +} + +CCSGSettingsWrapper * +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting) +{ + CCSGSettingsWrapper *ret = NULL; + gchar *pathName = makeSettingPath (ccsGSettingsBackendGetCurrentProfile (backend), setting); + + ret = ccsGSettingsGetSettingsObjectForPluginWithPath (backend, + ccsPluginGetName (ccsSettingGetParent (setting)), + pathName, + ccsPluginGetContext (ccsSettingGetParent (setting))); + + g_free (pathName); + return ret; +} + +gboolean +deleteProfile (CCSBackend *backend, + CCSContext *context, + const char *profile) +{ + GVariant *plugins; + GVariant *profiles; + const char *currentProfile = ccsGSettingsBackendGetCurrentProfile (backend); + gboolean ret = FALSE; + + plugins = ccsGSettingsBackendGetPluginsWithSetKeys (backend); + profiles = ccsGSettingsBackendGetExistingProfiles (backend); + + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (backend, context, plugins, currentProfile); + ccsGSettingsBackendClearPluginsWithSetKeys (backend); + + ret = removeItemFromVariant (&profiles, profile); + + /* Remove the profile from existing-profiles */ + ccsGSettingsBackendSetExistingProfiles (backend, profiles); + ccsGSettingsBackendUpdateProfile (backend, context); + + /* Since we do not call g_settings_set_value on + * plugins, we must also unref the variant */ + g_variant_unref (plugins); + + return ret; +} diff --git a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h index 944f172cac47470d5b488a69165d8cd415eb1ef0..1b1fe91ac5ec4159fba81a4429ed5dc38c8e532e 100644 --- a/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h +++ b/compizconfig/gsettings/gsettings_backend_shared/gsettings_util.h @@ -1,9 +1,40 @@ #ifndef _COMPIZ_GSETTINGS_UTIL_H #define _COMPIZ_GSETTINGS_UTIL_H +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + #include #include -#include +#include + +#include "ccs_gsettings_interface.h" + +/* some forward declarations */ +void +ccsGSettingsValueChanged (GSettings *settings, + gchar *keyname, + gpointer user_data); + +void ccsGSettingsWriteIntegratedOption (CCSBackend *backend, + CCSContext *context, + CCSSetting *setting, + int index); + +CCSStringList +ccsGSettingsGetExistingProfiles (CCSBackend *backend, CCSContext *context); + +void +ccsGSettingsSetIntegration (CCSBackend *backend, CCSIntegration *integration); + +typedef struct _CCSGSettingsBackendPrivate CCSGSettingsBackendPrivate; +typedef struct _CCSGSettingsBackendInterface CCSGSettingsBackendInterface; + +extern const CCSBackendInfo gsettingsBackendInfo; + +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; gchar * getSchemaNameForPlugin (const char *plugin); @@ -41,9 +72,9 @@ appendToPluginsWithSetKeysList (const gchar *plugin, char ***newWrittenPlugins, gsize *newWrittenPluginsSize); -GObject * -findObjectInListWithPropertySchemaName (const gchar *schemaName, - GList *iter); +CCSGSettingsWrapper * +findCCSGSettingsWrapperBySchemaName (const gchar *schemaName, + GList *iter); CCSSettingList filterAllSettingsMatchingType (CCSSettingType type, @@ -56,6 +87,20 @@ filterAllSettingsMatchingPartOfStringIgnoringDashesUnderscoresAndCase (const gch CCSSetting * attemptToFindCCSSettingFromLossyName (CCSSettingList settingList, const gchar *lossyName, CCSSettingType type); +Bool +findSettingAndPluginToUpdateFromPath (CCSGSettingsWrapper *settings, + const char *path, + const gchar *keyName, + CCSContext *context, + CCSPlugin **plugin, + CCSSetting **setting, + char **uncleanKeyName); + +Bool updateSettingWithGSettingsKeyName (CCSBackend *backend, + CCSGSettingsWrapper *settings, + const gchar *keyName, + CCSBackendUpdateFunc updateSetting); + GList * variantTypeToPossibleSettingType (const gchar *vt); @@ -65,4 +110,100 @@ makeCompizProfilePath (const gchar *profilename); gchar * makeCompizPluginPath (const gchar *profileName, const gchar *pluginName); +gchar * +getNameForCCSSetting (CCSSetting *setting); + +Bool +checkReadVariantIsValid (GVariant *gsettingsValue, CCSSettingType type, const gchar *pathName); + +GVariant * +getVariantAtKey (CCSGSettingsWrapper *settings, const char *key, const char *pathName, CCSSettingType type); + +const char * readStringFromVariant (GVariant *gsettingsValue); + +int readIntFromVariant (GVariant *gsettingsValue); + +Bool readBoolFromVariant (GVariant *gsettingsValue); + +float readFloatFromVariant (GVariant *gsettingsValue); + +CCSSettingColorValue readColorFromVariant (GVariant *gsettingsValue, Bool *success); + +CCSSettingKeyValue readKeyFromVariant (GVariant *gsettingsValue, Bool *success); + +CCSSettingButtonValue readButtonFromVariant (GVariant *gsettingsValue, Bool *success); + +unsigned int readEdgeFromVariant (GVariant *gsettingsValue); + +CCSSettingValueList +readListValue (GVariant *gsettingsValue, CCSSetting *setting, CCSObjectAllocationInterface *allocator); + +Bool +writeListValue (CCSSettingValueList list, + CCSSettingType listType, + GVariant **gsettingsValue); + +Bool writeStringToVariant (const char *value, GVariant **variant); + +Bool writeFloatToVariant (float value, GVariant **variant); + +Bool writeIntToVariant (int value, GVariant **variant); + +Bool writeBoolToVariant (Bool value, GVariant **variant); + +Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant); + +Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant); + +Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant); + +Bool writeEdgeToVariant (unsigned int edges, GVariant **variant); + +void writeVariantToKey (CCSGSettingsWrapper *settings, + const char *key, + GVariant *value); + +typedef int (*ComparisonPredicate) (const void *s1, const void *s2); + +int voidcmp0 (const void *v1, const void *v2); + +gboolean +deleteProfile (CCSBackend *backend, + CCSContext *context, + const char *profile); + +gboolean +appendStringToVariantIfUnique (GVariant **variant, + const char *string); + +gboolean +removeItemFromVariant (GVariant **variant, + const char *string); + +CCSSettingValueList +readBoolListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); + +CCSSettingValueList +readIntListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); + +CCSSettingValueList +readFloatListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); + +CCSSettingValueList +readStringListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); + +CCSSettingValueList +readColorListValue (GVariantIter *iter, guint nItems, CCSSetting *setting, CCSObjectAllocationInterface *allocator); + +gchar * +makeSettingPath (const char *currentProfile, CCSSetting *setting); + +CCSGSettingsWrapper * +getSettingsObjectForCCSSetting (CCSBackend *backend, CCSSetting *setting); + +void +resetOptionToDefault (CCSBackend *backend, CCSSetting * setting); + +COMPIZCONFIG_END_DECLS + #endif diff --git a/compizconfig/gsettings/src/gconf-integration.c b/compizconfig/gsettings/src/gconf-integration.c deleted file mode 100644 index b13ffa6f8a0266ad4c82ecde01728782b9a01dee..0000000000000000000000000000000000000000 --- a/compizconfig/gsettings/src/gconf-integration.c +++ /dev/null @@ -1,954 +0,0 @@ -/** - * - * GSettings libccs backend - * - * gconf-integration.c - * - * Copyright (c) 2011 Canonical Ltd - * - * Based on the original compizconfig-backend-gconf - * - * Copyright (c) 2007 Danny Baumann - * - * Parts of this code are taken from libberylsettings - * gconf backend, written by: - * - * Copyright (c) 2006 Robert Carr - * Copyright (c) 2007 Dennis Kasprzyk - * - * 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. - * - * Authored By: - * Sam Spilsbury - * - **/ - -#include "gsettings.h" -#ifdef USE_GCONF -GConfClient *client = NULL; -guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS]; - -const SpecialOptionGConf specialOptions[] = { - {"run_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/panel_run_dialog", OptionKey}, - {"main_menu_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/panel_main_menu", OptionKey}, - {"run_command_screenshot_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/run_command_screenshot", OptionKey}, - {"run_command_window_screenshot_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/run_command_window_screenshot", OptionKey}, - {"run_command_terminal_key", "gnomecompat", FALSE, - METACITY "/global_keybindings/run_command_terminal", OptionKey}, - - {"toggle_window_maximized_key", "core", FALSE, - METACITY "/window_keybindings/toggle_maximized", OptionKey}, - {"minimize_window_key", "core", FALSE, - METACITY "/window_keybindings/minimize", OptionKey}, - {"maximize_window_key", "core", FALSE, - METACITY "/window_keybindings/maximize", OptionKey}, - {"unmaximize_window_key", "core", FALSE, - METACITY "/window_keybindings/unmaximize", OptionKey}, - {"maximize_window_horizontally_key", "core", FALSE, - METACITY "/window_keybindings/maximize_horizontally", OptionKey}, - {"maximize_window_vertically_key", "core", FALSE, - METACITY "/window_keybindings/maximize_vertically", OptionKey}, - {"raise_window_key", "core", FALSE, - METACITY "/window_keybindings/raise", OptionKey}, - {"lower_window_key", "core", FALSE, - METACITY "/window_keybindings/lower", OptionKey}, - {"close_window_key", "core", FALSE, - METACITY "/window_keybindings/close", OptionKey}, - {"toggle_window_shaded_key", "core", FALSE, - METACITY "/window_keybindings/toggle_shaded", OptionKey}, - - {"show_desktop_key", "core", FALSE, - METACITY "/global_keybindings/show_desktop", OptionKey}, - - {"initiate_key", "move", FALSE, - METACITY "/window_keybindings/begin_move", OptionKey}, - {"initiate_key", "resize", FALSE, - METACITY "/window_keybindings/begin_resize", OptionKey}, - {"window_menu_key", "core", FALSE, - METACITY "/window_keybindings/activate_window_menu", OptionKey}, - - /* integration of Metacity's mouse_button_modifier option */ - {"initiate_button", "move", FALSE, - METACITY "/window_keybindings/begin_move", OptionSpecial}, - {"initiate_button", "resize", FALSE, - METACITY "/window_keybindings/begin_resize", OptionSpecial}, - {"window_menu_button", "core", FALSE, - METACITY "/window_keybindings/activate_window_menu", OptionSpecial}, - {"mouse_button_modifier", NULL, FALSE, - METACITY "/general/mouse_button_modifier", OptionSpecial}, - /* integration of the Metacity's option to swap mouse buttons */ - {"resize_with_right_button", NULL, FALSE, - METACITY "/general/resize_with_right_button", OptionSpecial}, - - {"visual_bell", "fade", TRUE, - METACITY "/general/visual_bell", OptionBool}, - {"fullscreen_visual_bell", "fade", TRUE, - METACITY "/general/visual_bell_type", OptionSpecial}, - - {"next_key", "staticswitcher", FALSE, - METACITY "/global_keybindings/switch_windows", OptionKey}, - {"prev_key", "staticswitcher", FALSE, - METACITY "/global_keybindings/switch_windows_backward", OptionKey}, - - {"toggle_sticky_key", "extrawm", FALSE, - METACITY "/window_keybindings/toggle_on_all_workspaces", OptionKey}, - {"toggle_fullscreen_key", "extrawm", FALSE, - METACITY "/window_keybindings/toggle_fullscreen", OptionKey}, - - {"command0", "commands", FALSE, - METACITY "/keybinding_commands/command_1", OptionString}, - {"command1", "commands", FALSE, - METACITY "/keybinding_commands/command_2", OptionString}, - {"command2", "commands", FALSE, - METACITY "/keybinding_commands/command_3", OptionString}, - {"command3", "commands", FALSE, - METACITY "/keybinding_commands/command_4", OptionString}, - {"command4", "commands", FALSE, - METACITY "/keybinding_commands/command_5", OptionString}, - {"command5", "commands", FALSE, - METACITY "/keybinding_commands/command_6", OptionString}, - {"command6", "commands", FALSE, - METACITY "/keybinding_commands/command_7", OptionString}, - {"command7", "commands", FALSE, - METACITY "/keybinding_commands/command_8", OptionString}, - {"command8", "commands", FALSE, - METACITY "/keybinding_commands/command_9", OptionString}, - {"command9", "commands", FALSE, - METACITY "/keybinding_commands/command_10", OptionString}, - {"command10", "commands", FALSE, - METACITY "/keybinding_commands/command_11", OptionString}, - {"command11", "commands", FALSE, - METACITY "/keybinding_commands/command_12", OptionString}, - - {"run_command0_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_1", OptionKey}, - {"run_command1_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_2", OptionKey}, - {"run_command2_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_3", OptionKey}, - {"run_command3_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_4", OptionKey}, - {"run_command4_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_5", OptionKey}, - {"run_command5_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_6", OptionKey}, - {"run_command6_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_7", OptionKey}, - {"run_command7_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_8", OptionKey}, - {"run_command8_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_9", OptionKey}, - {"run_command9_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_10", OptionKey}, - {"run_command10_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_11", OptionKey}, - {"run_command11_key", "commands", FALSE, - METACITY "/global_keybindings/run_command_12", OptionKey}, - - {"rotate_to_1_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_1", OptionKey}, - {"rotate_to_2_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_2", OptionKey}, - {"rotate_to_3_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_3", OptionKey}, - {"rotate_to_4_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_4", OptionKey}, - {"rotate_to_5_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_5", OptionKey}, - {"rotate_to_6_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_6", OptionKey}, - {"rotate_to_7_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_7", OptionKey}, - {"rotate_to_8_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_8", OptionKey}, - {"rotate_to_9_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_9", OptionKey}, - {"rotate_to_10_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_10", OptionKey}, - {"rotate_to_11_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_11", OptionKey}, - {"rotate_to_12_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_12", OptionKey}, - - {"rotate_left_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_left", OptionKey}, - {"rotate_right_key", "rotate", FALSE, - METACITY "/global_keybindings/switch_to_workspace_right", OptionKey}, - - {"switch_to_1_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_1", OptionKey}, - {"switch_to_2_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_2", OptionKey}, - {"switch_to_3_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_3", OptionKey}, - {"switch_to_4_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_4", OptionKey}, - {"switch_to_5_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_5", OptionKey}, - {"switch_to_6_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_6", OptionKey}, - {"switch_to_7_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_7", OptionKey}, - {"switch_to_8_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_8", OptionKey}, - {"switch_to_9_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_9", OptionKey}, - {"switch_to_10_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_10", OptionKey}, - {"switch_to_11_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_11", OptionKey}, - {"switch_to_12_key", "vpswitch", FALSE, - METACITY "/global_keybindings/switch_to_workspace_12", OptionKey}, - - {"up_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_up", OptionKey}, - {"down_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_down", OptionKey}, - {"left_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_left", OptionKey}, - {"right_key", "wall", FALSE, - METACITY "/global_keybindings/switch_to_workspace_right", OptionKey}, - {"left_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_left", OptionKey}, - {"right_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_right", OptionKey}, - {"up_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_up", OptionKey}, - {"down_window_key", "wall", FALSE, - METACITY "/window_keybindings/move_to_workspace_down", OptionKey}, - - {"put_topleft_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_nw", OptionKey}, - {"put_topright_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_ne", OptionKey}, - {"put_bottomleft_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_sw", OptionKey}, - {"put_bottomright_key", "put", FALSE, - METACITY "/window_keybindings/move_to_corner_se", OptionKey}, - {"put_left_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_w", OptionKey}, - {"put_right_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_e", OptionKey}, - {"put_top_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_n", OptionKey}, - {"put_bottom_key", "put", FALSE, - METACITY "/window_keybindings/move_to_side_s", OptionKey}, - - {"rotate_to_1_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_1", OptionKey}, - {"rotate_to_2_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_2", OptionKey}, - {"rotate_to_3_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_3", OptionKey}, - {"rotate_to_4_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_4", OptionKey}, - {"rotate_to_5_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_5", OptionKey}, - {"rotate_to_6_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_6", OptionKey}, - {"rotate_to_7_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_7", OptionKey}, - {"rotate_to_8_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_8", OptionKey}, - {"rotate_to_9_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_9", OptionKey}, - {"rotate_to_10_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_10", OptionKey}, - {"rotate_to_11_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_11", OptionKey}, - {"rotate_to_12_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_12", OptionKey}, - - {"rotate_left_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_left", OptionKey}, - {"rotate_right_window_key", "rotate", FALSE, - METACITY "/window_keybindings/move_to_workspace_right", OptionKey}, - - {"command_screenshot", "gnomecompat", FALSE, - METACITY "/keybinding_commands/command_screenshot", OptionString}, - {"command_window_screenshot", "gnomecompat", FALSE, - METACITY "/keybinding_commands/command_window_screenshot", OptionString}, - {"command_terminal", "gnomecompat", FALSE, - "/desktop/gnome/applications/terminal/exec", OptionString}, - - {"current_viewport", "thumbnail", TRUE, - "/apps/panel/applets/window_list/prefs/display_all_workspaces", - OptionSpecial}, - - {"autoraise", "core", FALSE, - METACITY "/general/auto_raise", OptionBool}, - {"autoraise_delay", "core", FALSE, - METACITY "/general/auto_raise_delay", OptionInt}, - {"raise_on_click", "core", FALSE, - METACITY "/general/raise_on_click", OptionBool}, - {"click_to_focus", "core", FALSE, - METACITY "/general/focus_mode", OptionSpecial}, - - {"audible_bell", "core", FALSE, - METACITY "/general/audible_bell", OptionBool}, - /*{"hsize", "core", TRUE, - METACITY "/general/num_workspaces", OptionInt},*/ -}; - -static const char* watchedGConfGnomeDirectories[] = { - METACITY, - "/desktop/gnome/applications/terminal", - "/apps/panel/applets/window_list/prefs" -}; - -#define N_SOPTIONS (sizeof (specialOptions) / sizeof (struct _SpecialOptionGConf)) - -static CCSSetting * -findDisplaySettingForPlugin (CCSContext *context, - const char *plugin, - const char *setting) -{ - CCSPlugin *p; - CCSSetting *s; - - p = ccsFindPlugin (context, plugin); - if (!p) - return NULL; - - s = ccsFindSetting (p, setting); - if (!s) - return NULL; - - return s; -} - -Bool -isGConfIntegratedOption (CCSSetting *setting, - int *index) -{ - unsigned int i; - - for (i = 0; i < N_SOPTIONS; i++) - { - const SpecialOptionGConf *opt = &specialOptions[i]; - - if (strcmp (ccsSettingGetName (setting), opt->settingName) != 0) - continue; - - if (ccsPluginGetName (ccsSettingGetParent (setting))) - { - if (!opt->pluginName) - continue; - if (strcmp (ccsPluginGetName (ccsSettingGetParent (setting)), opt->pluginName) != 0) - continue; - } - else - { - if (opt->pluginName) - continue; - } - - if (index) - *index = i; - - return TRUE; - } - - return FALSE; -} - -void -gnomeGConfValueChanged (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer user_data) -{ - CCSContext *context = (CCSContext *)user_data; - char *keyName = (char*) gconf_entry_get_key (entry); - int i, last = 0, num = 0; - Bool needInit = TRUE; - - if (!ccsGetIntegrationEnabled (context)) - return; - - /* we have to loop multiple times here, because one Gnome - option may be integrated with multiple Compiz options */ - - while (1) - { - for (i = last, num = -1; i < N_SOPTIONS; i++) - { - if (strcmp (specialOptions[i].gnomeName, keyName) == 0) - { - num = i; - last = i + 1; - break; - } - } - - if (num < 0) - break; - - if ((strcmp (specialOptions[num].settingName, - "mouse_button_modifier") == 0) || - (strcmp (specialOptions[num].settingName, - "resize_with_right_button") == 0)) - { - CCSSetting *s; - - if (needInit) - { - readInit (context); - needInit = FALSE; - } - - s = findDisplaySettingForPlugin (context, "core", - "window_menu_button"); - if (s) - readSetting (context, s); - - s = findDisplaySettingForPlugin (context, "move", - "initiate_button"); - if (s) - readSetting (context, s); - - s = findDisplaySettingForPlugin (context, "resize", - "initiate_button"); - if (s) - readSetting (context, s); - } - else - { - CCSPlugin *plugin = NULL; - CCSSetting *setting; - SpecialOptionGConf *opt = (SpecialOptionGConf *) &specialOptions[num]; - - plugin = ccsFindPlugin (context, (char*) opt->pluginName); - if (plugin) - { - for (i = 0; i < 1; i++) - { - setting = ccsFindSetting (plugin, (char*) opt->settingName); - - if (setting) - { - if (needInit) - { - readInit (context); - needInit = FALSE; - } - readSetting (context, setting); - } - - /* do not read display settings multiple - times for multiscreen environments */ - } - } - } - } -} - -void -initGConfClient (CCSContext *context) -{ - int i; - - client = gconf_client_get_default (); - - for (i = 0; i < NUM_WATCHED_DIRS; i++) - { - gnomeGConfNotifyIds[i] = gconf_client_notify_add (client, - watchedGConfGnomeDirectories[i], - gnomeGConfValueChanged, context, - NULL, NULL); - gconf_client_add_dir (client, watchedGConfGnomeDirectories[i], - GCONF_CLIENT_PRELOAD_NONE, NULL); - } -} - -void -finiGConfClient (void) -{ - int i; - - for (i = 0; i < NUM_WATCHED_DIRS; i++) - { - if (gnomeGConfNotifyIds[i]) - { - gconf_client_notify_remove (client, gnomeGConfNotifyIds[0]); - gnomeGConfNotifyIds[i] = 0; - } - gconf_client_remove_dir (client, watchedGConfGnomeDirectories[i], NULL); - } - gconf_client_suggest_sync (client, NULL); - - g_object_unref (client); - client = NULL; -} - -static unsigned int -getGnomeMouseButtonModifier(void) -{ - unsigned int modMask = 0; - GError *err = NULL; - char *value; - - value = gconf_client_get_string (client, - METACITY "/general/mouse_button_modifier", - &err); - - if (err) - { - g_error_free (err); - return 0; - } - - if (!value) - return 0; - - modMask = ccsStringToModifiers (value); - g_free (value); - - return modMask; -} - -static unsigned int -getButtonBindingForSetting (CCSContext *context, - const char *plugin, - const char *setting) -{ - CCSSetting *s; - - s = findDisplaySettingForPlugin (context, plugin, setting); - if (!s) - return 0; - - if (ccsSettingGetType (s) != TypeButton) - return 0; - - return ccsSettingGetValue (s)->value.asButton.button; -} - -Bool -readGConfIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index) -{ - GConfValue *gconfValue; - GError *err = NULL; - Bool ret = FALSE; - - ret = readOption (setting); - - gconfValue = gconf_client_get (client, - specialOptions[index].gnomeName, - &err); - - if (err) - { - g_error_free (err); - return FALSE; - } - - if (!gconfValue) - return FALSE; - - switch (specialOptions[index].type) { - case OptionInt: - if (gconfValue->type == GCONF_VALUE_INT) - { - guint value; - - value = gconf_value_get_int (gconfValue); - ccsSetInt (setting, value, TRUE); - ret = TRUE; - } - break; - case OptionBool: - if (gconfValue->type == GCONF_VALUE_BOOL) - { - gboolean value; - - value = gconf_value_get_bool (gconfValue); - ccsSetBool (setting, value ? TRUE : FALSE, TRUE); - ret = TRUE; - } - break; - case OptionString: - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *value; - - value = gconf_value_get_string (gconfValue); - if (value) - { - ccsSetString (setting, value, TRUE); - ret = TRUE; - } - } - break; - case OptionKey: - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *value; - - value = gconf_value_get_string (gconfValue); - if (value) - { - CCSSettingKeyValue key; - - memset (&key, 0, sizeof (CCSSettingKeyValue)); - ccsGetKey (setting, &key); - if (ccsStringToKeyBinding (value, &key)) - { - ccsSetKey (setting, key, TRUE); - ret = TRUE; - } - } - } - break; - case OptionSpecial: - { - const char *settingName = specialOptions[index].settingName; - const char *pluginName = specialOptions[index].pluginName; - - if (strcmp (settingName, "current_viewport") == 0) - { - if (gconfValue->type == GCONF_VALUE_BOOL) - { - gboolean showAll; - - showAll = gconf_value_get_bool (gconfValue); - ccsSetBool (setting, !showAll, TRUE); - ret = TRUE; - } - } - else if (strcmp (settingName, "fullscreen_visual_bell") == 0) - { - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *value; - - value = gconf_value_get_string (gconfValue); - if (value) - { - Bool fullscreen; - - fullscreen = strcmp (value, "fullscreen") == 0; - ccsSetBool (setting, fullscreen, TRUE); - ret = TRUE; - } - } - } - else if (strcmp (settingName, "click_to_focus") == 0) - { - if (gconfValue->type == GCONF_VALUE_STRING) - { - const char *focusMode; - - focusMode = gconf_value_get_string (gconfValue); - - if (focusMode) - { - Bool clickToFocus = (strcmp (focusMode, "click") == 0); - ccsSetBool (setting, clickToFocus, TRUE); - ret = TRUE; - } - } - } - else if (((strcmp (settingName, "initiate_button") == 0) && - ((strcmp (pluginName, "move") == 0) || - (strcmp (pluginName, "resize") == 0))) || - ((strcmp (settingName, "window_menu_button") == 0) && - (strcmp (pluginName, "core") == 0))) - { - gboolean resizeWithRightButton; - CCSSettingButtonValue button; - - memset (&button, 0, sizeof (CCSSettingButtonValue)); - ccsGetButton (setting, &button); - - button.buttonModMask = getGnomeMouseButtonModifier (); - - resizeWithRightButton = - gconf_client_get_bool (client, METACITY - "/general/resize_with_right_button", - &err); - - if (strcmp (settingName, "window_menu_button") == 0) - button.button = resizeWithRightButton ? 2 : 3; - else if (strcmp (pluginName, "resize") == 0) - button.button = resizeWithRightButton ? 3 : 2; - else - button.button = 1; - - ccsSetButton (setting, button, TRUE); - ret = TRUE; - } - } - break; - default: - break; - } - - gconf_value_free (gconfValue); - - return ret; -} - -static Bool -setGnomeMouseButtonModifier (unsigned int modMask) -{ - char *modifiers, *currentValue; - GError *err = NULL; - - modifiers = ccsModifiersToString (modMask); - if (!modifiers) - return FALSE; - - currentValue = gconf_client_get_string (client, - METACITY - "/general/mouse_button_modifier", - &err); - if (err) - { - free (modifiers); - g_error_free (err); - return FALSE; - } - - if (!currentValue || (strcmp (currentValue, modifiers) != 0)) - gconf_client_set_string (client, - METACITY "/general/mouse_button_modifier", - modifiers, NULL); - if (currentValue) - g_free (currentValue); - - free (modifiers); - - return TRUE; -} - -static void -setButtonBindingForSetting (CCSContext *context, - const char *plugin, - const char *setting, - unsigned int button, - unsigned int buttonModMask) -{ - CCSSetting *s; - CCSSettingButtonValue value; - - s = findDisplaySettingForPlugin (context, plugin, setting); - if (!s) - return; - - if (ccsSettingGetType (s) != TypeButton) - return; - - value = ccsSettingGetValue (s)->value.asButton; - - if ((value.button != button) || (value.buttonModMask != buttonModMask)) - { - value.button = button; - value.buttonModMask = buttonModMask; - - ccsSetButton (s, value, TRUE); - } -} - -void -writeGConfIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index) -{ - GError *err = NULL; - const char *optionName = specialOptions[index].gnomeName; - - switch (specialOptions[index].type) - { - case OptionInt: - { - int newValue, currentValue; - if (!ccsGetInt (setting, &newValue)) - break; - currentValue = gconf_client_get_int (client, optionName, &err); - - if (!err && (currentValue != newValue)) - gconf_client_set_int(client, specialOptions[index].gnomeName, - newValue, NULL); - } - break; - case OptionBool: - { - Bool newValue; - gboolean currentValue; - if (!ccsGetBool (setting, &newValue)) - break; - currentValue = gconf_client_get_bool (client, optionName, &err); - - if (!err && ((currentValue && !newValue) || - (!currentValue && newValue))) - gconf_client_set_bool (client, specialOptions[index].gnomeName, - newValue, NULL); - } - break; - case OptionString: - { - char *newValue; - gchar *currentValue; - if (!ccsGetString (setting, &newValue)) - break; - currentValue = gconf_client_get_string (client, optionName, &err); - - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - } - break; - case OptionKey: - { - char *newValue; - gchar *currentValue; - - newValue = ccsKeyBindingToString (&(ccsSettingGetValue (setting)->value.asKey)); - if (newValue) - { - if (strcmp (newValue, "Disabled") == 0) - { - /* Metacity doesn't like "Disabled", it wants "disabled" */ - newValue[0] = 'd'; - } - - currentValue = gconf_client_get_string (client, - optionName, &err); - - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - free (newValue); - } - } - break; - case OptionSpecial: - { - const char *settingName = specialOptions[index].settingName; - const char *pluginName = specialOptions[index].pluginName; - - if (strcmp (settingName, "current_viewport") == 0) - { - Bool currentViewport; - - if (!ccsGetBool (setting, ¤tViewport)) - break; - - gconf_client_set_bool (client, optionName, - !currentViewport, NULL); - } - else if (strcmp (settingName, "fullscreen_visual_bell") == 0) - { - Bool fullscreen; - gchar *currentValue, *newValue; - if (!ccsGetBool (setting, &fullscreen)) - break; - - newValue = fullscreen ? "fullscreen" : "frame_flash"; - currentValue = gconf_client_get_string (client, - optionName, &err); - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - } - else if (strcmp (settingName, "click_to_focus") == 0) - { - Bool clickToFocus; - gchar *newValue, *currentValue; - if (!ccsGetBool (setting, &clickToFocus)) - break; - - newValue = clickToFocus ? "click" : "sloppy"; - currentValue = gconf_client_get_string (client, - optionName, &err); - - if (!err && currentValue) - { - if (strcmp (currentValue, newValue) != 0) - gconf_client_set_string (client, optionName, - newValue, NULL); - g_free (currentValue); - } - } - else if (((strcmp (settingName, "initiate_button") == 0) && - ((strcmp (pluginName, "move") == 0) || - (strcmp (pluginName, "resize") == 0))) || - ((strcmp (settingName, "window_menu_button") == 0) && - (strcmp (pluginName, "core") == 0))) - { - unsigned int modMask; - Bool resizeWithRightButton = FALSE; - gboolean currentValue; - - if ((getButtonBindingForSetting (context, "resize", - "initiate_button") == 3) || - (getButtonBindingForSetting (context, "core", - "window_menu_button") == 2)) - { - resizeWithRightButton = TRUE; - } - - currentValue = - gconf_client_get_bool (client, METACITY - "/general/resize_with_right_button", - &err); - - if (!err && ((currentValue && !resizeWithRightButton) || - (!currentValue && resizeWithRightButton))) - { - gconf_client_set_bool (client, - METACITY - "/general/resize_with_right_button", - resizeWithRightButton, NULL); - } - - modMask = ccsSettingGetValue (setting)->value.asButton.buttonModMask; - if (setGnomeMouseButtonModifier (modMask)) - { - setButtonBindingForSetting (context, "move", - "initiate_button", 1, modMask); - setButtonBindingForSetting (context, "resize", - "initiate_button", - resizeWithRightButton ? 3 : 2, - modMask); - setButtonBindingForSetting (context, "core", - "window_menu_button", - resizeWithRightButton ? 2 : 3, - modMask); - } - } - } - break; - } - - if (err) - g_error_free (err); -} -#endif diff --git a/compizconfig/gsettings/src/gsettings.c b/compizconfig/gsettings/src/gsettings.c index f06b8dc03394b76a44d82dcec3710f73c6cf33d5..346dcee91943936744407c47bb4a3a49cc4074f9 100644 --- a/compizconfig/gsettings/src/gsettings.c +++ b/compizconfig/gsettings/src/gsettings.c @@ -34,383 +34,55 @@ #define CCS_LOG_DOMAIN "gsettings" #include "gsettings.h" - -static void -valueChanged (GSettings *settings, - gchar *keyname, - gpointer user_data); - -static GList *settingsList = NULL; -static GSettings *compizconfigSettings = NULL; -static GSettings *currentProfileSettings = NULL; - -char *currentProfile = NULL; - -/* some forward declarations */ -static void writeIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index); - -static GSettings * -getSettingsObjectForPluginWithPath (const char *plugin, - const char *path, - CCSContext *context) -{ - GSettings *settingsObj = NULL; - gchar *schemaName = getSchemaNameForPlugin (plugin); - GVariant *writtenPlugins; - gsize newWrittenPluginsSize; - gchar **newWrittenPlugins; - - settingsObj = (GSettings *) findObjectInListWithPropertySchemaName (schemaName, settingsList); - - if (settingsObj) - { - g_free (schemaName); - return settingsObj; - } - - /* No existing settings object found for this schema, create one */ - - settingsObj = g_settings_new_with_path (schemaName, path); - - g_signal_connect (G_OBJECT (settingsObj), "changed", (GCallback) valueChanged, (gpointer) context); - - settingsList = g_list_append (settingsList, (void *) settingsObj); - - /* Also write the plugin name to the list of modified plugins so - * that when we delete the profile the keys for that profile are also - * unset FIXME: This could be a little more efficient, like we could - * store keys that have changed from their defaults ... though - * gsettings doesn't seem to give you a way to get all of the schemas */ - - writtenPlugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys"); - - appendToPluginsWithSetKeysList (plugin, writtenPlugins, &newWrittenPlugins, &newWrittenPluginsSize); - - g_settings_set_strv (currentProfileSettings, "plugins-with-set-keys", (const gchar * const *)newWrittenPlugins); - - g_free (schemaName); - g_strfreev (newWrittenPlugins); - - return settingsObj; -} - -static gchar * -makeSettingPath (CCSSetting *setting) +#include "gsettings_shared.h" +#include "ccs_gsettings_backend_interface.h" +#include "ccs_gsettings_backend.h" +#include "ccs_gsettings_interface.h" +#include "ccs_gsettings_interface_wrapper.h" + +GVariant * +getVariantForCCSSetting (CCSBackend *backend, CCSSetting *setting) { - return makeCompizPluginPath (currentProfile, - ccsPluginGetName (ccsSettingGetParent (setting))); -} - -static GSettings * -getSettingsObjectForCCSSetting (CCSSetting *setting) -{ - GSettings *ret = NULL; - gchar *pathName = makeSettingPath (setting); - - ret = getSettingsObjectForPluginWithPath (ccsPluginGetName (ccsSettingGetParent (setting)), - pathName, - ccsPluginGetContext (ccsSettingGetParent (setting))); - - g_free (pathName); - return ret; + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); + char *cleanSettingName = getNameForCCSSetting (setting); + gchar *pathName = makeSettingPath (ccsGSettingsBackendGetCurrentProfile (backend), setting); + GVariant *gsettingsValue = getVariantAtKey (settings, + cleanSettingName, + pathName, + ccsSettingGetType (setting)); + + return gsettingsValue; } static Bool -isIntegratedOption (CCSSetting *setting, - int *index) -{ -#ifdef USE_GCONF - return isGConfIntegratedOption (setting, index); -#else - return FALSE; -#endif -} - -static void -valueChanged (GSettings *settings, - gchar *keyName, - gpointer user_data) -{ - CCSContext *context = (CCSContext *)user_data; - char *uncleanKeyName; - char *path, *pathOrig; - char *pluginName; - int index; - unsigned int screenNum; - CCSPlugin *plugin; - CCSSetting *setting; - - g_object_get (G_OBJECT (settings), "path", &pathOrig, NULL); - - path = pathOrig; - - if (!decomposeGSettingsPath (path, &pluginName, &screenNum)) - { - g_free (pathOrig); - return; - } - - plugin = ccsFindPlugin (context, pluginName); - - uncleanKeyName = translateKeyForCCS (keyName); - - setting = ccsFindSetting (plugin, uncleanKeyName); - if (!setting) - { - /* Couldn't find setting straight off the bat, - * try and find the best match */ - GVariant *value = g_settings_get_value (settings, keyName); - - if (value) - { - GList *possibleSettingTypes = variantTypeToPossibleSettingType (g_variant_get_type_string (value)); - GList *iter = possibleSettingTypes; - - while (iter) - { - setting = attemptToFindCCSSettingFromLossyName (ccsGetPluginSettings (plugin), - keyName, - (CCSSettingType) GPOINTER_TO_INT (iter->data)); - - if (setting) - break; - - iter = iter->next; - } - - g_list_free (possibleSettingTypes); - g_variant_unref (value); - } - - /* We hit a situation where either the key stored in GSettings couldn't be - * matched at all to a key in the xml file, or where there were multiple matches. - * Unfortunately, there isn't much we can do about this, other than try - * and warn the user and bail out. It just means that if the key was updated - * externally we won't know about the change until the next reload of settings */ - if (!setting) - { - ccsWarning ("Unable to find setting %s, for path %s", uncleanKeyName, path); - g_free (pluginName); - free (uncleanKeyName); - g_free (pathOrig); - return; - } - } - - readInit (context); - if (!readOption (setting)) - { - ccsResetToDefault (setting, TRUE); - } - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - writeInit (context); - writeIntegratedOption (context, setting, index); - } - - g_free (pluginName); - free (uncleanKeyName); - g_free (pathOrig); -} - -static Bool -readListValue (CCSSetting *setting) -{ - GSettings *settings = getSettingsObjectForCCSSetting (setting); - gboolean hasVariantType; - unsigned int nItems, i = 0; - CCSSettingValueList list = NULL; - GVariant *value; - GVariantIter iter; - - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - hasVariantType = compizconfigTypeHasVariantType (ccsSettingGetInfo (setting)->forList.listType); - - if (!hasVariantType) - return FALSE; - - value = g_settings_get_value (settings, cleanSettingName); - if (!value) - { - ccsSetList (setting, NULL, TRUE); - return TRUE; - } - - g_variant_iter_init (&iter, value); - nItems = g_variant_iter_n_children (&iter); - - switch (ccsSettingGetInfo (setting)->forList.listType) - { - case TypeBool: - { - Bool *array = malloc (nItems * sizeof (Bool)); - Bool *arrayCounter = array; - gboolean value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "b", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromBoolArray (array, nItems, setting); - free (array); - } - break; - case TypeInt: - { - int *array = malloc (nItems * sizeof (int)); - int *arrayCounter = array; - gint value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "i", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromIntArray (array, nItems, setting); - free (array); - } - break; - case TypeFloat: - { - double *array = malloc (nItems * sizeof (double)); - double *arrayCounter = array; - gdouble value; - - if (!array) - break; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_loop (&iter, "d", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromFloatArray ((float *) array, nItems, setting); - free (array); - } - break; - case TypeString: - case TypeMatch: - { - gchar **array = g_malloc0 ((nItems + 1) * sizeof (gchar *)); - gchar **arrayCounter = array; - gchar *value; - - if (!array) - break; - - array[nItems] = NULL; - - /* Reads each item from the variant into arrayCounter */ - while (g_variant_iter_next (&iter, "s", &value)) - *arrayCounter++ = value; - - list = ccsGetValueListFromStringArray (array, nItems, setting); - g_strfreev (array); - } - break; - case TypeColor: - { - CCSSettingColorValue *array; - char *colorValue; - array = malloc (nItems * sizeof (CCSSettingColorValue)); - if (!array) - break; - - while (g_variant_iter_loop (&iter, "s", &colorValue)) - { - memset (&array[i], 0, sizeof (CCSSettingColorValue)); - ccsStringToColor (colorValue, - &array[i]); - } - list = ccsGetValueListFromColorArray (array, nItems, setting); - free (array); - } - break; - default: - break; - } - - free (cleanSettingName); - - if (list) - { - ccsSetList (setting, list, TRUE); - ccsSettingValueListFree (list, TRUE); - return TRUE; - } - - return FALSE; -} - -static Bool -readIntegratedOption (CCSContext *context, +readIntegratedOption (CCSBackend *backend, CCSSetting *setting, - int index) + CCSIntegratedSetting *integrated) { -#ifdef USE_GCONF - return readGConfIntegratedOption (context, setting, index); -#else - return FALSE; -#endif + return ccsGSettingsBackendReadIntegratedOption (backend, setting, integrated); } Bool -readOption (CCSSetting * setting) +readOption (CCSBackend *backend, CCSSetting * setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); - GVariant *gsettingsValue = NULL; Bool ret = FALSE; + GVariant *gsettingsValue = NULL; /* It is impossible for certain settings to have a schema, * such as actions and read only settings, so in that case * just return FALSE since compizconfig doesn't expect us * to read them anyways */ - - if (ccsSettingGetType (setting) == TypeAction || - ccsSettingIsReadOnly (setting)) - { + if (!ccsSettingIsReadableByBackend (setting)) return FALSE; - } - - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - /* first check if the key is set */ - gsettingsValue = g_settings_get_value (settings, cleanSettingName); - - if (!gsettingsValue) - { - free (cleanSettingName); - return FALSE; - } - if (!variantIsValidForCCSType (gsettingsValue, ccsSettingGetType (setting))) - { - gchar *pathName = makeSettingPath (setting); - ccsWarning ("There is an unsupported value at path %s. " - "Settings from this path won't be read. Try to remove " - "that value so that operation can continue properly.", - pathName); - g_free (pathName); - free (cleanSettingName); - g_variant_unref (gsettingsValue); - return FALSE; - } + gsettingsValue = getVariantForCCSSetting (backend, setting); switch (ccsSettingGetType (setting)) { case TypeString: { const char *value; - value = g_variant_get_string (gsettingsValue, NULL); + value = readStringFromVariant (gsettingsValue); if (value) { ccsSetString (setting, value, TRUE); @@ -421,7 +93,7 @@ readOption (CCSSetting * setting) case TypeMatch: { const char * value; - value = g_variant_get_string (gsettingsValue, NULL); + value = readStringFromVariant (gsettingsValue); if (value) { ccsSetMatch (setting, value, TRUE); @@ -432,7 +104,7 @@ readOption (CCSSetting * setting) case TypeInt: { int value; - value = g_variant_get_int32 (gsettingsValue); + value = readIntFromVariant (gsettingsValue); ccsSetInt (setting, value, TRUE); ret = TRUE; @@ -440,29 +112,28 @@ readOption (CCSSetting * setting) break; case TypeBool: { - gboolean value; - value = g_variant_get_boolean (gsettingsValue); + Bool value; + value = readBoolFromVariant (gsettingsValue); - ccsSetBool (setting, value ? TRUE : FALSE, TRUE); + ccsSetBool (setting, value, TRUE); ret = TRUE; } break; case TypeFloat: { - double value; - value = g_variant_get_double (gsettingsValue); + float value; + value = readFloatFromVariant (gsettingsValue); - ccsSetFloat (setting, (float)value, TRUE); - ret = TRUE; + ccsSetFloat (setting, value, TRUE); + ret = TRUE; } break; case TypeColor: { - const char *value; - CCSSettingColorValue color; - value = g_variant_get_string (gsettingsValue, NULL); + Bool success = FALSE; + CCSSettingColorValue color = readColorFromVariant (gsettingsValue, &success); - if (value && ccsStringToColor (value, &color)) + if (success) { ccsSetColor (setting, color, TRUE); ret = TRUE; @@ -471,11 +142,10 @@ readOption (CCSSetting * setting) break; case TypeKey: { - const char *value; - CCSSettingKeyValue key; - value = g_variant_get_string (gsettingsValue, NULL); + Bool success = FALSE; + CCSSettingKeyValue key = readKeyFromVariant (gsettingsValue, &success); - if (value && ccsStringToKeyBinding (value, &key)) + if (success) { ccsSetKey (setting, key, TRUE); ret = TRUE; @@ -484,11 +154,10 @@ readOption (CCSSetting * setting) break; case TypeButton: { - const char *value; - CCSSettingButtonValue button; - value = g_variant_get_string (gsettingsValue, NULL); + Bool success = FALSE; + CCSSettingButtonValue button = readButtonFromVariant (gsettingsValue, &success); - if (value && ccsStringToButtonBinding (value, &button)) + if (success) { ccsSetButton (setting, button, TRUE); ret = TRUE; @@ -497,175 +166,68 @@ readOption (CCSSetting * setting) break; case TypeEdge: { - const char *value; - value = g_variant_get_string (gsettingsValue, NULL); + unsigned int edges = readEdgeFromVariant (gsettingsValue); - if (value) - { - unsigned int edges; - edges = ccsStringToEdges (value); - ccsSetEdge (setting, edges, TRUE); - ret = TRUE; - } + ccsSetEdge (setting, edges, TRUE); + ret = TRUE; } break; case TypeBell: { - gboolean value; - value = g_variant_get_boolean (gsettingsValue); + Bool value; + value = readBoolFromVariant (gsettingsValue); - ccsSetBell (setting, value ? TRUE : FALSE, TRUE); + ccsSetBell (setting, value, TRUE); ret = TRUE; } break; case TypeList: - ret = readListValue (setting); - break; - default: - ccsWarning ("Attempt to read unsupported setting type %d!", - ccsSettingGetType (setting)); - break; - } - - free (cleanSettingName); - g_variant_unref (gsettingsValue); - - return ret; -} + { + CCSSettingValueList list = readListValue (gsettingsValue, setting, &ccsDefaultObjectAllocator); -static void -writeListValue (CCSSetting *setting, - char *pathName) -{ - GSettings *settings = getSettingsObjectForCCSSetting (setting); - GVariant *value = NULL; - CCSSettingValueList list; + if (list) + { + CCSSettingValueList iter = list; - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - if (!ccsGetList (setting, &list)) - return; + while (iter) + { + ((CCSSettingValue *) iter->data)->parent = setting; + iter = iter->next; + } - switch (ccsSettingGetInfo (setting)->forList.listType) - { - case TypeBool: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ab")); - while (list) - { - g_variant_builder_add (builder, "b", list->data->value.asBool); - list = list->next; - } - value = g_variant_new ("ab", builder); - g_variant_builder_unref (builder); - } - break; - case TypeInt: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ai")); - while (list) - { - g_variant_builder_add (builder, "i", list->data->value.asInt); - list = list->next; - } - value = g_variant_new ("ai", builder); - g_variant_builder_unref (builder); - } - break; - case TypeFloat: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("ad")); - while (list) - { - g_variant_builder_add (builder, "d", (gdouble) list->data->value.asFloat); - list = list->next; - } - value = g_variant_new ("ad", builder); - g_variant_builder_unref (builder); - } - break; - case TypeString: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - while (list) - { - g_variant_builder_add (builder, "s", list->data->value.asString); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } - break; - case TypeMatch: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - while (list) - { - g_variant_builder_add (builder, "s", list->data->value.asMatch); - list = list->next; - } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); - } - break; - case TypeColor: - { - GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - char *item; - while (list) - { - item = ccsColorToString (&list->data->value.asColor); - g_variant_builder_add (builder, "s", item); - list = list->next; + ccsSetList (setting, list, TRUE); + ccsSettingValueListFree (list, TRUE); + ret = TRUE; } - value = g_variant_new ("as", builder); - g_variant_builder_unref (builder); } break; default: - ccsWarning ("Attempt to write unsupported list type %d!", - ccsSettingGetInfo (setting)->forList.listType); + ccsWarning ("Attempt to read unsupported setting type %d!", + ccsSettingGetType (setting)); break; } - if (value) - { - g_settings_set_value (settings, cleanSettingName, value); - g_variant_unref (value); - } - - free (cleanSettingName); -} - -static void -writeIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index) -{ -#ifdef USE_GCONF - writeGConfIntegratedOption (context, setting, index); -#endif + g_variant_unref (gsettingsValue); - return; + return ret; } static void -resetOptionToDefault (CCSSetting * setting) +writeIntegratedOption (CCSBackend *backend, + CCSSetting *setting, + CCSIntegratedSetting *integrated) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); - - char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); - - g_settings_reset (settings, cleanSettingName); - - free (cleanSettingName); + ccsGSettingsBackendWriteIntegratedOption (backend, setting, integrated); } void -writeOption (CCSSetting * setting) +writeOption (CCSBackend *backend, + CCSSetting *setting) { - GSettings *settings = getSettingsObjectForCCSSetting (setting); + CCSGSettingsWrapper *settings = getSettingsObjectForCCSSetting (backend, setting); char *cleanSettingName = translateKeyForGSettings (ccsSettingGetName (setting)); + GVariant *gsettingsValue = NULL; + Bool success = FALSE; switch (ccsSettingGetType (setting)) { @@ -674,7 +236,7 @@ writeOption (CCSSetting * setting) char *value; if (ccsGetString (setting, &value)) { - g_settings_set (settings, cleanSettingName, "s", value, NULL); + success = writeStringToVariant (value, &gsettingsValue); } } break; @@ -683,15 +245,17 @@ writeOption (CCSSetting * setting) char *value; if (ccsGetMatch (setting, &value)) { - g_settings_set (settings, cleanSettingName, "s", value, NULL); + + success = writeStringToVariant (value, &gsettingsValue); } } + break; case TypeFloat: { float value; if (ccsGetFloat (setting, &value)) { - g_settings_set (settings, cleanSettingName, "d", (double) value, NULL); + success = writeFloatToVariant (value, &gsettingsValue); } } break; @@ -700,7 +264,7 @@ writeOption (CCSSetting * setting) int value; if (ccsGetInt (setting, &value)) { - g_settings_set (settings, cleanSettingName, "i", value, NULL); + success = writeIntToVariant (value, &gsettingsValue); } } break; @@ -709,72 +273,48 @@ writeOption (CCSSetting * setting) Bool value; if (ccsGetBool (setting, &value)) { - g_settings_set (settings, cleanSettingName, "b", value, NULL); + success = writeBoolToVariant (value, &gsettingsValue); } } break; case TypeColor: { CCSSettingColorValue value; - char *colString; if (!ccsGetColor (setting, &value)) break; - colString = ccsColorToString (&value); - if (!colString) - break; - - g_settings_set (settings, cleanSettingName, "s", colString, NULL); - free (colString); + success = writeColorToVariant (value, &gsettingsValue); } break; case TypeKey: { CCSSettingKeyValue key; - char *keyString; if (!ccsGetKey (setting, &key)) break; - keyString = ccsKeyBindingToString (&key); - if (!keyString) - break; - - g_settings_set (settings, cleanSettingName, "s", keyString, NULL); - free (keyString); + success = writeKeyToVariant (key, &gsettingsValue); } break; case TypeButton: { CCSSettingButtonValue button; - char *buttonString; if (!ccsGetButton (setting, &button)) break; - buttonString = ccsButtonBindingToString (&button); - if (!buttonString) - break; - - g_settings_set (settings, cleanSettingName, "s", buttonString, NULL); - free (buttonString); + success = writeButtonToVariant (button, &gsettingsValue); } break; case TypeEdge: { unsigned int edges; - char *edgeString; if (!ccsGetEdge (setting, &edges)) break; - edgeString = ccsEdgesToString (edges); - if (!edgeString) - break; - - g_settings_set (settings, cleanSettingName, "s", edgeString, NULL); - free (edgeString); + success = writeEdgeToVariant (edges, &gsettingsValue); } break; case TypeBell: @@ -782,15 +322,20 @@ writeOption (CCSSetting * setting) Bool value; if (ccsGetBell (setting, &value)) { - g_settings_set (settings, cleanSettingName, "s", value, NULL); + success = writeBoolToVariant (value, &gsettingsValue); } } break; case TypeList: { - gchar *pathName = makeSettingPath (setting); - writeListValue (setting, pathName); - g_free (pathName); + CCSSettingValueList list = NULL; + + if (!ccsGetList (setting, &list)) + return; + + success = writeListValue (list, + ccsSettingGetInfo (setting)->forList.listType, + &gsettingsValue); } break; default: @@ -799,93 +344,90 @@ writeOption (CCSSetting * setting) break; } + if (success && gsettingsValue) + { + /* g_settings_set_value will consume the reference + * so there is no need to unref value here */ + writeVariantToKey (settings, cleanSettingName, gsettingsValue); + } + free (cleanSettingName); } -static void -updateCurrentProfileName (const char *profile) +Bool +readInit (CCSBackend *backend, CCSContext * context) { - GVariant *profiles; - char *prof; - gchar *profilePath = makeCompizProfilePath (profile); - GVariant *newProfiles; - GVariantBuilder *newProfilesBuilder; - GVariantIter iter; - gboolean found = FALSE; - - profiles = g_settings_get_value (compizconfigSettings, "existing-profiles"); + return ccsGSettingsBackendUpdateProfile (backend, context); +} - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); +void +readSetting (CCSBackend *backend, + CCSContext *context, + CCSSetting *setting) +{ + Bool status; + CCSIntegratedSetting *integrated = ccsGSettingsBackendGetIntegratedSetting (backend, setting); - g_variant_iter_init (&iter, profiles); - while (g_variant_iter_loop (&iter, "s", &prof)) + if (ccsGetIntegrationEnabled (context) && + integrated) { - g_variant_builder_add (newProfilesBuilder, "s", prof); - - if (!found) - found = (g_strcmp0 (prof, profile) == 0); + status = readIntegratedOption (backend, setting, integrated); } + else + status = readOption (backend, setting); - if (!found) - g_variant_builder_add (newProfilesBuilder, "s", profile); - - newProfiles = g_variant_new ("as", newProfilesBuilder); - g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles); - - g_variant_unref (newProfiles); - g_variant_builder_unref (newProfilesBuilder); - - /* Change the current profile and current profile settings */ - free (currentProfile); - - currentProfile = strdup (profile); - currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profilePath); - - g_settings_set (compizconfigSettings, "current-profile", "s", profile, NULL); - - g_free (profilePath); + if (!status) + ccsResetToDefault (setting, TRUE); } -static gboolean -updateProfile (CCSContext *context) +Bool +writeInit (CCSBackend *backend, CCSContext * context) { - char *profile = strdup (ccsGetProfile (context)); + return ccsGSettingsBackendUpdateProfile (backend, context); +} - if (!profile) - profile = strdup (DEFAULTPROF); +void +writeSetting (CCSBackend *backend, + CCSContext *context, + CCSSetting *setting) +{ + CCSIntegratedSetting *integrated = ccsGSettingsBackendGetIntegratedSetting (backend, setting); - if (!strlen (profile)) + if (ccsGetIntegrationEnabled (context) && + integrated) { - free (profile); - profile = strdup (DEFAULTPROF); + writeIntegratedOption (backend, setting, integrated); } + else if (ccsSettingGetIsDefault (setting)) + { + resetOptionToDefault (backend, setting); + } + else + writeOption (backend, setting); - if (g_strcmp0 (profile, currentProfile)) - updateCurrentProfileName (profile); - - free (profile); - - return TRUE; } -static char* -getCurrentProfileName (void) +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) { - GVariant *value; - char *ret = NULL; + CCSIntegratedSetting *integrated = ccsGSettingsBackendGetIntegratedSetting (backend, setting); - value = g_settings_get_value (compizconfigSettings, "current-profile"); - - if (value) - ret = strdup (g_variant_get_string (value, NULL)); - else - ret = strdup (DEFAULTPROF); + ccsBackendReadInit (backend, context); + if (!readOption (backend, setting)) + { + ccsResetToDefault (setting, TRUE); + } - return ret; + if (ccsGetIntegrationEnabled (context) && + integrated) + { + ccsBackendWriteInit (backend, context); + ccsGSettingsBackendWriteIntegratedOption (backend, setting, integrated); + } } static void -processEvents (unsigned int flags) +processEvents (CCSBackend *backend, unsigned int flags) { if (!(flags & ProcessEventsNoGlibMainLoopMask)) { @@ -895,229 +437,56 @@ processEvents (unsigned int flags) } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { - char *currentProfilePath; - g_type_init (); - compizconfigSettings = g_settings_new (COMPIZCONFIG_SCHEMA_ID); - -#ifdef USE_GCONF - initGConfClient (context); -#endif - - currentProfile = getCurrentProfileName (); - currentProfilePath = makeCompizProfilePath (currentProfile); - currentProfileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, currentProfilePath); - - g_free (currentProfilePath); - - return TRUE; + return ccsGSettingsBackendAttachNewToBackend (backend, context); } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend *backend) { - GList *l = settingsList; - - processEvents (0); - -#ifdef USE_GCONF - gconf_client_clear_cache (client); - finiGConfClient (); -#endif - - if (currentProfile) - { - free (currentProfile); - currentProfile = NULL; - } - - while (l) - { - g_object_unref (G_OBJECT (l->data)); - l = g_list_next (l); - } + ccsGSettingsBackendDetachFromBackend (backend); - if (currentProfileSettings) - { - g_object_unref (currentProfileSettings); - currentProfileSettings = NULL; - } - - g_object_unref (G_OBJECT (compizconfigSettings)); - - processEvents (0); return TRUE; } -Bool -readInit (CCSContext * context) -{ - return updateProfile (context); -} - -void -readSetting (CCSContext *context, - CCSSetting *setting) -{ - Bool status; - int index; - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - status = readIntegratedOption (context, setting, index); - } - else - status = readOption (setting); - - if (!status) - ccsResetToDefault (setting, TRUE); -} - -Bool -writeInit (CCSContext * context) -{ - return updateProfile (context); -} - -void -writeSetting (CCSContext *context, - CCSSetting *setting) -{ - int index; - - if (ccsGetIntegrationEnabled (context) && - isIntegratedOption (setting, &index)) - { - writeIntegratedOption (context, setting, index); - } - else if (ccsSettingGetIsDefault (setting)) - { - resetOptionToDefault (setting); - } - else - writeOption (setting); - -} - static Bool -getSettingIsIntegrated (CCSSetting * setting) +getSettingIsIntegrated (CCSBackend *backend, CCSSetting * setting) { if (!ccsGetIntegrationEnabled (ccsPluginGetContext (ccsSettingGetParent (setting)))) return FALSE; - if (!isIntegratedOption (setting, NULL)) + if (!ccsGSettingsBackendGetIntegratedSetting (backend, setting)) return FALSE; return TRUE; } static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; } -static CCSStringList -getExistingProfiles (CCSContext *context) +static const CCSBackendInfo * +getInfo (CCSBackend *backend) { - GVariant *value; - char *profile; - GVariantIter iter; - CCSStringList ret = NULL; - - value = g_settings_get_value (compizconfigSettings, "existing-profiles"); - g_variant_iter_init (&iter, value); - while (g_variant_iter_loop (&iter, "s", &profile)) - { - CCSString *str = malloc (sizeof (CCSString)); - - str->value = strdup (profile); - - ret = ccsStringListAppend (ret, str); - } - - g_variant_unref (value); - - return ret; + return &gsettingsBackendInfo; } static Bool -deleteProfile (CCSContext *context, - char *profile) +ccsGSettingsWrapDeleteProfile (CCSBackend *backend, + CCSContext *context, + char *profile) { - GVariant *plugins; - GVariant *profiles; - GVariant *newProfiles; - GVariantBuilder *newProfilesBuilder; - char *plugin, *prof; - GVariantIter iter; - char *profileSettingsPath = makeCompizProfilePath (profile); - GSettings *profileSettings = g_settings_new_with_path (PROFILE_SCHEMA_ID, profileSettingsPath); - - plugins = g_settings_get_value (currentProfileSettings, "plugins-with-set-keys"); - profiles = g_settings_get_value (compizconfigSettings, "existing-profiles"); - - g_variant_iter_init (&iter, plugins); - while (g_variant_iter_loop (&iter, "s", &plugin)) - { - GSettings *settings; - gchar *pathName = makeCompizPluginPath (currentProfile, plugin); - - settings = getSettingsObjectForPluginWithPath (plugin, pathName, context); - g_free (pathName); - - /* The GSettings documentation says not to use this API - * because we should know our own schema ... though really - * we don't because we autogenerate schemas ... */ - if (settings) - { - char **keys = g_settings_list_keys (settings); - char **key_ptr; - - /* Unset all the keys */ - for (key_ptr = keys; *key_ptr; key_ptr++) - g_settings_reset (settings, *key_ptr); - - g_strfreev (keys); - } - } - - /* Remove the profile from existing-profiles */ - g_settings_reset (profileSettings, "plugins-with-set-values"); - - g_variant_iter_init (&iter, profiles); - newProfilesBuilder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - - while (g_variant_iter_loop (&iter, "s", &prof)) - { - if (g_strcmp0 (prof, profile)) - g_variant_builder_add (newProfilesBuilder, "s", prof); - } - - newProfiles = g_variant_new ("as", newProfilesBuilder); - g_settings_set_value (compizconfigSettings, "existing-profiles", newProfiles); - - g_variant_unref (newProfiles); - g_variant_builder_unref (newProfilesBuilder); - - g_free (profileSettingsPath); - - updateProfile (context); - - return TRUE; + return deleteProfile (backend, context, profile); } -static CCSBackendVTable gsettingsVTable = { - "gsettings", - "GSettings Configuration Backend", - "GSettings Configuration Backend for libccs", - TRUE, - TRUE, +static CCSBackendInterface gsettingsVTable = { + getInfo, processEvents, initBackend, finiBackend, @@ -1127,15 +496,16 @@ static CCSBackendVTable gsettingsVTable = { writeInit, writeSetting, 0, + updateSetting, getSettingIsIntegrated, getSettingIsReadOnly, - getExistingProfiles, - deleteProfile + ccsGSettingsGetExistingProfiles, + ccsGSettingsWrapDeleteProfile, + ccsGSettingsSetIntegration }; -CCSBackendVTable * +CCSBackendInterface * getBackendInfo (void) { return &gsettingsVTable; } - diff --git a/compizconfig/gsettings/src/gsettings.h b/compizconfig/gsettings/src/gsettings.h index 4ac1c7cc7c0445c47aa3e56e0fcdb93b79849763..d80a4afc65e3df7d8b81f68d2e584e4da0a41658 100644 --- a/compizconfig/gsettings/src/gsettings.h +++ b/compizconfig/gsettings/src/gsettings.h @@ -2,7 +2,7 @@ * * GSettings libccs backend * - * gconf-integration.c + * gsettings.h * * Copyright (c) 2011 Canonical Ltd * @@ -34,87 +34,13 @@ #ifndef _COMPIZCONFIG_BACKEND_GSETTINGS_GSETTINGS_H #define _COMPIZCONFIG_BACKEND_GSETTINGS_GSETTINGS_H -#include -#include -#include -#include -#include -#include - #include #include #include -#include "gsettings_shared.h" - -#define BUFSIZE 512 - -#define NUM_WATCHED_DIRS 3 - #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif -typedef enum { - OptionInt, - OptionBool, - OptionKey, - OptionString, - OptionSpecial, -} SpecialOptionType; - -char *currentProfile; - -Bool readInit (CCSContext * context); -void readSetting (CCSContext * context, CCSSetting * setting); -Bool readOption (CCSSetting * setting); -Bool writeInit (CCSContext * context); -void writeOption (CCSSetting *setting); - -#ifdef USE_GCONF - -#include -#include -#include - -GConfClient *client; -guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS]; - -typedef struct _SpecialOptionGConf { - const char* settingName; - const char* pluginName; - Bool screen; - const char* gnomeName; - SpecialOptionType type; -} SpecialOptionGConf; - -Bool -isGConfIntegratedOption (CCSSetting *setting, - int *index); - -void -gnomeGConfValueChanged (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer user_data); - -void -initGConfClient (CCSContext *context); - -void -finiGConfClient (void); - -Bool -readGConfIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index); - -void -writeGConfIntegratedOption (CCSContext *context, - CCSSetting *setting, - int index); - -#endif - #endif diff --git a/compizconfig/gsettings/tests/CMakeLists.txt b/compizconfig/gsettings/tests/CMakeLists.txt index 4cd58d5b68b6b846669caebfc378074699468f74..29b97724749deed57a4c466911b78ed35edd9069 100644 --- a/compizconfig/gsettings/tests/CMakeLists.txt +++ b/compizconfig/gsettings/tests/CMakeLists.txt @@ -1,23 +1,71 @@ +include (CompizGSettings) + include_directories (${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/../src - ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests) + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../src + ${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/tests + ${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig + ${CMAKE_CURRENT_SOURCE_DIR}/../../tests + ${CMAKE_SOURCE_DIR}/tests/shared) pkg_check_modules (COMPIZCONFIG_TEST_GSETTINGS libcompizconfig) +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + +link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) + +add_library (compizconfig_ccs_gsettings_wrapper_mock STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_wrapper_mock.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_wrapper_mock.h) + +add_library (compizconfig_ccs_gsettings_backend_mock STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/ccs_gsettings_backend_mock.h) + add_executable (compizconfig_test_gsettings - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_wrapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gsettings_mocks.h ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_tests.h) -link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../libcompizconfig/tests) +add_executable (compizconfig_test_gsettings_conformance + ${CMAKE_CURRENT_SOURCE_DIR}/test_gsettings_conformance.cpp) target_link_libraries (compizconfig_test_gsettings - gsettings_backend_shared - setting-mock + compizconfig_gsettings_backend + compizconfig_ccs_setting_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_context_mock + compizconfig_ccs_gsettings_backend_mock + compizconfig_ccs_gsettings_wrapper_mock + ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_MAIN_LIBRARY}) + +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/gsettings-mock-schemas-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/gsettings-mock-schemas-config.h) + +add_custom_command (OUTPUT ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml + COMMAND cp -r ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/org.compiz.mock.gschema.xml + VERBATIM) + +add_custom_target (compiz_gsettings_mock_schema ALL + DEPENDS ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/org.compiz.mock.gschema.xml) + +add_gsettings_schema_to_recompilation_list (compiz_gsettings_mock_schema) + +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/backend-conformance-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/backend-conformance-config.h) + +target_link_libraries (compizconfig_test_gsettings_conformance + compizconfig_gsettings_backend + compizconfig_ccs_setting_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_context_mock ${COMPIZCONFIG_TEST_GSETTINGS_LIBRARIES} ${GTEST_BOTH_LIBRARIES} ${GMOCK_MAIN_LIBRARY}) -compiz_discover_tests (compizconfig_test_gsettings COVERAGE gsettings_backend_shared) +compiz_discover_tests (compizconfig_test_gsettings COVERAGE compizconfig_gsettings_backend) +compiz_discover_tests (compizconfig_test_gsettings_conformance COVERAGE compizconfig_gsettings_backend gsettings) diff --git a/compizconfig/gsettings/tests/backend-conformance-config.h.in b/compizconfig/gsettings/tests/backend-conformance-config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..0db3f2ea422ece6553affd3234459bd2525e7e81 --- /dev/null +++ b/compizconfig/gsettings/tests/backend-conformance-config.h.in @@ -0,0 +1 @@ +#define BACKEND_BINARY_PATH "@CMAKE_BINARY_DIR@/compizconfig/gsettings" diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d286591b8ac396c0c15534007aef47f1dd18a0d1 --- /dev/null +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.cpp @@ -0,0 +1,62 @@ +#include +#include + +#include + +#include "ccs_gsettings_backend_mock.h" + +CCSGSettingsBackendInterface ccsGSettingsBackendGMockInterface = +{ + CCSGSettingsBackendGMock::ccsGSettingsBackendGetContext, + CCSGSettingsBackendGMock::ccsGSettingsBackendConnectToValueChangedSignal, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetSettingsObjectForPluginWithPath, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetCurrentProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetExistingProfiles, + CCSGSettingsBackendGMock::ccsGSettingsBackendSetExistingProfiles, + CCSGSettingsBackendGMock::ccsGSettingsBackendSetCurrentProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetPluginsWithSetKeys, + CCSGSettingsBackendGMock::ccsGSettingsBackendClearPluginsWithSetKeys, + CCSGSettingsBackendGMock::ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendUpdateCurrentProfileName, + CCSGSettingsBackendGMock::ccsGSettingsBackendAddProfile, + CCSGSettingsBackendGMock::ccsGSettingsBackendGetIntegratedSetting, + CCSGSettingsBackendGMock::ccsGSettingsBackendReadIntegratedOption, + CCSGSettingsBackendGMock::ccsGSettingsBackendWriteIntegratedOption +}; + +CCSBackend * +ccsGSettingsBackendGMockNew () +{ + CCSBackend *backend = (CCSBackend *) calloc (1, sizeof (CCSBackend)); + + if (!backend) + return NULL; + + CCSGSettingsBackendGMock *gmock = new CCSGSettingsBackendGMock (backend); + + if (!gmock) + { + free (backend); + return NULL; + } + + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + ccsObjectAddInterface (backend, (const CCSInterface *) &ccsGSettingsBackendGMockInterface, GET_INTERFACE_TYPE (CCSGSettingsBackendInterface)); + ccsObjectSetPrivate (backend, reinterpret_cast (gmock)); + + return backend; +} + +void +ccsGSettingsBackendGMockFree (CCSBackend *backend) +{ + CCSGSettingsBackendGMock *mock = reinterpret_cast (ccsObjectGetPrivate (backend)); + + delete mock; + + ccsObjectSetPrivate (backend, NULL); + ccsObjectFinalize (backend); + + free (backend); +} diff --git a/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..68f1ef8178be6fdade353006462832332dee4313 --- /dev/null +++ b/compizconfig/gsettings/tests/ccs_gsettings_backend_mock.h @@ -0,0 +1,186 @@ +#ifndef _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_MOCK +#define _COMPIZCONFIG_CCS_GSETTINGS_BACKEND_MOCK + +#include +#include + +#include +#include "ccs_gsettings_backend_interface.h" + +using ::testing::_; +using ::testing::Return; + +CCSBackend * ccsGSettingsBackendGMockNew (); +void ccsGSettingsBackendGMockFree (CCSBackend *backend); + +class CCSGSettingsBackendGMockInterface +{ + public: + + virtual ~CCSGSettingsBackendGMockInterface () {} + + virtual CCSContext * getContext () = 0; + virtual void connectToChangedSignal (CCSGSettingsWrapper *) = 0; + virtual CCSGSettingsWrapper * getSettingsObjectForPluginWithPath (const char * plugin, + const char * path, + CCSContext * context) = 0; + virtual const char * getCurrentProfile () = 0; + virtual GVariant * getExistingProfiles () = 0; + virtual void setExistingProfiles (GVariant *) = 0; + virtual void setCurrentProfile (const gchar *) = 0; + virtual GVariant * getPluginsWithSetKeys () = 0; + virtual void clearPluginsWithSetKeys () = 0; + virtual void unsetAllChangedPluginKeysInProfile (CCSContext *, GVariant *, const char *) = 0; + virtual gboolean updateProfile (CCSContext *) = 0; + virtual void updateCurrentProfileName (const char *) = 0; + virtual gboolean addProfile (const char *) = 0; + virtual CCSIntegratedSetting * getIntegratedSetting (CCSSetting *) = 0; + virtual Bool readIntegratedOption (CCSSetting *, CCSIntegratedSetting *) = 0; + virtual void writeIntegratedOption (CCSSetting *, CCSIntegratedSetting *) = 0; + +}; + +class CCSGSettingsBackendGMock : + public CCSGSettingsBackendGMockInterface +{ + public: + + CCSGSettingsBackendGMock (CCSBackend *backend) : + mBackend (backend) + { + } + + MOCK_METHOD0 (getContext, CCSContext * ()); + MOCK_METHOD1 (connectToChangedSignal, void (CCSGSettingsWrapper *)); + MOCK_METHOD3 (getSettingsObjectForPluginWithPath, CCSGSettingsWrapper * (const char * plugin, + const char * path, + CCSContext * context)); + MOCK_METHOD0 (getCurrentProfile, const char * ()); + MOCK_METHOD0 (getExistingProfiles, GVariant * ()); + MOCK_METHOD1 (setExistingProfiles, void (GVariant *)); + MOCK_METHOD1 (setCurrentProfile, void (const gchar *)); + MOCK_METHOD0 (getPluginsWithSetKeys, GVariant * ()); + MOCK_METHOD0 (clearPluginsWithSetKeys, void ()); + MOCK_METHOD3 (unsetAllChangedPluginKeysInProfile, void (CCSContext *, GVariant *, const char *)); + MOCK_METHOD1 (updateProfile, gboolean (CCSContext *)); + MOCK_METHOD1 (updateCurrentProfileName, void (const char *)); + MOCK_METHOD1 (addProfile, gboolean (const char *)); + MOCK_METHOD1 (getIntegratedSetting, CCSIntegratedSetting * (CCSSetting *)); + MOCK_METHOD2 (readIntegratedOption, Bool (CCSSetting *, CCSIntegratedSetting *)); + MOCK_METHOD2 (writeIntegratedOption, void (CCSSetting *, CCSIntegratedSetting *)); + + CCSBackend * getBackend () { return mBackend; } + + private: + + CCSBackend *mBackend; + + public: + + static CCSContext * + ccsGSettingsBackendGetContext (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getContext (); + } + + static void + ccsGSettingsBackendConnectToValueChangedSignal (CCSBackend *backend, CCSGSettingsWrapper *object) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->connectToChangedSignal(object); + } + + static CCSGSettingsWrapper * + ccsGSettingsBackendGetSettingsObjectForPluginWithPath (CCSBackend *backend, + const char *plugin, + const char *path, + CCSContext *context) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getSettingsObjectForPluginWithPath (plugin, + path, + context); + } + + static const char * + ccsGSettingsBackendGetCurrentProfile (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getCurrentProfile (); + } + + static GVariant * + ccsGSettingsBackendGetExistingProfiles (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getExistingProfiles (); + } + + static void + ccsGSettingsBackendSetExistingProfiles (CCSBackend *backend, GVariant *value) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->setExistingProfiles (value); + } + + static void + ccsGSettingsBackendSetCurrentProfile (CCSBackend *backend, const gchar *value) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->setCurrentProfile (value); + } + + static GVariant * + ccsGSettingsBackendGetPluginsWithSetKeys (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getPluginsWithSetKeys (); + } + + static void + ccsGSettingsBackendClearPluginsWithSetKeys (CCSBackend *backend) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->clearPluginsWithSetKeys (); + } + + static void + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (CCSBackend *backend, + CCSContext *context, + GVariant *pluginKeys, + const char *profile) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->unsetAllChangedPluginKeysInProfile (context, pluginKeys, profile); + } + + static gboolean + ccsGSettingsBackendUpdateProfile (CCSBackend *backend, CCSContext *context) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->updateProfile (context); + } + + static void + ccsGSettingsBackendUpdateCurrentProfileName (CCSBackend *backend, const char *profile) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->updateCurrentProfileName (profile); + } + + static gboolean + ccsGSettingsBackendAddProfile (CCSBackend *backend, const char *profile) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->addProfile (profile); + } + + static CCSIntegratedSetting * + ccsGSettingsBackendGetIntegratedSetting (CCSBackend *backend, CCSSetting *setting) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->getIntegratedSetting (setting); + } + + static Bool + ccsGSettingsBackendReadIntegratedOption (CCSBackend *backend, CCSSetting *setting, CCSIntegratedSetting *integrated) + { + return (reinterpret_cast (ccsObjectGetPrivate (backend)))->readIntegratedOption (setting, integrated); + + } + + static void + ccsGSettingsBackendWriteIntegratedOption (CCSBackend *backend, CCSSetting *setting, CCSIntegratedSetting *integrated) + { + (reinterpret_cast (ccsObjectGetPrivate (backend)))->writeIntegratedOption (setting, integrated); + } +}; + +#endif diff --git a/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0c659ec674b5f8dd7720b408f09c897d474148a --- /dev/null +++ b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.cpp @@ -0,0 +1,52 @@ +#include + +const CCSGSettingsWrapperInterface mockInterface = +{ + CCSGSettingsWrapperGMock::ccsGSettingsWrapperSetValue, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetValue, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperResetKey, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperListKeys, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetGSettings, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetSchemaName, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperGetPath, + CCSGSettingsWrapperGMock::ccsGSettingsWrapperConnectToChangedSignal, + CCSGSettingsWrapperGMock::ccsFreeGSettingsWrapper +}; + +CCSGSettingsWrapper * +ccsMockGSettingsWrapperNew () +{ + CCSGSettingsWrapper *wrapper = (CCSGSettingsWrapper *) calloc (1, sizeof (CCSGSettingsWrapper)); + + if (!wrapper) + return NULL; + + CCSGSettingsWrapperGMock *gmockWrapper = new CCSGSettingsWrapperGMock (wrapper); + + if (!gmockWrapper) + { + free (wrapper); + return NULL; + } + + ccsObjectInit (wrapper, &ccsDefaultObjectAllocator); + ccsObjectAddInterface (wrapper, (const CCSInterface *) &mockInterface, GET_INTERFACE_TYPE (CCSGSettingsWrapperInterface)); + ccsObjectSetPrivate (wrapper, (CCSPrivate *) gmockWrapper); + + ccsGSettingsWrapperRef (wrapper); + + return wrapper; +} + +void +ccsMockGSettingsWrapperFree (CCSGSettingsWrapper *wrapper) +{ + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper)); + + delete gmockWrapper; + + ccsObjectSetPrivate (wrapper, NULL); + ccsObjectFinalize (wrapper); + free (wrapper); +} + diff --git a/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..d8b92e83ce118dfbe6f812e4886d57a385c530d0 --- /dev/null +++ b/compizconfig/gsettings/tests/ccs_gsettings_wrapper_mock.h @@ -0,0 +1,113 @@ +#ifndef _COMPIZCONFIG_CCS_GSETTINGS_WRAPPER_MOCK +#define _COMPIZCONFIG_CCS_GSETTINGS_WRAPPER_MOCK + +#include +#include + +#include + +CCSGSettingsWrapper * ccsMockGSettingsWrapperNew (); +void ccsMockGSettingsWrapperFree (CCSGSettingsWrapper *); + +class CCSGSettingsWrapperMockInterface +{ + public: + + virtual ~CCSGSettingsWrapperMockInterface () {} + virtual void setValue (const char *, GVariant *) = 0; + virtual GVariant * getValue (const char *) = 0; + virtual void resetKey (const char *) = 0; + virtual char ** listKeys () = 0; + virtual GSettings * getGSettings () = 0; + virtual const char * getSchemaName () = 0; + virtual const char * getPath () = 0; + virtual void connectToChangedSignal (GCallback, gpointer) = 0; +}; + +class CCSGSettingsWrapperGMock : + public CCSGSettingsWrapperMockInterface +{ + public: + + CCSGSettingsWrapperGMock (CCSGSettingsWrapper *wrapper) : + mWrapper (wrapper) + { + } + + MOCK_METHOD2 (setValue, void (const char *, GVariant *)); + MOCK_METHOD1 (getValue, GVariant * (const char *)); + MOCK_METHOD1 (resetKey, void (const char *)); + MOCK_METHOD0 (listKeys, char ** ()); + MOCK_METHOD0 (getGSettings, GSettings * ()); + MOCK_METHOD0 (getSchemaName, const char * ()); + MOCK_METHOD0 (getPath, const char * ()); + MOCK_METHOD2 (connectToChangedSignal, void (GCallback, gpointer)); + + private: + + CCSGSettingsWrapper *mWrapper; + + public: + + static void + ccsGSettingsWrapperSetValue (CCSGSettingsWrapper *wrapper, + const char *key, + GVariant *value) + { + reinterpret_cast (ccsObjectGetPrivate (wrapper))->setValue (key, value); + } + + static GVariant * + ccsGSettingsWrapperGetValue (CCSGSettingsWrapper *wrapper, + const char *key) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getValue (key); + } + + static void + ccsGSettingsWrapperResetKey (CCSGSettingsWrapper *wrapper, + const char *key) + { + reinterpret_cast (ccsObjectGetPrivate (wrapper))->resetKey (key); + } + + static char ** + ccsGSettingsWrapperListKeys (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->listKeys (); + } + + static GSettings * + ccsGSettingsWrapperGetGSettings (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getGSettings (); + } + + static const char * + ccsGSettingsWrapperGetSchemaName (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getSchemaName (); + } + + static const char * + ccsGSettingsWrapperGetPath (CCSGSettingsWrapper *wrapper) + { + return reinterpret_cast (ccsObjectGetPrivate (wrapper))->getPath (); + } + + static void + ccsGSettingsWrapperConnectToChangedSignal (CCSGSettingsWrapper *wrapper, + GCallback callback, + gpointer data) + { + reinterpret_cast (ccsObjectGetPrivate (wrapper))->connectToChangedSignal (callback, data); + } + + static void + ccsFreeGSettingsWrapper (CCSGSettingsWrapper *wrapper) + { + ccsMockGSettingsWrapperFree (wrapper); + } +}; + +#endif diff --git a/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in b/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..e41634193287d149bce615feb82fc65be9d996bc --- /dev/null +++ b/compizconfig/gsettings/tests/gsettings-mock-schemas-config.h.in @@ -0,0 +1,12 @@ +#ifndef _COMPIZCONFIG_GSETTINGS_MOCK_SCHEMAS_CONFIG_H +#define _COMPIZCONFIG_GSETTINGS_MOCK_SCHEMAS_CONFIG_H + +#define MOCK_SCHEMA_PATH "@CMAKE_BINARY_DIR@/generated/glib-2.0/schemas" + +namespace +{ +const std::string MOCK_SCHEMA ("org.compiz.mock"); +const std::string MOCK_PATH (MOCK_SCHEMA_PATH); +} + +#endif diff --git a/compizconfig/gsettings/tests/gsettings_mocks.cpp b/compizconfig/gsettings/tests/gsettings_mocks.cpp deleted file mode 100644 index ec2e600eacd32bead9bc0bccef0fd910f06d27b1..0000000000000000000000000000000000000000 --- a/compizconfig/gsettings/tests/gsettings_mocks.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include - -static void compizconfig_gsettings_wrap_gsettings_default_init (CCSGSettingsWrapGSettingsInterface *interface); - -G_DEFINE_INTERFACE (CCSGSettingsWrapGSettings, compizconfig_gsettings_wrap_gsettings, G_TYPE_OBJECT) - -static void compizconfig_gsettings_wrap_gsettings_default_init (CCSGSettingsWrapGSettingsInterface *klass) -{ - g_object_interface_install_property (klass, - g_param_spec_string ("schema", - "schema", - "Schema Name", - "invalid.invalid", - static_cast (G_PARAM_CONSTRUCT_ONLY | - G_PARAM_WRITABLE | - G_PARAM_READABLE))); -} - -CCSGSettingsWrapGSettings * -compizconfig_gsettings_wrap_gsettings_new (GType type, const gchar *name) -{ - GValue name_v = G_VALUE_INIT; - - g_value_init (&name_v, G_TYPE_STRING); - - g_value_set_string (&name_v, name); - - GParameter param[1] = - { - { "schema", name_v } - }; - - CCSGSettingsWrapGSettings *wrap_gsettings = COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS (g_object_newv (type, 1, param)); - - g_value_unset (&name_v); - - return wrap_gsettings; -} - -G_BEGIN_DECLS - -#define COMPIZCONFIG_GSETTINGS_MOCK_WRAP_GSETTINGS(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettings)) - -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_GSETTINGS_CONCRETE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsClass)) - -#define COMPIZCONFIG_GSETTINGS_IS_MOCK_WRAP_GSETTINGS(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS) - -#define COMPIZCONFIG_GSETTINGS_IS_MOCK_WRAP_GSETTINGS_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS)) - -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_GSETTINGS_CONCRETE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsClass)) - -typedef struct { - GObject parent; -} CCSGSettingsMockWrapGSettings; - -typedef struct { - GObjectClass parent_class; -} CCSGSettingsMockWrapGSettingsClass; - -G_END_DECLS - -static void compizconfig_gsettings_mock_wrap_gsettings_interface_init (CCSGSettingsWrapGSettingsInterface *interface); - -G_DEFINE_TYPE_WITH_CODE (CCSGSettingsMockWrapGSettings, compizconfig_gsettings_mock_wrap_gsettings, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, - compizconfig_gsettings_mock_wrap_gsettings_interface_init)) - -#define GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, CCSGSettingsMockWrapGSettingsPrivate)) - -typedef struct _CCSGSettingsMockWrapGSettingsPrivate CCSGSettingsMockWrapGSettingsPrivate; - -struct _CCSGSettingsMockWrapGSettingsPrivate -{ - gchar *name; -}; - -static void -compizconfig_gsettings_mock_wrap_gsettings_dispose (GObject *object) -{ - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); - G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->dispose (object); - - if (priv->name) - g_free (priv->name); - - priv->name = NULL; -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_finalize (GObject *object) -{ - G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->finalize (object); -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_interface_init (CCSGSettingsWrapGSettingsInterface *interface) -{ -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); - - switch (property_id) - { - case COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME: - if (priv->name) - g_free (priv->name); - - priv->name = g_value_dup_string (value); - break; - default: - g_assert_not_reached (); - break; - } -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - CCSGSettingsMockWrapGSettingsPrivate *priv = GET_PRIVATE (object); - - switch (property_id) - { - case COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME: - g_value_set_string (value, priv->name); - break; - default: - g_assert_not_reached (); - break; - } -} - -static GObject * -compizconfig_gsettings_mock_wrap_gsettings_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construction_properties) -{ - GObject *object; - CCSGSettingsMockWrapGSettingsPrivate *priv; - - { - object = G_OBJECT_CLASS (compizconfig_gsettings_mock_wrap_gsettings_parent_class)->constructor (type, - n_construct_properties, - construction_properties); - } - - priv = GET_PRIVATE (object); - - for (guint i = 0; i < n_construct_properties; i++) - { - if (g_strcmp0 (construction_properties[i].pspec->name, "schema") == 0) - { - if (!priv->name) - priv->name = g_value_dup_string (construction_properties[i].value); - } - else - { - g_assert_not_reached (); - } - } - - return object; -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_class_init (CCSGSettingsMockWrapGSettingsClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (CCSGSettingsMockWrapGSettingsPrivate)); - - object_class->dispose = compizconfig_gsettings_mock_wrap_gsettings_dispose; - object_class->finalize = compizconfig_gsettings_mock_wrap_gsettings_finalize; - object_class->set_property = compizconfig_gsettings_mock_wrap_gsettings_set_property; - object_class->get_property = compizconfig_gsettings_mock_wrap_gsettings_get_property; - object_class->constructor = compizconfig_gsettings_mock_wrap_gsettings_constructor; - - g_object_class_override_property (G_OBJECT_CLASS (klass), - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME, - "schema"); -} - -static void -compizconfig_gsettings_mock_wrap_gsettings_init (CCSGSettingsMockWrapGSettings *self) -{ -} diff --git a/compizconfig/gsettings/tests/gsettings_mocks.h b/compizconfig/gsettings/tests/gsettings_mocks.h deleted file mode 100644 index c63b62083f5ab31d2258cbe33f226ee3d13f19bf..0000000000000000000000000000000000000000 --- a/compizconfig/gsettings/tests/gsettings_mocks.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _COMPIZ_COMPIZCONFIG_GSETTINGS_MOCKS -#define _COMPIZ_COMPIZCONFIG_GSETTINGS_MOCKS - -#include -#include - -G_BEGIN_DECLS - -#define COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, CCSGSettingsWrapGSettings)) - -#define COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS, CCSGSettingsWrapGSettingsInterface)) - -#define COMPIZCONFIG_GSETTINGS_TYPE_WRAP_GSETTINGS (compizconfig_gsettings_wrap_gsettings_get_type()) - -GType compizconfig_gsettings_wrap_gsettings_get_type (void); - -typedef struct _CCSGSettingsWrapGSettings CCSGSettingsWrapGSettings; /* dummy typedef */ -typedef struct _CCSGSettingsWrapGSettingsInterface CCSGSettingsWrapGSettingsInterface; - -struct _CCSGSettingsWrapGSettingsInterface { - GTypeInterface parent; - -}; - -enum -{ - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_SCHEMA_NAME = 1, - COMPIZCONFIG_GSETTINGS_WRAP_GSETTINGS_PROPERTY_NUM = 2 -}; - -#define COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS (compizconfig_gsettings_mock_wrap_gsettings_get_type ()) - -GType compizconfig_gsettings_mock_wrap_gsettings_get_type (); - -/** - * compizconfig_gsettings_wrap_gsettings_new: - * @type: (in) (transfer none): a GType of the object type to be created - * @name: (in) (transfer none): schema name - * Return value: (transfer full): a new CCSGSettingsWrapGSettings - */ -CCSGSettingsWrapGSettings * compizconfig_gsettings_wrap_gsettings_new (GType type, const gchar *name); - -G_END_DECLS - -#endif diff --git a/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml new file mode 100644 index 0000000000000000000000000000000000000000..1d3d8491b90ccbdcb2f73c15d5c767b788e29f5e --- /dev/null +++ b/compizconfig/gsettings/tests/org.compiz.mock.gschema.xml @@ -0,0 +1,53 @@ + + + + + 0 + + + false + + + 0.0 + + + "" + + + "" + + + false + + + "" + + + "" + + + "" + + + "" + + + [0] + + + [0.0] + + + [true] + + + [""] + + + [""] + + + [""] + + + diff --git a/compizconfig/gsettings/tests/test_gsettings_conformance.cpp b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb7d197de4325a02ca67bbd5c2166abf2107c276 --- /dev/null +++ b/compizconfig/gsettings/tests/test_gsettings_conformance.cpp @@ -0,0 +1,856 @@ +#include +#include + +#include + +#include "backend-conformance-config.h" +#include "gsettings-mock-schemas-config.h" + +#include +#include + +#include +#include + +#include "gtest_shared_autodestroy.h" +#include "test_gsettings_tests.h" + +using ::testing::AtLeast; +using ::testing::Pointee; +using ::testing::ReturnNull; + +CCSIntegration * +ccsMockIntegrationBackendNew (CCSObjectAllocationInterface *ai); + +void +ccsMockIntegrationBackendFree (CCSIntegration *integration); + +class CCSIntegrationGMockInterface +{ + public: + + virtual ~CCSIntegrationGMockInterface () {} + + virtual CCSIntegratedSetting * getIntegratedOptionIndex (const char *pluginName, const char *settingName) = 0; + virtual Bool readOptionIntoSetting (CCSContext *context, CCSSetting *setting, CCSIntegratedSetting *) = 0; + virtual void writeOptionFromSetting (CCSContext *context, CCSSetting *setting, CCSIntegratedSetting *) = 0; + virtual void updateIntegratedSettings (CCSContext *context, CCSIntegratedSettingList settingList) = 0; + virtual void disallowIntegratedWrites () = 0; + virtual void allowIntegratedWrites () = 0; +}; + +class CCSIntegrationGMock : + public CCSIntegrationGMockInterface +{ + public: + + MOCK_METHOD2 (getIntegratedOptionIndex, CCSIntegratedSetting * (const char *, const char *)); + MOCK_METHOD3 (readOptionIntoSetting, Bool (CCSContext *, CCSSetting *, CCSIntegratedSetting *)); + MOCK_METHOD3 (writeOptionFromSetting, void (CCSContext *, CCSSetting *, CCSIntegratedSetting *)); + MOCK_METHOD2 (updateIntegratedSettings, void (CCSContext *, CCSIntegratedSettingList)); + MOCK_METHOD0 (disallowIntegratedWrites, void ()); + MOCK_METHOD0 (allowIntegratedWrites, void ()); + + + CCSIntegrationGMock (CCSIntegration *integration) : + mIntegration (integration) + { + } + + CCSIntegration * + getIntegrationBackend () + { + return mIntegration; + } + + public: + + static + CCSIntegratedSetting * CCSIntegrationGetIntegratedOptionIndex (CCSIntegration *integration, + const char *pluginName, + const char *settingName) + { + return reinterpret_cast (ccsObjectGetPrivate (integration))->getIntegratedOptionIndex (pluginName, settingName); + } + + static + Bool CCSIntegrationReadOptionIntoSetting (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integrated) + { + return reinterpret_cast (ccsObjectGetPrivate (integration))->readOptionIntoSetting (context, setting, integrated); + } + + static + void CCSIntegrationWriteSettingIntoOption (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integrated) + { + return reinterpret_cast (ccsObjectGetPrivate (integration))->writeOptionFromSetting (context, setting, integrated); + } + + static void CCSIntegrationUpdateIntegratedSettings (CCSIntegration *integration, + CCSContext *context, + CCSIntegratedSettingList settingList) + { + return reinterpret_cast (ccsObjectGetPrivate (integration))->updateIntegratedSettings (context, settingList); + } + + static + void ccsFreeIntegration (CCSIntegration *integration) + { + ccsMockIntegrationBackendFree (integration); + } + + static void ccsIntegrationDisallowIntegratedWrites (CCSIntegration *integration) + { + reinterpret_cast (ccsObjectGetPrivate (integration))->disallowIntegratedWrites (); + } + + static void ccsIntegrationAllowIntegratedWrites (CCSIntegration *integration) + { + reinterpret_cast (ccsObjectGetPrivate (integration))->allowIntegratedWrites (); + } + + private: + + CCSIntegration *mIntegration; +}; + +const CCSIntegrationInterface mockIntegrationBackendInterface = +{ + CCSIntegrationGMock::CCSIntegrationGetIntegratedOptionIndex, + CCSIntegrationGMock::CCSIntegrationReadOptionIntoSetting, + CCSIntegrationGMock::CCSIntegrationWriteSettingIntoOption, + CCSIntegrationGMock::CCSIntegrationUpdateIntegratedSettings, + CCSIntegrationGMock::ccsIntegrationDisallowIntegratedWrites, + CCSIntegrationGMock::ccsIntegrationAllowIntegratedWrites, + CCSIntegrationGMock::ccsFreeIntegration +}; + +CCSIntegration * +ccsMockIntegrationBackendNew (CCSObjectAllocationInterface *ai) +{ + CCSIntegration *integration = reinterpret_cast ((*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegration))); + + if (!integration) + return NULL; + + CCSIntegrationGMock *gmockBackend = new CCSIntegrationGMock (integration); + + ccsObjectInit (integration, ai); + ccsObjectSetPrivate (integration, (CCSPrivate *) gmockBackend); + ccsObjectAddInterface (integration, (const CCSInterface *) &mockIntegrationBackendInterface, GET_INTERFACE_TYPE (CCSIntegrationInterface)); + + ccsObjectRef (integration); + + return integration; +} + +void +ccsMockIntegrationBackendFree (CCSIntegration *integration) +{ + CCSIntegrationGMock *gmockBackend = reinterpret_cast (ccsObjectGetPrivate (integration)); + + delete gmockBackend; + + ccsObjectSetPrivate (integration, NULL); + ccsObjectFinalize (integration); + (*integration->object.object_allocation->free_) (integration->object.object_allocation->allocator, integration); +} + +class CCSGSettingsStorageEnv : + public CCSSettingsConceptTestEnvironmentInterface, + public CCSGSettingsMemoryBackendTestingEnv +{ + public: + + typedef boost::shared_ptr GVariantShared; + + virtual void SetUp () + { + SetUpEnv (); + } + + virtual void TearDown () + { + TearDownEnv (); + } + + CCSGSettingsStorageEnv (CCSGSettingsWrapper *settings, + const std::string &profileName) : + mSettings (settings), + profileName (profileName) + { + } + + void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeBoolToVariant (boolToBool (boost::get (value)), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeIntToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeFloatToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeStringToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeColorToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeKeyToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeButtonToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeEdgeToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeStringToVariant (boost::get (value), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + if (writeBoolToVariant (boolToBool (boost::get (value)), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + void WriteListAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + GVariant *variant = NULL; + + const CCSListWrapper::Ptr &lw (boost::get (value)); + + if (writeListValue (*lw, lw->type (), &variant)) + writeVariantToKey (mSettings, CharacterWrapper (translateKeyForGSettings (key.c_str ())), variant); + else + throw std::exception (); + } + + Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeBool)); + return readBoolFromVariant (variant.get ()); + } + + int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeInt)); + return readIntFromVariant (variant.get ()); + } + + float ReadFloatAtKey (const std::string &plugin, + const std::string &key) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeFloat)); + return readFloatFromVariant (variant.get ()); + } + + const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeString)); + return readStringFromVariant (variant.get ()); + } + + CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) + { + Bool success = FALSE; + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeColor)); + CCSSettingColorValue value = readColorFromVariant (variant.get (), &success); + EXPECT_TRUE (success); + return value; + } + + CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) + { + Bool success = FALSE; + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeKey)); + CCSSettingKeyValue value = readKeyFromVariant (variant.get (), &success); + EXPECT_TRUE (success); + return value; + } + + CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) + { + Bool success = FALSE; + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeButton)); + CCSSettingButtonValue value = readButtonFromVariant (variant.get (), &success); + EXPECT_TRUE (success); + return value; + } + + unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeEdge)); + return readEdgeFromVariant (variant.get ()); + } + + const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeMatch)); + return readStringFromVariant (variant.get ()); + } + + Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeBell)); + return readBoolFromVariant (variant.get ()); + } + + CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key, + CCSSetting *setting) + { + GVariantShared variant (ReadVariantAtKeyToShared (plugin, + key, + TypeList)); + return readListValue (variant.get (), setting, &ccsDefaultObjectAllocator); + } + + private: + + GVariantShared + ReadVariantAtKeyToShared (const std::string &plugin, + const std::string &key, + CCSSettingType type) + { + CharacterWrapper translatedKey (translateKeyForGSettings (key.c_str ())); + CharacterWrapper pluginPath (makeCompizPluginPath (profileName.c_str (), + plugin.c_str ())); + + GVariant *rawVariant = getVariantAtKey (mSettings, + translatedKey, + pluginPath, + type); + + GVariantShared shared (AutoDestroy (rawVariant, g_variant_unref)); + + + + return shared; + } + + CCSGSettingsWrapper *mSettings; + std::string profileName; + + +}; + +class CCSGSettingsBackendEnv : + public CCSBackendConceptTestEnvironmentInterface, + public CCSGSettingsMemoryBackendTestingEnv +{ + private: + + virtual void SetUp () + { + } + + virtual void TearDown () + { + } + + public: + + CCSGSettingsBackendEnv () : + pluginToMatch ("mock") + { + g_type_init (); + } + + /* A wrapper to prevent signals from being added */ + static void connectToSignalWrapper (CCSBackend *backend, CCSGSettingsWrapper *wrapper) + { + }; + + const CCSBackendInfo * GetInfo () + { + return &gsettingsBackendInfo; + } + + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) + { + CCSGSettingsBackendInterface *overloadedInterface = NULL; + + SetUpEnv (); + g_setenv ("LIBCOMPIZCONFIG_BACKEND_PATH", BACKEND_BINARY_PATH, true); + + mContext = context; + + std::string path ("gsettings"); + + mBackend = reinterpret_cast (ccsOpenBackend (&ccsDefaultInterfaceTable, mContext, path.c_str ())); + + EXPECT_TRUE (mBackend); + + mGSettingsBackend = ccsDynamicBackendGetRawBackend (mBackend); + + + CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, mBackend))->backendInit; + + if (backendInit) + (*backendInit) ((CCSBackend *) mBackend, mContext); + + /* Set the new integration, drop our reference on it */ + CCSIntegration *integration = ccsMockIntegrationBackendNew (&ccsDefaultObjectAllocator); + CCSIntegrationGMock *gmockIntegration = reinterpret_cast (ccsObjectGetPrivate (integration)); + + EXPECT_CALL (*gmockIntegration, getIntegratedOptionIndex (_, _)).WillRepeatedly (ReturnNull ()); + + ccsBackendSetIntegration ((CCSBackend *) mBackend, integration); + ccsIntegrationUnref (integration); + + overloadedInterface = GET_INTERFACE (CCSGSettingsBackendInterface, mGSettingsBackend); + overloadedInterface->gsettingsBackendConnectToChangedSignal = CCSGSettingsBackendEnv::connectToSignalWrapper; + + mSettings = ccsGSettingsGetSettingsObjectForPluginWithPath (mGSettingsBackend, "mock", + CharacterWrapper (makeCompizPluginPath (profileName.c_str (), "mock")), + mContext); + + mStorage.reset (new CCSGSettingsStorageEnv (mSettings, profileName)); + + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); + + return (CCSBackend *) mBackend; + } + + void TearDown (CCSBackend *) + { + GVariantBuilder noProfilesBuilder; + g_variant_builder_init (&noProfilesBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&noProfilesBuilder, "s", "Default"); + GVariant *noProfiles = g_variant_builder_end (&noProfilesBuilder); + + GVariantBuilder pluginKeysBuilder; + g_variant_builder_init (&pluginKeysBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&pluginKeysBuilder, "s", "mock"); + GVariant *pluginKeys = g_variant_builder_end (&pluginKeysBuilder); + + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfile (mGSettingsBackend, + mContext, + pluginKeys, + ccsGSettingsBackendGetCurrentProfile ( + mGSettingsBackend)); + ccsGSettingsBackendClearPluginsWithSetKeys (mGSettingsBackend); + ccsGSettingsBackendSetExistingProfiles (mGSettingsBackend, noProfiles); + ccsGSettingsBackendSetCurrentProfile (mGSettingsBackend, "Default"); + + ccsFreeDynamicBackend (mBackend); + + ccsGSettingsWrapperUnref (mSettings); + mStorage.reset (); + + g_variant_unref (pluginKeys); + + TearDownEnv (); + g_unsetenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); + } + + void AddProfile (const std::string &profile) + { + ccsGSettingsBackendAddProfile (mGSettingsBackend, profile.c_str ()); + } + + void SetGetExistingProfilesExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*gmockContext, getProfile ()).Times (AtLeast (1)); + } + + void SetDeleteProfileExpectation (const std::string &profileToDelete, + CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*gmockContext, getProfile ()).Times (AtLeast (1)); + } + + void SetReadInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (profileName.c_str ())); + } + + void SetReadDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + } + + void SetWriteInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (profileName.c_str ())); + } + + void SetWriteDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + } + + void PreWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillRepeatedly (Return (FALSE)); + EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getIsDefault ()).WillRepeatedly (Return (FALSE)); + + if (type == TypeList) + EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); + } + + void PostWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} + + + + void PreRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, isReadableByBackend ()).WillRepeatedly (Return (TRUE)); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); + } + } + + void PostRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} + + void PreUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*gmockContext, getIntegrationEnabled ()).WillOnce (Return (FALSE)); + EXPECT_CALL (*gmockPlugin, getContext ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockPlugin, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getName ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getParent ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, isReadableByBackend ()).WillRepeatedly (Return (TRUE)); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).WillRepeatedly (ReturnNull ()); + } + + EXPECT_CALL (*gmockContext, getProfile ()); + } + + void PostUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) {} + + bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) + { + CharacterWrapper keyName (translateKeyForGSettings (setting.c_str ())); + + if (updateSettingWithGSettingsKeyName (reinterpret_cast (mGSettingsBackend), mSettings, keyName, ccsBackendUpdateSetting)) + return true; + + return false; + } + + void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteBoolAtKey (plugin, key, value); + } + + void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteIntegerAtKey (plugin, key, value); + } + + void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteFloatAtKey (plugin, key, value); + } + + void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteStringAtKey (plugin, key, value); + } + + void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteColorAtKey (plugin, key, value); + } + + void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteKeyAtKey (plugin, key, value); + } + + void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteButtonAtKey (plugin, key, value); + } + + void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteEdgeAtKey (plugin, key, value); + } + + void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteMatchAtKey (plugin, key, value); + } + + void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteBellAtKey (plugin, key, value); + } + + void WriteListAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mStorage->WriteListAtKey (plugin, key, value); + } + + Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadBoolAtKey (plugin, key); + } + + int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadIntegerAtKey (plugin, key); + } + + float ReadFloatAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadFloatAtKey (plugin, key); + } + + const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadStringAtKey (plugin, key); + } + + CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadColorAtKey (plugin, key); + } + + CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadKeyAtKey (plugin, key); + } + + CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadButtonAtKey (plugin, key); + } + + unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadEdgeAtKey (plugin, key); + } + + const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadMatchAtKey (plugin, key); + } + + Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) + { + return mStorage->ReadBellAtKey (plugin, key); + } + + CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key, + CCSSetting *setting) + { + return mStorage->ReadListAtKey (plugin, key, setting); + } + + private: + + CCSGSettingsWrapper *mSettings; + boost::shared_ptr mStorage; + CCSContext *mContext; + CCSDynamicBackend *mBackend; + CCSBackend *mGSettingsBackend; + std::string pluginToMatch; + + static const std::string profileName; +}; + +const std::string CCSGSettingsBackendEnv::profileName = "mock"; + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestReadWrite, + compizconfig::test::GenerateTestingParametersForBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestInfo, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestInitFiniFuncs, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendConcept, CCSBackendConformanceTestProfileHandling, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.cpp b/compizconfig/gsettings/tests/test_gsettings_tests.cpp index 433d279f6e11752b30db63df93b974b3f5f6d090..55d8f7d2a78dc41cf5bb15b95c6907bbe033b931 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.cpp +++ b/compizconfig/gsettings/tests/test_gsettings_tests.cpp @@ -1,13 +1,120 @@ +#include + #include #include +#include + +#include +#include #include "test_gsettings_tests.h" #include "gsettings.h" -#include "gsettings_mocks.h" +#include "ccs_gsettings_backend.h" +#include "ccs_gsettings_backend_mock.h" +#include "compizconfig_ccs_context_mock.h" +#include "compizconfig_ccs_plugin_mock.h" +#include "compizconfig_ccs_setting_mock.h" +#include "gtest_shared_characterwrapper.h" +#include "compizconfig_test_value_combiners.h" +#include "compizconfig_ccs_mocked_allocator.h" +#include "gsettings_shared.h" +#include "ccs_gsettings_interface.h" +#include "ccs_gsettings_wrapper_mock.h" using ::testing::Values; using ::testing::ValuesIn; using ::testing::Return; +using ::testing::ReturnNull; +using ::testing::Invoke; +using ::testing::WithArgs; +using ::testing::MatcherInterface; +using ::testing::MatchResultListener; +using ::testing::AllOf; +using ::testing::Not; +using ::testing::Matcher; +using ::testing::Eq; +using ::testing::NiceMock; +using ::testing::StrictMock; +using ::testing::IsNull; + +class GVariantSubtypeMatcher : + public ::testing::MatcherInterface +{ + public: + GVariantSubtypeMatcher (const std::string &type) : + mType (type) + { + } + + virtual ~GVariantSubtypeMatcher () {} + virtual bool MatchAndExplain (GVariant *x, MatchResultListener *listener) const + { + return g_variant_type_is_subtype_of (G_VARIANT_TYPE (mType.c_str ()), g_variant_get_type (x)); + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "is subtype of " << mType; + } + private: + + std::string mType; +}; + +template +class GVariantHasValueInArrayMatcher : + public ::testing::MatcherInterface +{ + public: + GVariantHasValueInArrayMatcher (const std::string &type, + const T &t, + const boost::function &eq) : + mType (type), + mT (t), + mEq (eq) + { + } + + virtual ~GVariantHasValueInArrayMatcher () {} + virtual bool MatchAndExplain (GVariant *x, MatchResultListener *listener) const + { + GVariantIter iter; + T match; + bool found = false; + + g_variant_iter_init (&iter, x); + while (g_variant_iter_loop (&iter, mType.c_str (), &match)) + { + if (mEq (match, mT)) + found = true; + } + + return found; + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "contains " << mT; + } + private: + + std::string mType; + T mT; + boost::function mEq; +}; + +template +inline Matcher GVariantHasValueInArray (const std::string &type, + const T &t, + const boost::function &eq) +{ + return MakeMatcher (new GVariantHasValueInArrayMatcher (type, t, eq)); +} + +inline Matcher IsVariantSubtypeOf (const std::string &type) +{ + return MakeMatcher (new GVariantSubtypeMatcher (type)); +} TEST_P(CCSGSettingsTest, TestTestFixtures) { @@ -17,6 +124,115 @@ TEST_F(CCSGSettingsTestIndependent, TestTest) { } +namespace +{ +bool streq (const char * const &s1, const char * const &s2) +{ + return g_str_equal (s1, s2); +} + +} + +class CCSGSettingsTestProfiles : + public CCSGSettingsTestIndependent +{ + public: + + static const std::string newProfileName; + static const std::string existingProfileName; +}; + +const std::string CCSGSettingsTestProfiles::existingProfileName ("ExistingProfile"); +const std::string CCSGSettingsTestProfiles::newProfileName ("NewProfile"); + +TEST_F(CCSGSettingsTestProfiles, TestAddProfile) +{ + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + + GVariantBuilder builder; + + g_variant_builder_init (&builder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&builder, "s", existingProfileName.c_str ()); + + GVariant *existingProfiles = g_variant_builder_end (&builder); + + EXPECT_CALL (*gmock, getExistingProfiles ()).WillOnce (Return (existingProfiles)); + EXPECT_CALL (*gmock, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), + GVariantHasValueInArray ("s", + newProfileName.c_str (), + boost::bind (streq, _1, _2))))) + .WillOnce (WithArgs <0> (Invoke (g_variant_unref))); + + ccsGSettingsBackendAddProfileDefault (backend.get (), newProfileName.c_str ()); +} + +TEST_F(CCSGSettingsTestProfiles, TestUpdateCurrentProfileNameAppendNew) +{ + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + + EXPECT_CALL (*gmock, addProfile (Eq (newProfileName))); + EXPECT_CALL (*gmock, setCurrentProfile (Eq (newProfileName))); + + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), newProfileName.c_str ()); +} + +TEST_F(CCSGSettingsTestProfiles, TestUpdateCurrentProfileNameExisting) +{ + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmock = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + + EXPECT_CALL (*gmock, addProfile (Eq (existingProfileName))); + EXPECT_CALL (*gmock, setCurrentProfile (Eq (existingProfileName))); + + ccsGSettingsBackendUpdateCurrentProfileNameDefault (backend.get (), existingProfileName.c_str ()); +} + +TEST_F(CCSGSettingsTestProfiles, TestDeleteProfileExistingProfile) +{ + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (ccsFreeMockContext, _1)); + + CCSGSettingsBackendGMock *mockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + + std::string currentProfile ("foo"); + std::string otherProfile ("other"); + + GVariant *existingProfiles = NULL; + GVariantBuilder existingProfilesBuilder; + + g_variant_builder_init (&existingProfilesBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&existingProfilesBuilder, "s", currentProfile.c_str ()); + g_variant_builder_add (&existingProfilesBuilder, "s", otherProfile.c_str ()); + + existingProfiles = g_variant_builder_end (&existingProfilesBuilder); + + EXPECT_CALL (*mockBackend, getPluginsWithSetKeys ()).WillOnce (ReturnNull ()); + EXPECT_CALL (*mockBackend, unsetAllChangedPluginKeysInProfile (context.get (), NULL, Eq (currentProfile))); + EXPECT_CALL (*mockBackend, clearPluginsWithSetKeys ()); + + EXPECT_CALL (*mockBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*mockBackend, getExistingProfiles ()).WillOnce (Return (existingProfiles)); + EXPECT_CALL (*mockBackend, setExistingProfiles (AllOf (IsVariantSubtypeOf ("as"), + Not (GVariantHasValueInArray ("s", + currentProfile.c_str (), + boost::bind (streq, _1, _2))), + GVariantHasValueInArray ("s", + otherProfile.c_str (), + boost::bind (streq, _1, _2))))) + .WillOnce (WithArgs <0> (Invoke (g_variant_unref))); + + EXPECT_CALL (*mockBackend, updateProfile (context.get ())); + + deleteProfile (backend.get (), context.get (), currentProfile.c_str ()); +} + TEST_F(CCSGSettingsTestIndependent, TestGetSchemaNameForPlugin) { const gchar *plugin = "foo"; @@ -88,6 +304,32 @@ TEST_F(CCSGSettingsTestIndependent, TestTranslateUpperToLowerForGSettings) EXPECT_EQ (std::string (keyname), "plugin-option"); } +TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForGSettingsNoTrunc) +{ + std::string keyname ("FoO_BaR"); + std::string expected ("foo-bar"); + + CharacterWrapper translated (translateKeyForGSettings (keyname.c_str ())); + + EXPECT_EQ (std::string (translated), expected); +} + +TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForGSettingsTrunc) +{ + const unsigned int OVER_KEY_SIZE = MAX_GSETTINGS_KEY_SIZE + 1; + std::string keyname; + + for (unsigned int i = 0; i <= OVER_KEY_SIZE - 1; i++) + keyname.push_back ('a'); + + ASSERT_EQ (keyname.size (), OVER_KEY_SIZE); + + CharacterWrapper translated (translateKeyForGSettings (keyname.c_str ())); + std::string stringOfTranslated (translated); + + EXPECT_EQ (stringOfTranslated.size (), MAX_GSETTINGS_KEY_SIZE); +} + TEST_F(CCSGSettingsTestIndependent, TestTranslateKeyForCCS) { std::string keyname ("plugin-option"); @@ -173,6 +415,22 @@ TEST_F(CCSGSettingsTestIndependent, TestDecomposeGSettingsPath) g_free (pluginName); } +TEST_F(CCSGSettingsTestIndependent, TestDecomposeGSettingsPathBadPathname) +{ + std::string compiz_gsettings_path ("org/this/path/is/wrong/"); + std::string fake_option_path ("PROFILENAME/plugins/PLUGINNAME"); + + compiz_gsettings_path += fake_option_path; + + CharacterWrapper pluginName (strdup ("aaa")); + char *pluginNameC = pluginName; + unsigned int screenNum = 1; + + EXPECT_FALSE (decomposeGSettingsPath (compiz_gsettings_path.c_str (), &pluginNameC, &screenNum)); + EXPECT_EQ (std::string (pluginNameC), "aaa"); + EXPECT_EQ (screenNum, 1); +} + TEST_F(CCSGSettingsTestIndependent, TestMakeCompizProfilePath) { gchar *a = makeCompizProfilePath ("alpha"); @@ -267,6 +525,11 @@ namespace GVariantSubtypeWrappers { return g_variant_type_is_array (g_variant_get_type (v)); } + + gboolean unknown (GVariant *) + { + return FALSE; + } } struct ArrayVariantInfo @@ -283,6 +546,7 @@ namespace const char *vInt = "i"; const char *vDouble = "d"; const char *vArray = "as"; + const char *vUnknown = ""; ArrayVariantInfo arrayVariantInfo[] = { @@ -296,7 +560,8 @@ namespace { &GVariantSubtypeWrappers::edge, TypeEdge, vString }, { &GVariantSubtypeWrappers::integer, TypeInt, vInt }, { &GVariantSubtypeWrappers::doubleprecision, TypeFloat, vDouble }, - { &GVariantSubtypeWrappers::list, TypeList, vArray } + { &GVariantSubtypeWrappers::list, TypeList, vArray }, + { &GVariantSubtypeWrappers::unknown, TypeNum, vUnknown } }; } @@ -431,60 +696,72 @@ TEST_F(CCSGSettingsTestPluginsWithSetKeysGVariantSetup, TestAppendToPluginsWithS EXPECT_EQ (std::string (newWrittenPlugins[1]), std::string ("bar")); } -class CCSGSettingsTestGObjectListWithProperty : +class CCSGSettingsTestGSettingsWrapperWithSchemaName : public CCSGSettingsTestIndependent { public: - virtual void SetUp () + typedef std::tr1::tuple , CCSGSettingsWrapperGMock *> WrapperMock; + + CCSGSettingsTestGSettingsWrapperWithSchemaName () : + objectSchemaGList (NULL) { CCSGSettingsTestIndependent::SetUp (); - g_type_init (); - - objectSchemaList = NULL; } - virtual void TearDown () + ~CCSGSettingsTestGSettingsWrapperWithSchemaName () { - GList *iter = objectSchemaList; - - while (iter) - { - g_object_unref ((GObject *) iter->data); - iter = g_list_next (iter); - } - - g_list_free (objectSchemaList); - objectSchemaList = NULL; + g_list_free (objectSchemaGList); CCSGSettingsTestIndependent::TearDown (); } - CCSGSettingsWrapGSettings * AddObjectWithSchemaName (const std::string &schemaName) + WrapperMock + AddObject () { - CCSGSettingsWrapGSettings *wrapGSettingsObject = - compizconfig_gsettings_wrap_gsettings_new (COMPIZCONFIG_GSETTINGS_TYPE_MOCK_WRAP_GSETTINGS, schemaName.c_str ()); - objectSchemaList = g_list_append (objectSchemaList, wrapGSettingsObject); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); - return wrapGSettingsObject; + objectSchemaGList = g_list_append (objectSchemaGList, wrapper.get ()); + objectSchemaList.push_back (wrapper); + + return WrapperMock (wrapper, gmockWrapper); } + static const std::string VALUE_FOO; + static const std::string VALUE_BAR; + static const std::string VALUE_BAZ; + protected: - GList *objectSchemaList; + GList *objectSchemaGList; + std::vector > objectSchemaList; }; -TEST_F(CCSGSettingsTestGObjectListWithProperty, TestFindExistingObjectWithSchema) +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_FOO = "foo"; +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_BAR = "bar"; +const std::string CCSGSettingsTestGSettingsWrapperWithSchemaName::VALUE_BAZ = "baz"; + +TEST_F(CCSGSettingsTestGSettingsWrapperWithSchemaName, TestFindExistingObjectWithSchema) { - GObject *obj = reinterpret_cast (AddObjectWithSchemaName ("foo")); + WrapperMock wr1 (AddObject ()); + WrapperMock wr2 (AddObject ()); + + EXPECT_CALL (*(std::tr1::get <1> (wr1)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAR.c_str ())); + EXPECT_CALL (*(std::tr1::get <1> (wr2)), getSchemaName ()).WillRepeatedly (Return (VALUE_FOO.c_str ())); - EXPECT_EQ (findObjectInListWithPropertySchemaName ("foo", objectSchemaList), obj); + EXPECT_EQ (findCCSGSettingsWrapperBySchemaName (VALUE_FOO.c_str (), objectSchemaGList), (std::tr1::get <0> (wr2)).get ()); } -TEST_F(CCSGSettingsTestGObjectListWithProperty, TestNoFindNonexistingObjectWithSchema) +TEST_F(CCSGSettingsTestGSettingsWrapperWithSchemaName, TestNoFindNonexistingObjectWithSchema) { - AddObjectWithSchemaName ("bar"); + WrapperMock wr1 (AddObject ()); + WrapperMock wr2 (AddObject ()); + + EXPECT_CALL (*(std::tr1::get <1> (wr1)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAR.c_str ())); + EXPECT_CALL (*(std::tr1::get <1> (wr2)), getSchemaName ()).WillRepeatedly (Return (VALUE_BAZ.c_str ())); - EXPECT_EQ (NULL, findObjectInListWithPropertySchemaName ("foo", objectSchemaList)); + EXPECT_THAT (findCCSGSettingsWrapperBySchemaName (VALUE_FOO.c_str (), objectSchemaGList), IsNull ()); } class CCSGSettingsTestFindSettingLossy : @@ -745,14 +1022,16 @@ namespace GListContainerEqualityBase (const PopulateFunc &populateGList) { - setenv ("G_SLICE", "always-malloc", 1); + g_setenv ("G_SLICE", "always-malloc", 1); mList = populateGList (); - unsetenv ("G_SLICE"); + g_unsetenv ("G_SLICE"); } - GListContainerEqualityBase (const GListContainerEqualityBase &other) : - mList (g_list_copy (other.mList)) + GListContainerEqualityBase (const GListContainerEqualityBase &other) { + g_setenv ("G_SLICE", "always-malloc", 1); + mList = g_list_copy (other.mList); + g_unsetenv ("G_SLICE"); } GListContainerEqualityBase & @@ -899,3 +1178,857 @@ TEST_P(CCSGSettingsTestVariantTypeToCCSTypeListFixture, TestVariantTypesInListTe INSTANTIATE_TEST_CASE_P(CCSGSettingsTestVariantTypeToCCSTypeListInstantiation, CCSGSettingsTestVariantTypeToCCSTypeListFixture, ValuesIn (variantTypeToListOfCCSTypes)); + +TEST_F(CCSGSettingsTestIndependent, TestGetNameForCCSSetting) +{ + CCSSetting *setting = ccsMockSettingNew (); + CCSSettingGMock *gmock = (CCSSettingGMock *) ccsObjectGetPrivate (setting); + char *rawSettingName = strdup ("FoO_BaR"); + char *properSettingName = translateKeyForGSettings (rawSettingName); + + EXPECT_CALL (*gmock, getName ()).WillOnce (Return (rawSettingName)); + + char *translatedSettingName = getNameForCCSSetting (setting); + + EXPECT_EQ (std::string (translatedSettingName), std::string (properSettingName)); + EXPECT_NE (std::string (translatedSettingName), std::string (rawSettingName)); + + free (translatedSettingName); + free (properSettingName); + free (rawSettingName); + + ccsSettingUnref (setting); +} + +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidNULL) +{ + EXPECT_FALSE (checkReadVariantIsValid (NULL, TypeNum, "foo/bar")); +} + +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeBad) +{ + GVariant *v = g_variant_new ("i", 1); + + EXPECT_FALSE (checkReadVariantIsValid (v, TypeString, "foo/bar")); + + g_variant_unref (v); +} + +TEST_F(CCSGSettingsTestIndependent, TestReadVariantIsValidTypeGood) +{ + GVariant *v = g_variant_new ("i", 1); + + EXPECT_TRUE (checkReadVariantIsValid (v, TypeInt, "foo/bar")); + + g_variant_unref (v); +} + +typedef CCSSettingValueList (*ReadValueListOfDataTypeFunc) (GVariantIter *, guint nItems, CCSSetting *setting); + +class ReadListValueTypeTestParam +{ + public: + + typedef boost::function ReadValueListFunc; + typedef boost::function GVariantPopulator; + typedef boost::function CCSSettingValueListPopulator; + + ReadListValueTypeTestParam (const ReadValueListFunc &readFunc, + const GVariantPopulator &variantPopulator, + const CCSSettingValueListPopulator &listPopulator, + const CCSSettingType &type) : + mReadFunc (readFunc), + mVariantPopulator (variantPopulator), + mListPopulator (listPopulator), + mType (type) + { + } + + CCSSettingValueList read (GVariantIter *iter, + guint nItems, + CCSSetting *setting, + CCSObjectAllocationInterface *allocator) const + { + return mReadFunc (iter, nItems, setting, allocator); + } + + boost::shared_ptr populateVariant () const + { + return boost::shared_ptr (mVariantPopulator (), boost::bind (g_variant_unref, _1)); + } + + boost::shared_ptr <_CCSSettingValueList> populateList (CCSSetting *setting) const + { + return boost::shared_ptr <_CCSSettingValueList> (mListPopulator (setting), boost::bind (ccsSettingValueListFree, _1, TRUE)); + } + + CCSSettingType type () const { return mType; } + + private: + + ReadValueListFunc mReadFunc; + GVariantPopulator mVariantPopulator; + CCSSettingValueListPopulator mListPopulator; + CCSSettingType mType; + +}; + +namespace compizconfig +{ + namespace test + { + namespace impl + { + namespace populators + { + namespace variant + { + GVariant * boolean () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ab")); + g_variant_builder_add (&vb, "b", boolValues[0]); + g_variant_builder_add (&vb, "b", boolValues[1]); + g_variant_builder_add (&vb, "b", boolValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * integer () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ai")); + g_variant_builder_add (&vb, "i", intValues[0]); + g_variant_builder_add (&vb, "i", intValues[1]); + g_variant_builder_add (&vb, "i", intValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * doubleprecision () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("ad")); + g_variant_builder_add (&vb, "d", floatValues[0]); + g_variant_builder_add (&vb, "d", floatValues[1]); + g_variant_builder_add (&vb, "d", floatValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * string () + { + GVariantBuilder vb; + g_variant_builder_init (&vb, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&vb, "s", stringValues[0]); + g_variant_builder_add (&vb, "s", stringValues[1]); + g_variant_builder_add (&vb, "s", stringValues[2]); + return g_variant_builder_end (&vb); + } + + GVariant * color () + { + GVariantBuilder vb; + + CharacterWrapper s1 (ccsColorToString (&(getColorValueList ()[0]))); + CharacterWrapper s2 (ccsColorToString (&(getColorValueList ()[1]))); + CharacterWrapper s3 (ccsColorToString (&(getColorValueList ()[2]))); + + char * c1 = s1; + char * c2 = s2; + char * c3 = s3; + + g_variant_builder_init (&vb, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&vb, "s", c1); + g_variant_builder_add (&vb, "s", c2); + g_variant_builder_add (&vb, "s", c3); + return g_variant_builder_end (&vb); + } + } + } + } + } +} + +class CCSGSettingsTestReadListValueTypes : + public ::testing::TestWithParam +{ +}; + +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueGoodAllocation) +{ + boost::shared_ptr variant = GetParam ().populateVariant (); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + CCSSettingInfo info; + + info.forList.listType = GetParam ().type (); + + boost::shared_ptr <_CCSSettingValueList> valueList (GetParam ().populateList (mockSetting.get ())); + GVariantIter iter; + + g_variant_iter_init (&iter, variant.get ()); + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); + + boost::shared_ptr <_CCSSettingValueList> readValueList (GetParam ().read (&iter, + 3, + mockSetting.get (), + &ccsDefaultObjectAllocator), + boost::bind (ccsSettingValueListFree, _1, TRUE)); + + EXPECT_TRUE (ccsCompareLists (valueList.get (), readValueList.get (), info.forList)); +} + +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueThroughListValueDispatch) +{ + boost::shared_ptr variant = GetParam ().populateVariant (); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + CCSSettingInfo info; + + info.forList.listType = GetParam ().type (); + + boost::shared_ptr <_CCSSettingValueList> valueList (GetParam ().populateList (mockSetting.get ())); + GVariantIter iter; + + g_variant_iter_init (&iter, variant.get ()); + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); + + boost::shared_ptr <_CCSSettingValueList> readValueList (readListValue (variant.get (), + mockSetting.get (), + &ccsDefaultObjectAllocator), + boost::bind (ccsSettingValueListFree, _1, TRUE)); + + EXPECT_TRUE (ccsCompareLists (valueList.get (), readValueList.get (), info.forList)); +} + +TEST_P(CCSGSettingsTestReadListValueTypes, TestListValueBadAllocation) +{ + boost::shared_ptr variant = GetParam ().populateVariant (); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + StrictMock objectAllocationGMock; + FailingObjectAllocation fakeFailingAllocator; + + CCSObjectAllocationInterface failingAllocatorGMock = failingAllocator; + failingAllocatorGMock.allocator = reinterpret_cast (&objectAllocationGMock); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + GVariantIter iter; + g_variant_iter_init (&iter, variant.get ()); + + EXPECT_CALL (objectAllocationGMock, calloc_ (_, _)).WillOnce (Invoke (&fakeFailingAllocator, + &FailingObjectAllocation::calloc_)); + + boost::shared_ptr <_CCSSettingValueList> readValueList (GetParam ().read (&iter, + 3, + mockSetting.get (), + &failingAllocatorGMock)); + + EXPECT_THAT (readValueList.get (), IsNull ()); +} + +namespace variant_populators = compizconfig::test::impl::populators::variant; +namespace list_populators = compizconfig::test::impl::populators::list; + +ReadListValueTypeTestParam readListValueTypeTestParam[] = +{ + ReadListValueTypeTestParam (boost::bind (readBoolListValue, _1, _2, _3, _4), + boost::bind (variant_populators::boolean), + boost::bind (list_populators::boolean, _1), + TypeBool), + ReadListValueTypeTestParam (boost::bind (readIntListValue, _1, _2, _3, _4), + boost::bind (variant_populators::integer), + boost::bind (list_populators::integer, _1), + TypeInt), + ReadListValueTypeTestParam (boost::bind (readFloatListValue, _1, _2, _3, _4), + boost::bind (variant_populators::doubleprecision), + boost::bind (list_populators::doubleprecision, _1), + TypeFloat), + ReadListValueTypeTestParam (boost::bind (readStringListValue, _1, _2, _3, _4), + boost::bind (variant_populators::string), + boost::bind (list_populators::string, _1), + TypeString), + ReadListValueTypeTestParam (boost::bind (readColorListValue, _1, _2, _3, _4), + boost::bind (variant_populators::color), + boost::bind (list_populators::color, _1), + TypeColor) +}; + +INSTANTIATE_TEST_CASE_P (TestGSettingsReadListValueParameterized, CCSGSettingsTestReadListValueTypes, + ::testing::ValuesIn (readListValueTypeTestParam)); + +class CCSGSettingsBackendReadListValueBadTypesTest : + public ::testing::TestWithParam +{ +}; + +TEST_P (CCSGSettingsBackendReadListValueBadTypesTest, TestGSettingsReadListValueFailsOnNonVariantTypes) +{ + GVariant *variant = NULL; + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + CCSSettingInfo info; + + info.forList.listType = GetParam (); + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&info)); + + EXPECT_THAT (readListValue (variant, mockSetting.get (), &ccsDefaultObjectAllocator), IsNull ()); +} + +CCSSettingType readListValueNonVariantTypes[] = +{ + TypeAction, + TypeKey, + TypeButton, + TypeEdge, + TypeBell, + TypeList, + TypeNum +}; + +INSTANTIATE_TEST_CASE_P (CCSGSettingsBackendReadListValueBadTypesTestParameterized, + CCSGSettingsBackendReadListValueBadTypesTest, + ::testing::ValuesIn (readListValueNonVariantTypes)); + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplCurrentProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (currentProfile.c_str ())); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplDifferentProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + std::string otherProfile ("other"); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (otherProfile.c_str ())); + EXPECT_CALL (*gmockGSettingsBackend, updateCurrentProfileName (Eq (otherProfile))); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplNullProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + std::string otherProfile ("other"); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockGSettingsBackend, updateCurrentProfileName (Eq (std::string (DEFAULTPROF)))); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestUpdateProfileDefaultImplEmptyStringProfile) +{ + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (&ccsFreeMockContext, _1)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (&ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockGSettingsBackend = reinterpret_cast (ccsObjectGetPrivate (backend)); + CCSContextGMock *gmockContext = reinterpret_cast (ccsObjectGetPrivate (context)); + + std::string currentProfile ("mock"); + std::string otherProfile (""); + + EXPECT_CALL (*gmockGSettingsBackend, getCurrentProfile ()).WillOnce (Return (currentProfile.c_str ())); + EXPECT_CALL (*gmockContext, getProfile ()).WillOnce (Return (otherProfile.c_str ())); + EXPECT_CALL (*gmockGSettingsBackend, updateCurrentProfileName (Eq (std::string (DEFAULTPROF)))); + + ccsGSettingsBackendUpdateProfileDefault (backend.get (), context.get ()); +} + +class CCSGSettingsUpdateHandlersTest : + public CCSGSettingsTestIndependent +{ + public: + + CCSGSettingsUpdateHandlersTest () : + gsettingsBackend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)), + gmockBackend (reinterpret_cast (ccsObjectGetPrivate (gsettingsBackend.get ()))), + wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)), + gmockWrapper (reinterpret_cast (ccsObjectGetPrivate (wrapper.get ()))), + context (ccsMockContextNew (), + boost::bind (ccsFreeMockContext, _1)), + gmockContext (reinterpret_cast (ccsObjectGetPrivate (context.get ()))), + plugin (NULL), + setting (NULL), + uncleanKeyName (NULL) + { + } + + ~CCSGSettingsUpdateHandlersTest () + { + if (plugin) + ccsPluginUnref (plugin); + + if (setting) + ccsSettingUnref (setting); + + if (uncleanKeyName) + free (uncleanKeyName); + } + + void SetPathAndKeyname (const std::string &setPath, + const std::string &setKeyName) + { + path = setPath; + keyName = setKeyName; + } + + protected: + + boost::shared_ptr gsettingsBackend; + CCSGSettingsBackendGMock *gmockBackend; + boost::shared_ptr wrapper; + CCSGSettingsWrapperGMock *gmockWrapper; + boost::shared_ptr context; + CCSContextGMock *gmockContext; + std::string path; + std::string keyName; + CCSPlugin *plugin; + CCSSetting *setting; + char *uncleanKeyName; +}; + +TEST_F (CCSGSettingsUpdateHandlersTest, TestBadPath) +{ + SetPathAndKeyname ("/wrong", "foo"); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_THAT (plugin, IsNull ()); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, IsNull ()); +} + +TEST_F (CCSGSettingsUpdateHandlersTest, TestNoPluginFound) +{ + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", "foo-bar"); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (ReturnNull ()); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_THAT (plugin, IsNull ()); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, IsNull ()); +} + +TEST_F (CCSGSettingsUpdateHandlersTest, TestNoSettingFound) +{ + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (ReturnNull ()); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsUpdateHandlersTest, TestSettingNotFoundAndNoTypeMatches) +{ + GVariant *value = g_variant_new_int16 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsUpdateHandlersTest, TestSettingNotFoundAndNoSettingMatches) +{ + GVariant *value = g_variant_new_int32 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + boost::shared_ptr mockSetting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + /* Maybe we should fix ccsSettingGetName to return + * const char * instead of char * */ + CharacterWrapper settingNameInList (strdup ("fbrarr")); + char *settingNameInListC = settingNameInList; + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + boost::shared_ptr <_CCSSettingList> settingList (ccsSettingListAppend (NULL, mockSetting.get ()), + boost::bind (ccsSettingListFree, _1, FALSE)); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + EXPECT_CALL (*gmockPlugin, getPluginSettings ()).WillOnce (Return (settingList.get ())); + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeInt)); + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (settingNameInListC)); + + EXPECT_FALSE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, IsNull ()); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsUpdateHandlersTest, TestSettingMatches) +{ + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + CCSSetting *mockSetting = ccsMockSettingNew (); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (Return (mockSetting)); + EXPECT_TRUE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, mockSetting); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsUpdateHandlersTest, TestFoundSetting) +{ + GVariant *value = g_variant_new_int32 (2); + CCSPlugin *mockPlugin = ccsMockPluginNew (); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (mockPlugin)); + CCSSetting *mockSetting = ccsMockSettingNew (); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (mockSetting)); + std::string gKeyName ("foo-bar"); + + SetPathAndKeyname ("/org/compiz/profiles/baz/plugins/bar", gKeyName.c_str ()); + + /* Maybe we should fix ccsSettingGetName to return + * const char * instead of char * */ + CharacterWrapper settingNameInList (strdup ("foo_bar")); + char *settingNameInListC = settingNameInList; + + CharacterWrapper translated (translateKeyForCCS (gKeyName.c_str ())); + + boost::shared_ptr <_CCSSettingList> settingList (ccsSettingListAppend (NULL, mockSetting), + boost::bind (ccsSettingListFree, _1, FALSE)); + + EXPECT_CALL (*gmockContext, findPlugin (Eq (std::string ("bar")))).WillOnce (Return (mockPlugin)); + EXPECT_CALL (*gmockPlugin, findSetting (Eq (std::string (translated)))).WillOnce (ReturnNull ()); + EXPECT_CALL (*gmockWrapper, getValue (Eq (std::string (gKeyName.c_str ())))).WillOnce (Return (value)); + EXPECT_CALL (*gmockPlugin, getPluginSettings ()).WillOnce (Return (settingList.get ())); + EXPECT_CALL (*gmockSetting, getType ()).WillRepeatedly (Return (TypeInt)); + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (settingNameInListC)); + + EXPECT_TRUE (findSettingAndPluginToUpdateFromPath (wrapper.get (), + path.c_str (), + keyName.c_str (), + context.get (), + &plugin, + &setting, + &uncleanKeyName)); + + EXPECT_EQ (plugin, mockPlugin); + EXPECT_THAT (setting, mockSetting); + EXPECT_THAT (uncleanKeyName, Eq (std::string (translated))); +} + +TEST_F (CCSGSettingsUpdateHandlersTest, TestUnfindableSettingToUpdateSetttingsWithGSettingsKeyName) +{ + SetPathAndKeyname ("/wrong", "bad-key"); + + EXPECT_CALL (*gmockBackend, getContext ()).WillOnce (Return (context.get ())); + EXPECT_CALL (*gmockWrapper, getPath ()).WillOnce (Return (path.c_str ())); + + EXPECT_FALSE (updateSettingWithGSettingsKeyName (gsettingsBackend.get (), + wrapper.get (), + keyName.c_str (), + NULL)); +} + +TEST_F (CCSGSettingsTestIndependent, TestGetVariantAtKeySuccess) +{ + CCSSettingType TYPE = TypeInt; + const std::string KEY ("good-key"); + const std::string PATH ("/org/compiz/mock/plugins/mock"); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + boost::shared_ptr value (g_variant_ref_sink (g_variant_new_int32 (2)), + boost::bind (g_variant_unref, _1)); + + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); + + EXPECT_CALL (*gmockWrapper, getValue (Eq (KEY))).WillOnce (Return (value.get ())); + EXPECT_EQ (getVariantAtKey (wrapper.get (), KEY.c_str (), PATH.c_str (), TYPE), value.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestGetVariantAtKeyFailure) +{ + CCSSettingType TYPE = TypeString; + const std::string KEY ("good-key"); + const std::string PATH ("/org/compiz/mock/plugins/mock"); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + GVariant *value = g_variant_new_int32 (2); + + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); + + EXPECT_CALL (*gmockWrapper, getValue (Eq (KEY))).WillOnce (Return (value)); + EXPECT_THAT (getVariantAtKey (wrapper.get (), KEY.c_str (), PATH.c_str (), TYPE), IsNull ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestMakeSettingPath) +{ + CharacterWrapper PLUGIN (strdup ("mock")); + char *PLUGIN_STR = PLUGIN; + std::string PROFILE ("mock"); + std::string EXPECTED_PATH ("/org/compiz/profiles/mock/plugins/mock/"); + boost::shared_ptr plugin (ccsMockPluginNew (), + boost::bind (ccsPluginUnref, _1)); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (plugin)); + boost::shared_ptr setting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (setting)); + + EXPECT_CALL (*gmockSetting, getParent ()).WillOnce (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, getName ()).WillOnce (Return (PLUGIN_STR)); + + CharacterWrapper path (makeSettingPath (PROFILE.c_str (), setting.get ())); + std::string pathString (path); + + EXPECT_EQ (pathString, EXPECTED_PATH); +} + +TEST_F (CCSGSettingsTestIndependent, TestFindSettingsObject) +{ + CharacterWrapper PLUGIN (strdup ("mock")); + char *PLUGIN_STR = PLUGIN; + std::string PROFILE ("mock"); + std::string EXPECTED_PATH ("/org/compiz/profiles/mock/plugins/mock/"); + boost::shared_ptr plugin (ccsMockPluginNew (), + boost::bind (ccsPluginUnref, _1)); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (plugin)); + boost::shared_ptr setting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (setting)); + + EXPECT_CALL (*gmockSetting, getParent ()).WillOnce (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, getName ()).WillOnce (Return (PLUGIN_STR)); + + CharacterWrapper path (makeSettingPath (PROFILE.c_str (), setting.get ())); + std::string pathString (path); + + EXPECT_EQ (pathString, EXPECTED_PATH); +} + +TEST_F (CCSGSettingsTestIndependent, TestResetOptionToDefault) +{ + CharacterWrapper SETTING_NAME (strdup ("Mock_setting")); + char *SETTING_NAME_STR = SETTING_NAME; + CharacterWrapper TRANSLATED_SETTING_NAME (translateKeyForGSettings (SETTING_NAME)); + CharacterWrapper PLUGIN (strdup ("mock")); + char *PLUGIN_STR = PLUGIN; + std::string PROFILE ("mock"); + boost::shared_ptr wrapper (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapper = reinterpret_cast (ccsObjectGetPrivate (wrapper.get ())); + boost::shared_ptr plugin (ccsMockPluginNew (), + boost::bind (ccsPluginUnref, _1)); + CCSPluginGMock *gmockPlugin = reinterpret_cast (ccsObjectGetPrivate (plugin)); + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + boost::shared_ptr setting (ccsMockSettingNew (), + boost::bind (ccsSettingUnref, _1)); + CCSSettingGMock *gmockSetting = reinterpret_cast (ccsObjectGetPrivate (setting.get ())); + + EXPECT_CALL (*gmockSetting, getName ()).WillRepeatedly (Return (SETTING_NAME_STR)); + EXPECT_CALL (*gmockSetting, getParent ()).WillRepeatedly (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, getName ()).WillRepeatedly (Return (PLUGIN_STR)); + EXPECT_CALL (*gmockPlugin, getContext ()).WillRepeatedly (ReturnNull ()); + + EXPECT_CALL (*gmockBackend, getCurrentProfile ()).WillRepeatedly (Return (PROFILE.c_str ())); + EXPECT_CALL (*gmockBackend, getSettingsObjectForPluginWithPath (Eq (std::string (PLUGIN)), + _, + IsNull ())).WillOnce (Return (wrapper.get ())); + + EXPECT_CALL (*gmockWrapper, resetKey (Eq (std::string (TRANSLATED_SETTING_NAME)))); + + resetOptionToDefault (backend.get (), setting.get ()); +} + +TEST_F (CCSGSettingsTestIndependent, TestUnsetAllChangedPluginKeysInProfileDefaultImpl) +{ + std::string PLUGIN_FOO ("foo"); + std::string PLUGIN_BAR ("bar"); + + std::string KEY_EXAMPLE_ONE ("example-one"); + std::string KEY_EXAMPLE_TWO ("example-two"); + std::string KEY_EXAMPLE_THREE ("example-three"); + + boost::shared_ptr backend (ccsGSettingsBackendGMockNew (), + boost::bind (ccsGSettingsBackendGMockFree, _1)); + CCSGSettingsBackendGMock *gmockBackend = reinterpret_cast (ccsObjectGetPrivate (backend.get ())); + boost::shared_ptr context (ccsMockContextNew (), + boost::bind (ccsFreeMockContext, _1)); + + GVariantBuilder pluginsWithChangedKeysBuilder; + + const unsigned short NUM_KEYS = 3; + + gchar ** fooKeys = (gchar **) calloc (1, sizeof (char *) * (NUM_KEYS + 1)); + fooKeys[0] = g_strdup (KEY_EXAMPLE_ONE.c_str ()); + fooKeys[1] = g_strdup (KEY_EXAMPLE_TWO.c_str ()); + fooKeys[2] = g_strdup (KEY_EXAMPLE_THREE.c_str ()); + fooKeys[3] = NULL; + + gchar ** barKeys = (gchar **) calloc (1, sizeof (char *) * (NUM_KEYS + 1)); + barKeys[0] = g_strdup (KEY_EXAMPLE_ONE.c_str ()); + barKeys[1] = g_strdup (KEY_EXAMPLE_TWO.c_str ()); + barKeys[2] = g_strdup (KEY_EXAMPLE_THREE.c_str ()); + barKeys[3] = NULL; + + g_variant_builder_init (&pluginsWithChangedKeysBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&pluginsWithChangedKeysBuilder, "s", PLUGIN_FOO.c_str ()); + g_variant_builder_add (&pluginsWithChangedKeysBuilder, "s", PLUGIN_BAR.c_str ()); + + boost::shared_ptr pluginsWithChangedKeys (g_variant_ref_sink (g_variant_builder_end (&pluginsWithChangedKeysBuilder)), + boost::bind (g_variant_unref, _1)); + + boost::shared_ptr wrapperForFoo (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapperForFoo = reinterpret_cast (ccsObjectGetPrivate (wrapperForFoo.get ())); + boost::shared_ptr wrapperForBar (ccsMockGSettingsWrapperNew (), + boost::bind (ccsGSettingsWrapperUnref, _1)); + CCSGSettingsWrapperGMock *gmockWrapperForBar = reinterpret_cast (ccsObjectGetPrivate (wrapperForBar.get ())); + + + /* Get the settings wrapper */ + EXPECT_CALL (*gmockBackend, getSettingsObjectForPluginWithPath (Eq (PLUGIN_FOO), _, context.get ())).WillOnce (Return (wrapperForFoo.get ())); + + /* List the keys */ + EXPECT_CALL (*gmockWrapperForFoo, listKeys ()).WillOnce (Return (fooKeys)); + + /* Unset all the keys */ + EXPECT_CALL (*gmockWrapperForFoo, resetKey (Eq (KEY_EXAMPLE_ONE))); + EXPECT_CALL (*gmockWrapperForFoo, resetKey (Eq (KEY_EXAMPLE_TWO))); + EXPECT_CALL (*gmockWrapperForFoo, resetKey (Eq (KEY_EXAMPLE_THREE))); + + /* Get the settings wrapper */ + EXPECT_CALL (*gmockBackend, getSettingsObjectForPluginWithPath (Eq (PLUGIN_BAR), _, context.get ())).WillOnce (Return (wrapperForBar.get ())); + + /* List the keys */ + EXPECT_CALL (*gmockWrapperForBar, listKeys ()).WillOnce (Return (barKeys)); + + /* Unset all the keys */ + EXPECT_CALL (*gmockWrapperForBar, resetKey (Eq (KEY_EXAMPLE_ONE))); + EXPECT_CALL (*gmockWrapperForBar, resetKey (Eq (KEY_EXAMPLE_TWO))); + EXPECT_CALL (*gmockWrapperForBar, resetKey (Eq (KEY_EXAMPLE_THREE))); + + ccsGSettingsBackendUnsetAllChangedPluginKeysInProfileDefault (backend.get (), + context.get (), + pluginsWithChangedKeys.get (), + "mock"); +} diff --git a/compizconfig/gsettings/tests/test_gsettings_tests.h b/compizconfig/gsettings/tests/test_gsettings_tests.h index 6125bb2a117ee0176415482423fe33cf40d83ba6..fbc25d997cc9fffbde07aa79da2850059772f969 100644 --- a/compizconfig/gsettings/tests/test_gsettings_tests.h +++ b/compizconfig/gsettings/tests/test_gsettings_tests.h @@ -1,4 +1,10 @@ +#ifndef _COMPIZCONFIG_TEST_GSETTINGS_TESTS_H +#define _COMPIZCONFIG_TEST_GSETTINGS_TESTS_H + #include +#include +#include +#include using ::testing::TestWithParam; @@ -24,6 +30,28 @@ class CCSGSettingsTestingEnv } }; +class CCSGSettingsMemoryBackendTestingEnv : + public CCSGSettingsTestingEnv +{ + public: + + virtual void SetUpEnv () + { + CCSGSettingsTestingEnv::SetUpEnv (); + + g_setenv ("GSETTINGS_SCHEMA_DIR", MOCK_PATH.c_str (), true); + g_setenv ("GSETTINGS_BACKEND", "memory", 1); + } + + virtual void TearDownEnv () + { + g_unsetenv ("GSETTINGS_BACKEND"); + g_unsetenv ("GSETTINGS_SCHEMA_DIR"); + + CCSGSettingsTestingEnv::TearDownEnv (); + } +}; + class CCSGSettingsTest : public CCSGSettingsTestingEnv, public ::testing::TestWithParam @@ -60,6 +88,8 @@ class CCSGSettingsTestIndependent : virtual void SetUp () { + g_type_init (); + CCSGSettingsTestingEnv::SetUpEnv (); } @@ -69,3 +99,23 @@ class CCSGSettingsTestIndependent : } }; +class CCSGSettingsTestWithMemoryBackend : + public CCSGSettingsTestIndependent, + public CCSGSettingsMemoryBackendTestingEnv +{ + public: + + virtual void SetUp () + { + CCSGSettingsTestIndependent::SetUp (); + CCSGSettingsMemoryBackendTestingEnv::SetUpEnv (); + } + + virtual void TearDown () + { + CCSGSettingsMemoryBackendTestingEnv::TearDownEnv (); + CCSGSettingsTestIndependent::TearDown (); + } +}; + +#endif diff --git a/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..df80cdb273e1738077bffb147612773047926e75 --- /dev/null +++ b/compizconfig/gsettings/tests/test_gsettings_wrapper.cpp @@ -0,0 +1,249 @@ +#include + +#include +#include + +#include +#include +#include + +#include + +#include "test_gsettings_tests.h" +#include + +using ::testing::NotNull; +using ::testing::Eq; +using ::testing::_; + + +class CCSGSettingsWrapperTest : + public CCSGSettingsTestWithMemoryBackend +{ + public: + + CCSGSettingsWrapperTest () : + mockSchema ("org.compiz.mock"), + mockPath ("/org/compiz/mock/mock") + { + } + + virtual CCSObjectAllocationInterface * GetAllocator () = 0; + + virtual void SetUp () + { + CCSGSettingsTestWithMemoryBackend::SetUp (); + } + + virtual void TearDown () + { + CCSGSettingsTestWithMemoryBackend::TearDown (); + } + + protected: + + std::string mockSchema; + std::string mockPath; + boost::shared_ptr wrapper; + GSettings *settings; +}; + +class CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest : + public CCSGSettingsWrapperTest +{ + protected: + + CCSObjectAllocationInterface * GetAllocator () + { + return &ccsDefaultObjectAllocator; + } +}; + +class CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest : + public CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest +{ + public: + + virtual void SetUp () + { + CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest::SetUp (); + + wrapper.reset (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), + mockPath.c_str (), + GetAllocator ()), + boost::bind (ccsFreeGSettingsWrapper, _1)); + + ASSERT_THAT (wrapper.get (), NotNull ()); + + settings = ccsGSettingsWrapperGetGSettings (wrapper.get ()); + + ASSERT_THAT (settings, NotNull ()); + } +}; + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest, TestWrapperConstruction) +{ + boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), + mockPath.c_str (), + &ccsDefaultObjectAllocator), + boost::bind (ccsFreeGSettingsWrapper, _1)); + + EXPECT_THAT (wrapper.get (), NotNull ()); +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorTest, TestGetGSettingsWrapper) +{ + boost::shared_ptr wrapper (ccsGSettingsWrapperNewForSchemaWithPath (mockSchema.c_str (), + mockPath.c_str (), + &ccsDefaultObjectAllocator), + boost::bind (ccsFreeGSettingsWrapper, _1)); + + ASSERT_THAT (wrapper.get (), NotNull ()); + EXPECT_THAT (ccsGSettingsWrapperGetGSettings (wrapper.get ()), NotNull ()); +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestSetValueOnWrapper) +{ + const unsigned int VALUE = 2; + const std::string KEY ("integer-setting"); + boost::shared_ptr variant (g_variant_new ("i", VALUE, NULL), + boost::bind (g_variant_unref, _1)); + ccsGSettingsWrapperSetValue (wrapper.get (), KEY.c_str (), variant.get ()); + + boost::shared_ptr value (g_settings_get_value (settings, KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + int v = g_variant_get_int32 (value.get ()); + EXPECT_EQ (VALUE, v); +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetValueOnWrapper) +{ + const double VALUE = 3.0; + const std::string KEY ("float-setting"); + boost::shared_ptr variant (g_variant_new ("d", VALUE, NULL), + boost::bind (g_variant_unref, _1)); + g_settings_set_value (settings, KEY.c_str (), variant.get ()); + boost::shared_ptr value (ccsGSettingsWrapperGetValue (wrapper.get (), + KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + double v = (double) g_variant_get_double (value.get ()); + EXPECT_EQ (VALUE, v); +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestResetKeyOnWrapper) +{ + const char * DEFAULT = ""; + const char * VALUE = "foo"; + const std::string KEY ("string-setting"); + GVariant *variant = g_variant_new ("s", VALUE); + ccsGSettingsWrapperSetValue (wrapper.get (), KEY.c_str (), variant); + + boost::shared_ptr value (g_settings_get_value (settings, KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + gsize length; + std::string v (g_variant_get_string (value.get (), &length)); + ASSERT_EQ (strlen (VALUE), length); + ASSERT_THAT (v, Eq (VALUE)); + + ccsGSettingsWrapperResetKey (wrapper.get (), KEY.c_str ()); + + value.reset (g_settings_get_value (settings, KEY.c_str ()), + boost::bind (g_variant_unref, _1)); + + v = std::string (g_variant_get_string (value.get (), &length)); + ASSERT_EQ (strlen (DEFAULT), length); + ASSERT_THAT (v, Eq (DEFAULT)); +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestListKeysOnWrapper) +{ + const char * EXPECTED_KEYS[] = + { + "bell-setting", + "bool-list-setting", + "boolean-setting", + "button-setting", + "color-list-setting", + "color-setting", + "edge-setting", + "float-list-setting", + "float-setting", + "int-list-setting", + "integer-setting", + "key-setting", + "match-list-setting", + "match-setting", + "string-list-setting", + "string-setting" + }; + + boost::shared_ptr keys (ccsGSettingsWrapperListKeys (wrapper.get ()), + boost::bind (g_strfreev, _1)); + + ASSERT_EQ (g_strv_length (keys.get ()), + sizeof (EXPECTED_KEYS) / + sizeof (EXPECTED_KEYS[0])); +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetSchemaName) +{ + EXPECT_THAT (ccsGSettingsWrapperGetSchemaName (wrapper.get ()), Eq (mockSchema)); +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestGetPath) +{ + EXPECT_THAT (ccsGSettingsWrapperGetPath (wrapper.get ()), Eq (mockPath)); +} + +namespace signal_test +{ + class VerificationInterface + { + public: + + virtual ~VerificationInterface () {} + virtual void Verify (GSettings *settings, gchar *keyname) = 0; + }; + + class VerificationMock : + public VerificationInterface + { + public: + + MOCK_METHOD2 (Verify, void (GSettings *settings, gchar *keyname)); + }; + + + void dummyChangedSignal (GSettings *s, + gchar *keyName, + gpointer user_data) + { + VerificationInterface *verifier = reinterpret_cast (user_data); + verifier->Verify (s, keyName); + } +} + +TEST_F (CCSGSettingsWrapperWithMemoryBackendEnvGoodAllocatorAutoInitTest, TestConnectToChangedSignal) +{ + std::string keyname ("int-setting"); + signal_test::VerificationMock mv; + + /* We're not able to verify the keyname + * at the moment, need a person who knows + * GSignal better than I do to figure this + * one out */ + EXPECT_CALL (mv, Verify (settings, _)); + + ccsGSettingsWrapperConnectToChangedSignal (wrapper.get (), + (GCallback) signal_test::dummyChangedSignal, + (gpointer) static_cast (&mv)); + + g_signal_emit_by_name (G_OBJECT (settings), + "changed", + settings, + keyname.c_str (), + NULL); +} diff --git a/compizconfig/integration/CMakeLists.txt b/compizconfig/integration/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c795d0ff37b3fd9508851a6cd8b79ff900a1bb5c --- /dev/null +++ b/compizconfig/integration/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (gnome) diff --git a/compizconfig/integration/gnome/CMakeLists.txt b/compizconfig/integration/gnome/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b8bb0d4cb29ce6238e3307c2668cb1982dcbea9a --- /dev/null +++ b/compizconfig/integration/gnome/CMakeLists.txt @@ -0,0 +1,41 @@ +include (FindPkgConfig) + +add_subdirectory (gconf) +add_subdirectory (gsettings) + +set (_deps + glib-2.0>=2.20.0 + gio-2.0>=2.25.0) + +compiz_pkg_check_modules (COMPIZCONFIG_GNOME_INTEGRATION ${_deps}) + +if (COMPIZCONFIG_GNOME_INTEGRATION_FOUND) + + include_directories (${CMAKE_SOURCE_DIR}/compizconfig/libcompizconfig/include + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/include + ${COMPIZCONFIG_GNOME_INTEGRATION_INCLUDE_DIRS}) + + link_directories (${CMAKE_BINARY_DIR}/compizconfig/libcompizconfig + ${COMPIZCONFIG_GNOME_INTEGRATION_LIBRARY_DIRS}) + + add_library (compizconfig_gnome_integration_constants STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/ccs_gnome_integration_constants.c) + + add_library (compizconfig_gnome_integration STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/ccs_gnome_integration.c) + + target_link_libraries (compizconfig_gnome_integration + compizconfig_gnome_integration_constants + compizconfig_gnome_integrated_setting + compizconfig + ${COMPIZCONFIG_GNOME_INTEGRATION_LIBRARIES}) + + add_library (compizconfig_gnome_integrated_setting STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/ccs_gnome_integrated_setting.c) + + target_link_libraries (compizconfig_gnome_integrated_setting + compizconfig_gnome_integration_constants + compizconfig + ${COMPIZCONFIG_GNOME_INTEGRATION_LIBRARIES}) + +endif (COMPIZCONFIG_GNOME_INTEGRATION_FOUND) diff --git a/compizconfig/integration/gnome/gconf/CMakeLists.txt b/compizconfig/integration/gnome/gconf/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7182f8ff1ba44b3df888bbc37da4fe73778fd1a2 --- /dev/null +++ b/compizconfig/integration/gnome/gconf/CMakeLists.txt @@ -0,0 +1,46 @@ +include (FindPkgConfig) + +if (USE_GCONF) + + set (_deps + glib-2.0>=2.20.0 + gio-2.0>=2.25.0 + gconf-2.0>=2.31.1) + + compiz_pkg_check_modules (COMPIZCONFIG_GNOME_GCONF_INTEGRATION ${_deps}) + + if (COMPIZCONFIG_GNOME_GCONF_INTEGRATION_FOUND) + + add_definitions (-DUSE_GCONF) + + include_directories (${CMAKE_SOURCE_DIR}/compizconfig/libcompizconfig/include + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/include + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/gconf/include + ${COMPIZCONFIG_GNOME_GCONF_INTEGRATION_INCLUDE_DIRS}) + + link_directories (${CMAKE_BINARY_DIR}/compizconfig/libcompizconfig + ${CMAKE_BINARY_DIR}/compizconfig/integration/gnome + ${COMPIZCONFIG_GNOME_GCONF_INTEGRATION_LIBRARY_DIRS}) + + add_library (compizconfig_gnome_integration_gconf_integrated_setting STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/ccs_gnome_integration_gconf_integrated_setting.c) + + target_link_libraries (compizconfig_gnome_integration_gconf_integrated_setting + compizconfig_gnome_integrated_setting + compizconfig_gnome_integration_constants + compizconfig + ${COMPIZCONFIG_GNOME_GCONF_INTEGRATION_LIBRARIES}) + + add_library (compizconfig_gnome_integration_gconf_setting_factory STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/ccs_gnome_integration_gconf_integrated_setting_factory.c) + + target_link_libraries (compizconfig_gnome_integration_gconf_setting_factory + compizconfig_gnome_integration_constants + compizconfig_gnome_integrated_setting + compizconfig_gnome_integration_gconf_integrated_setting + compizconfig + ${COMPIZCONFIG_GNOME_GCONF_INTEGRATION_LIBRARIES}) + + endif (COMPIZCONFIG_GNOME_GCONF_INTEGRATION_FOUND) + +endif (USE_GCONF) diff --git a/compizconfig/integration/gnome/gconf/include/ccs_gnome_integration_gconf_integrated_setting.h b/compizconfig/integration/gnome/gconf/include/ccs_gnome_integration_gconf_integrated_setting.h new file mode 100644 index 0000000000000000000000000000000000000000..ef92d926375e5d1752ae9a73fbe53d2fc444ddc1 --- /dev/null +++ b/compizconfig/integration/gnome/gconf/include/ccs_gnome_integration_gconf_integrated_setting.h @@ -0,0 +1,33 @@ +#ifndef _CCS_GNOME_GCONF_INTEGRATED_SETTING_H +#define _CCS_GNOME_GCONF_INTEGRATED_SETTING_H + +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSIntegratedSetting CCSIntegratedSetting; +typedef struct _CCSIntegratedSettingInfo CCSIntegratedSettingInfo; +typedef struct _CCSGNOMEIntegratedSettingInfo CCSGNOMEIntegratedSettingInfo; +typedef struct _GConfClient GConfClient; + +/** + * @brief ccsGConfIntegratedSettingNew + * @param base a CCSGNOMEIntegratedSetting + * @param client a GConfClient + * @param section the preceeding path to the keyname + * @param ai a CCSObjectAllocationInterface + * @return + * + * Creates the GConf implementation of a CCSIntegratedSetting, which will + * write to GConf keys when necessary. + */ +CCSIntegratedSetting * +ccsGConfIntegratedSettingNew (CCSGNOMEIntegratedSettingInfo *base, + GConfClient *client, + const char *section, + CCSObjectAllocationInterface *ai); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/integration/gnome/gconf/include/ccs_gnome_integration_gconf_integrated_setting_factory.h b/compizconfig/integration/gnome/gconf/include/ccs_gnome_integration_gconf_integrated_setting_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..3add8abfcefee94ff453b2097811351add7e9e7f --- /dev/null +++ b/compizconfig/integration/gnome/gconf/include/ccs_gnome_integration_gconf_integrated_setting_factory.h @@ -0,0 +1,31 @@ +#ifndef _CCS_GNOME_GCONF_INTEGRATED_SETTING_FACTORY_H +#define _CCS_GNOME_GCONF_INTEGRATED_SETTING_FACTORY_H + +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSIntegratedSettingFactory CCSIntegratedSettingFactory; +typedef struct _CCSGNOMEValueChangeData CCSGNOMEValueChangeData; +typedef struct _GConfClient GConfClient; + +/** + * @brief ccsGConfIntegratedSettingFactoryNew + * @param client an existing GConfClient or NULL + * @param data some data to pass to the change callback + * @param ai a CCSObjectAllocationInterface + * @return a new CCSIntegratedSettingFactory + * + * CCSGConfIntegratedSettingFactory implements CCSIntegratedSettingFactory * + * and will create CCSGConfIntegratedSetting objects (which implement + * CCSIntegratedSetting). + */ +CCSIntegratedSettingFactory * +ccsGConfIntegratedSettingFactoryNew (GConfClient *client, + CCSGNOMEValueChangeData *data, + CCSObjectAllocationInterface *ai); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/integration/gnome/gconf/src/ccs_gnome_integration_gconf_integrated_setting.c b/compizconfig/integration/gnome/gconf/src/ccs_gnome_integration_gconf_integrated_setting.c new file mode 100644 index 0000000000000000000000000000000000000000..4ff78028e1ca525a1927e9f5e5755ffab93a893a --- /dev/null +++ b/compizconfig/integration/gnome/gconf/src/ccs_gnome_integration_gconf_integrated_setting.c @@ -0,0 +1,275 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "ccs_gnome_integration_gconf_integrated_setting.h" +#include "ccs_gnome_integrated_setting.h" +#include "ccs_gnome_integration_constants.h" + + +/* CCSGConfIntegratedSetting implementation */ +typedef struct _CCSGConfIntegratedSettingPrivate CCSGConfIntegratedSettingPrivate; + +struct _CCSGConfIntegratedSettingPrivate +{ + CCSGNOMEIntegratedSettingInfo *gnomeIntegratedSettingInfo; + GConfClient *client; + const char *sectionName; +}; + +SpecialOptionType +ccsGConfIntegratedSettingGetSpecialOptionType (CCSGNOMEIntegratedSettingInfo *setting) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + return ccsGNOMEIntegratedSettingInfoGetSpecialOptionType (priv->gnomeIntegratedSettingInfo); +} + +const char * +ccsGConfIntegratedSettingGetGNOMEName (CCSGNOMEIntegratedSettingInfo *setting) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + return ccsGNOMEIntegratedSettingInfoGetGNOMEName (priv->gnomeIntegratedSettingInfo); +} + +CCSSettingValue * +ccsGConfIntegratedSettingReadValue (CCSIntegratedSetting *setting, CCSSettingType type) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + CCSSettingValue *v = calloc (1, sizeof (CCSSettingValue)); + const char *gnomeKeyName = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting); + char *gnomeKeyPath = g_strconcat (priv->sectionName, gnomeKeyName, NULL); + + v->isListChild = FALSE; + v->parent = NULL; + v->refCount = 1; + + GConfValue *gconfValue; + GError *err = NULL; + + gconfValue = gconf_client_get (priv->client, + gnomeKeyPath, + &err); + + if (!gconfValue) + { + ccsError ("NULL encountered while reading GConf setting"); + free (gnomeKeyPath); + return v; + } + + if (err) + { + ccsError ("%s", err->message); + g_error_free (err); + free (gnomeKeyPath); + return v; + } + + switch (type) + { + case TypeInt: + if (gconfValue->type != GCONF_VALUE_INT) + { + ccsError ("Expected integer value"); + break; + } + + v->value.asInt = gconf_value_get_int (gconfValue); + break; + case TypeBool: + if (gconfValue->type != GCONF_VALUE_BOOL) + { + ccsError ("Expected boolean value"); + break; + } + + v->value.asBool = gconf_value_get_bool (gconfValue) ? TRUE : FALSE; + break; + case TypeString: + case TypeKey: + if (gconfValue->type != GCONF_VALUE_STRING) + { + ccsError ("Expected string value"); + break; + } + + const char *str = gconf_value_get_string (gconfValue); + + v->value.asString = strdup (str ? str : ""); + break; + default: + g_assert_not_reached (); + } + + gconf_value_free (gconfValue); + free (gnomeKeyPath); + + return v; +} + +void +ccsGConfIntegratedSettingWriteValue (CCSIntegratedSetting *setting, CCSSettingValue *v, CCSSettingType type) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + const char *gnomeKeyName = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting); + char *gnomeKeyPath = g_strconcat (priv->sectionName, gnomeKeyName, NULL); + GError *err = NULL; + + switch (type) + { + case TypeInt: + { + int currentValue = gconf_client_get_int (priv->client, gnomeKeyPath, &err); + + if (!err && (currentValue != v->value.asInt)) + gconf_client_set_int(priv->client, gnomeKeyPath, + v->value.asInt, NULL); + } + break; + case TypeBool: + { + Bool newValue = v->value.asBool; + gboolean currentValue; + + currentValue = gconf_client_get_bool (priv->client, gnomeKeyPath, &err); + + if (!err && ((currentValue && !newValue) || + (!currentValue && newValue))) + gconf_client_set_bool (priv->client, gnomeKeyPath, + newValue, NULL); + } + break; + case TypeString: + case TypeKey: + { + char *newValue = v->value.asString; + gchar *currentValue; + + currentValue = gconf_client_get_string (priv->client, gnomeKeyPath, &err); + + if (!err && currentValue) + { + if (strcmp (currentValue, newValue) != 0) + gconf_client_set_string (priv->client, gnomeKeyPath, + newValue, NULL); + g_free (currentValue); + } + } + break; + default: + g_assert_not_reached (); + break; + } + + if (err) + { + ccsError ("%s", err->message); + g_error_free (err); + } + + free (gnomeKeyPath); +} + +const char * +ccsGConfIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *info) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info); + + return ccsIntegratedSettingInfoPluginName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo); +} + +const char * +ccsGConfIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *info) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info); + + return ccsIntegratedSettingInfoSettingName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo); +} + +CCSSettingType +ccsGConfIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *info) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (info); + + return ccsIntegratedSettingInfoGetType ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo); +} + +void +ccsGConfIntegratedSettingFree (CCSIntegratedSetting *setting) +{ + CCSGConfIntegratedSettingPrivate *priv = (CCSGConfIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + ccsIntegratedSettingInfoUnref ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSettingInfo); + ccsObjectFinalize (setting); + + (*setting->object.object_allocation->free_) (setting->object.object_allocation->allocator, setting); +} + +void +ccsGConfIntegratedSettingInfoFree (CCSIntegratedSettingInfo *info) +{ + ccsGConfIntegratedSettingFree ((CCSIntegratedSetting *) info); +} + +const CCSGNOMEIntegratedSettingInfoInterface ccsGConfGNOMEIntegratedSettingInfoInterface = +{ + ccsGConfIntegratedSettingGetSpecialOptionType, + ccsGConfIntegratedSettingGetGNOMEName +}; + +const CCSIntegratedSettingInterface ccsGConfIntegratedSettingInterface = +{ + ccsGConfIntegratedSettingReadValue, + ccsGConfIntegratedSettingWriteValue, + ccsGConfIntegratedSettingFree +}; + +const CCSIntegratedSettingInfoInterface ccsGConfIntegratedSettingInfoInterface = +{ + ccsGConfIntegratedSettingInfoPluginName, + ccsGConfIntegratedSettingInfoSettingName, + ccsGConfIntegratedSettingInfoGetType, + ccsGConfIntegratedSettingInfoFree +}; + +CCSIntegratedSetting * +ccsGConfIntegratedSettingNew (CCSGNOMEIntegratedSettingInfo *base, + GConfClient *client, + const char *section, + CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSetting *setting = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSetting)); + + if (!setting) + return NULL; + + CCSGConfIntegratedSettingPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGConfIntegratedSettingPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, priv); + return NULL; + } + + priv->gnomeIntegratedSettingInfo = base; + priv->client = client; + priv->sectionName = section; + + ccsObjectInit (setting, ai); + ccsObjectSetPrivate (setting, (CCSPrivate *) priv); + ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGConfIntegratedSettingInfoInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInfoInterface)); + ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGConfIntegratedSettingInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInterface)); + ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGConfGNOMEIntegratedSettingInfoInterface, GET_INTERFACE_TYPE (CCSGNOMEIntegratedSettingInfoInterface)); + ccsIntegratedSettingRef (setting); + + return setting; +} diff --git a/compizconfig/integration/gnome/gconf/src/ccs_gnome_integration_gconf_integrated_setting_factory.c b/compizconfig/integration/gnome/gconf/src/ccs_gnome_integration_gconf_integrated_setting_factory.c new file mode 100644 index 0000000000000000000000000000000000000000..4fd83d64586e9db72e82da925d01490586e05b3b --- /dev/null +++ b/compizconfig/integration/gnome/gconf/src/ccs_gnome_integration_gconf_integrated_setting_factory.c @@ -0,0 +1,247 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include "ccs_gnome_integration.h" +#include "ccs_gnome_integrated_setting.h" +#include "ccs_gnome_integration_constants.h" +#include "ccs_gnome_integration_gconf_integrated_setting.h" + +typedef struct _CCSGConfIntegratedSettingFactoryPrivate CCSGConfIntegratedSettingFactoryPrivate; + +struct _CCSGConfIntegratedSettingFactoryPrivate +{ + GConfClient *client; + guint gnomeGConfNotifyIds[NUM_WATCHED_DIRS]; + GHashTable *pluginsToSettingsSectionsHashTable; + GHashTable *pluginsToSettingsSpecialTypesHashTable; + GHashTable *pluginsToSettingNameGNOMENameHashTable; + CCSGNOMEValueChangeData *valueChangedData; +}; + +static void +gnomeGConfValueChanged (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer user_data) +{ + CCSGNOMEValueChangeData *data = (CCSGNOMEValueChangeData *) user_data; + const gchar *keyName = gconf_entry_get_key (entry); + gchar *baseName = g_path_get_basename (keyName); + + /* We don't care if integration is not enabled */ + if (!ccsGetIntegrationEnabled (data->context)) + return; + + CCSIntegratedSettingList settingList = ccsIntegratedSettingsStorageFindMatchingSettingsByPredicate (data->storage, + ccsGNOMEIntegrationFindSettingsMatchingPredicate, + baseName); + + ccsIntegrationUpdateIntegratedSettings (data->integration, + data->context, + settingList); + + g_free (baseName); +} + +static CCSIntegratedSetting * +createNewGConfIntegratedSetting (GConfClient *client, + const char *sectionName, + const char *gnomeName, + const char *pluginName, + const char *settingName, + CCSSettingType type, + SpecialOptionType specialOptionType, + CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSettingInfo *sharedIntegratedSettingInfo = ccsSharedIntegratedSettingInfoNew (pluginName, settingName, type, ai); + + if (!sharedIntegratedSettingInfo) + return NULL; + + CCSGNOMEIntegratedSettingInfo *gnomeIntegratedSettingInfo = ccsGNOMEIntegratedSettingInfoNew (sharedIntegratedSettingInfo, specialOptionType, gnomeName, ai); + + if (!gnomeIntegratedSettingInfo) + { + ccsIntegratedSettingInfoUnref (sharedIntegratedSettingInfo); + return NULL; + } + + CCSIntegratedSetting *gconfIntegratedSetting = ccsGConfIntegratedSettingNew (gnomeIntegratedSettingInfo, client, sectionName, ai); + + if (!gconfIntegratedSetting) + { + ccsIntegratedSettingInfoUnref ((CCSIntegratedSettingInfo *) gnomeIntegratedSettingInfo); + return NULL; + } + + return gconfIntegratedSetting; +} + +static void +finiGConfClient (GConfClient *client, + guint *gnomeGConfNotifyIds) +{ + int i; + + gconf_client_clear_cache (client); + + for (i = 0; i < NUM_WATCHED_DIRS; i++) + { + if (gnomeGConfNotifyIds[i]) + { + gconf_client_notify_remove (client, gnomeGConfNotifyIds[0]); + gnomeGConfNotifyIds[i] = 0; + } + gconf_client_remove_dir (client, watchedGConfGnomeDirectories[i], NULL); + } + gconf_client_suggest_sync (client, NULL); + + g_object_unref (client); +} + +static void +registerGConfClient (GConfClient *client, + guint *gnomeGConfNotifyIds, + CCSGNOMEValueChangeData *data, + GConfClientNotifyFunc func) +{ + int i; + + for (i = 0; i < NUM_WATCHED_DIRS; i++) + gnomeGConfNotifyIds[i] = gconf_client_notify_add (client, + watchedGConfGnomeDirectories[i], + func, (gpointer) data, + NULL, NULL); +} + +static void +initGConfClient (CCSIntegratedSettingFactory *factory) +{ + int i; + CCSGConfIntegratedSettingFactoryPrivate *priv = (CCSGConfIntegratedSettingFactoryPrivate *) ccsObjectGetPrivate (factory); + priv->client = gconf_client_get_default (); + + for (i = 0; i < NUM_WATCHED_DIRS; i++) + gconf_client_add_dir (priv->client, watchedGConfGnomeDirectories[i], + GCONF_CLIENT_PRELOAD_NONE, NULL); +} + +CCSIntegratedSetting * +ccsGConfIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType (CCSIntegratedSettingFactory *factory, + CCSIntegration *integration, + const char *pluginName, + const char *settingName, + CCSSettingType type) +{ + CCSGConfIntegratedSettingFactoryPrivate *priv = (CCSGConfIntegratedSettingFactoryPrivate *) ccsObjectGetPrivate (factory); + GHashTable *settingsSectionsHashTable = g_hash_table_lookup (priv->pluginsToSettingsSectionsHashTable, pluginName); + GHashTable *settingsSpecialTypesHashTable = g_hash_table_lookup (priv->pluginsToSettingsSpecialTypesHashTable, pluginName); + GHashTable *settingsSettingNameGNOMENameHashTable = g_hash_table_lookup (priv->pluginsToSettingNameGNOMENameHashTable, pluginName); + + if (!priv->client) + initGConfClient (factory); + + if (!priv->gnomeGConfNotifyIds[0]) + registerGConfClient (priv->client, priv->gnomeGConfNotifyIds, priv->valueChangedData, gnomeGConfValueChanged); + + if (settingsSectionsHashTable && + settingsSpecialTypesHashTable && + settingsSettingNameGNOMENameHashTable) + { + const gchar *sectionName = g_hash_table_lookup (settingsSectionsHashTable, settingName); + SpecialOptionType specialType = (SpecialOptionType) GPOINTER_TO_INT (g_hash_table_lookup (settingsSpecialTypesHashTable, settingName)); + const gchar *integratedName = g_hash_table_lookup (settingsSettingNameGNOMENameHashTable, settingName); + + return createNewGConfIntegratedSetting (priv->client, + sectionName, + integratedName, + pluginName, + settingName, + type, + specialType, + factory->object.object_allocation); + } + + + return NULL; +} + +void +ccsGConfIntegratedSettingFactoryFree (CCSIntegratedSettingFactory *factory) +{ + CCSGConfIntegratedSettingFactoryPrivate *priv = (CCSGConfIntegratedSettingFactoryPrivate *) ccsObjectGetPrivate (factory); + + if (priv->client) + finiGConfClient (priv->client, priv->gnomeGConfNotifyIds); + + if (priv->pluginsToSettingsSectionsHashTable) + g_hash_table_unref (priv->pluginsToSettingsSectionsHashTable); + + if (priv->pluginsToSettingsSpecialTypesHashTable) + g_hash_table_unref (priv->pluginsToSettingsSpecialTypesHashTable); + + if (priv->pluginsToSettingNameGNOMENameHashTable) + g_hash_table_unref (priv->pluginsToSettingNameGNOMENameHashTable); + + ccsObjectFinalize (factory); + (*factory->object.object_allocation->free_) (factory->object.object_allocation->allocator, factory); +} + + +const CCSIntegratedSettingFactoryInterface ccsGConfIntegratedSettingFactoryInterface = +{ + ccsGConfIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType, + ccsGConfIntegratedSettingFactoryFree +}; + +CCSIntegratedSettingFactory * +ccsGConfIntegratedSettingFactoryNew (GConfClient *client, + CCSGNOMEValueChangeData *valueChangedData, + CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSettingFactory *factory = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSettingFactory)); + + if (!factory) + return NULL; + + CCSGConfIntegratedSettingFactoryPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGConfIntegratedSettingFactoryPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, factory); + return NULL; + } + + if (client) + { + int i; + priv->client = (GConfClient *) g_object_ref (client); + for (i = 0; i < NUM_WATCHED_DIRS; i++) + gconf_client_add_dir (priv->client, watchedGConfGnomeDirectories[i], + GCONF_CLIENT_PRELOAD_NONE, NULL); + } + else + priv->client = NULL; + + priv->pluginsToSettingsSectionsHashTable = ccsGNOMEIntegrationPopulateCategoriesHashTables (); + priv->pluginsToSettingsSpecialTypesHashTable = ccsGNOMEIntegrationPopulateSpecialTypesHashTables (); + priv->pluginsToSettingNameGNOMENameHashTable = ccsGNOMEIntegrationPopulateSettingNameToGNOMENameHashTables (); + priv->valueChangedData = valueChangedData; + + ccsObjectInit (factory, ai); + ccsObjectSetPrivate (factory, (CCSPrivate *) priv); + ccsObjectAddInterface (factory, (const CCSInterface *) &ccsGConfIntegratedSettingFactoryInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingFactoryInterface)); + + ccsIntegratedSettingFactoryRef (factory); + + return factory; +} + diff --git a/compizconfig/integration/gnome/gsettings/CMakeLists.txt b/compizconfig/integration/gnome/gsettings/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..70f0d065bf4aaa12fcf60e696c6f0039048d7042 --- /dev/null +++ b/compizconfig/integration/gnome/gsettings/CMakeLists.txt @@ -0,0 +1,76 @@ +include (FindPkgConfig) + +if (USE_GSETTINGS) + + set (_deps + glib-2.0>=2.20.0 + gio-2.0>=2.25.0) + + compiz_pkg_check_modules (COMPIZCONFIG_GNOME_GSETTINGS_INTEGRATION ${_deps}) + + if (COMPIZCONFIG_GNOME_GSETTINGS_INTEGRATION_FOUND) + + add_definitions (-DUSE_GCONF) + + include_directories (${CMAKE_SOURCE_DIR}/compizconfig/libcompizconfig/include + ${CMAKE_SOURCE_DIR}/compizconfig/gsettings/gsettings_backend_shared + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/include + ${CMAKE_SOURCE_DIR}/compizconfig/integration/gnome/gsettings/include + ${COMPIZCONFIG_GNOME_GSETTINGS_INTEGRATION_INCLUDE_DIRS}) + + link_directories (${CMAKE_BINARY_DIR}/compizconfig/libcompizconfig + ${CMAKE_BINARY_DIR}/compizconfig/gsettings/gsettings_backend_shared + ${CMAKE_BINARY_DIR}/compizconfig/integration/gnome + ${COMPIZCONFIG_GNOME_GSETTINGS_INTEGRATION_LIBRARY_DIRS}) + + add_library (compizconfig_gnome_integration_gsettings_integrated_setting STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/ccs_gnome_integration_gsettings_integrated_setting.c) + + target_link_libraries (compizconfig_gnome_integration_gsettings_integrated_setting + compizconfig_gnome_integrated_setting + compizconfig_gnome_integration_constants + compizconfig + compizconfig_gsettings_util + ${COMPIZCONFIG_GNOME_GSETTINGS_INTEGRATION_LIBRARIES}) + + add_library (compizconfig_gnome_integration_gsettings_setting_factory STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/ccs_gnome_integration_gsettings_integrated_setting_factory.c) + + target_link_libraries (compizconfig_gnome_integration_gsettings_setting_factory + compizconfig_gnome_integration_constants + compizconfig_gnome_integrated_setting + compizconfig_gnome_integration_gsettings_integrated_setting + compizconfig + compizconfig_gsettings_util + ${COMPIZCONFIG_GNOME_GSETTINGS_INTEGRATIONLIBRARIES}) + + find_program (GLIB_COMPILE_SCHEMAS glib-compile-schemas) + + if (GLIB_COMPILE_SCHEMAS) + + set (_integrated_gschema org.compiz.integrated) + set (_integrated_gschema_file ${_integrated_gschema}.gschema.xml) + set (_integrated_gschema_src ${CMAKE_CURRENT_SOURCE_DIR}/${_integrated_gschema_file}) + set (_integrated_gschema_dest ${CMAKE_BINARY_DIR}/generated/glib-2.0/schemas/${_integrated_gschema_file}) + + configure_file (${_integrated_gschema_src} ${_integrated_gschema_dest}) + + add_custom_command ( + OUTPUT ${CMAKE_BINARY_DIR}/glib-2.0/schemas/gschemas.compiled + COMMAND ${GLIB_COMPILE_SCHEMAS} --targetdir=${CMAKE_BINARY_DIR}/glib-2.0/schemas/ + ${CMAKE_BINARY_DIR}/glib-2.0/schemas/ + ) + + add_custom_target (compiz_gsettings_integrated_settings_schema ALL + DEPENDS ${_integrated_gschema_src}) + + add_gsettings_schema_to_recompilation_list (compiz_gsettings_integrated_settings_schema) + + compiz_install_gsettings_schema (${_integrated_gschema_dest} + ${CMAKE_INSTALL_PREFIX}/share/glib-2.0/schemas) + + endif (GLIB_COMPILE_SCHEMAS) + + endif (COMPIZCONFIG_GNOME_GSETTINGS_INTEGRATION_FOUND) + +endif (USE_GSETTINGS) diff --git a/compizconfig/integration/gnome/gsettings/include/ccs_gnome_integration_gsettings_integrated_setting.h b/compizconfig/integration/gnome/gsettings/include/ccs_gnome_integration_gsettings_integrated_setting.h new file mode 100644 index 0000000000000000000000000000000000000000..1ce59704aedcf9513f9e29d9c5a0dcfd85f0a40c --- /dev/null +++ b/compizconfig/integration/gnome/gsettings/include/ccs_gnome_integration_gsettings_integrated_setting.h @@ -0,0 +1,31 @@ +#ifndef _CCS_GNOME_GSETTINGS_INTEGRATED_SETTING_H +#define _CCS_GNOME_GSETTINGS_INTEGRATED_SETTING_H + +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSIntegratedSetting CCSIntegratedSetting; +typedef struct _CCSGNOMEIntegratedSettingInfo CCSGNOMEIntegratedSettingInfo; +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; + +/** + * @brief ccsGSettingsIntegratedSettingNew + * @param base + * @param wrapper + * @param ai + * @return + * + * The GSettings implementation of CCSIntegratedSetting *, which will + * write using a CCSGSettingsWrapper * object when the read and write + * methods are called. + */ +CCSIntegratedSetting * +ccsGSettingsIntegratedSettingNew (CCSGNOMEIntegratedSettingInfo *base, + CCSGSettingsWrapper *wrapper, + CCSObjectAllocationInterface *ai); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/integration/gnome/gsettings/include/ccs_gnome_integration_gsettings_integrated_setting_factory.h b/compizconfig/integration/gnome/gsettings/include/ccs_gnome_integration_gsettings_integrated_setting_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..f7fffdc5897d50ad93b24404e5069a709b91e83b --- /dev/null +++ b/compizconfig/integration/gnome/gsettings/include/ccs_gnome_integration_gsettings_integrated_setting_factory.h @@ -0,0 +1,59 @@ +#ifndef _CCS_GNOME_GCONF_INTEGRATED_SETTING_FACTORY_H +#define _CCS_GNOME_GCONF_INTEGRATED_SETTING_FACTORY_H + +#include +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSIntegratedSettingFactory CCSIntegratedSettingFactory; +typedef struct _CCSGNOMEValueChangeData CCSGNOMEValueChangeData; +typedef struct _CCSGSettingsWrapper CCSGSettingsWrapper; +typedef struct _GSettings GSettings; + +typedef void (*CCSGNOMEIntegrationGSettingsChangedCallback) (GSettings *, gchar *, gpointer); + +typedef struct _CCSGNOMEIntegrationGSettingsWrapperFactory CCSGNOMEIntegrationGSettingsWrapperFactory; +typedef struct _CCSGNOMEIntegrationGSettingsWrapperFactoryInterface CCSGNOMEIntegrationGSettingsWrapperFactoryInterface; + +typedef CCSGSettingsWrapper * (*CCSGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapper) (CCSGNOMEIntegrationGSettingsWrapperFactory *, + const gchar *schema, + CCSGNOMEIntegrationGSettingsChangedCallback callback, + CCSGNOMEValueChangeData *data, + CCSObjectAllocationInterface *ai); + +struct _CCSGNOMEIntegrationGSettingsWrapperFactoryInterface +{ + CCSGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapper newGSettingsWrapper; +}; + +/** + * @brief The _CCSGNOMEIntegrationGSettingsWrapperFactory struct + * + * Will create new CCSGSettingsIntegratedSetting objects on demand + */ +struct _CCSGNOMEIntegrationGSettingsWrapperFactory +{ + CCSObject object; +}; + +unsigned int ccsCCSGNOMEIntegrationGSettingsWrapperFactoryInterfaceGetType (); + +CCSGSettingsWrapper * +ccsGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapper (CCSGNOMEIntegrationGSettingsWrapperFactory *factory, + const gchar *schemaName, + CCSGNOMEIntegrationGSettingsChangedCallback callback, + CCSGNOMEValueChangeData *data, + CCSObjectAllocationInterface *ai); + +CCSGNOMEIntegrationGSettingsWrapperFactory * +ccsGNOMEIntegrationGSettingsWrapperDefaultImplNew (CCSObjectAllocationInterface *ai); + +CCSIntegratedSettingFactory * +ccsGSettingsIntegratedSettingFactoryNew (CCSGNOMEIntegrationGSettingsWrapperFactory *wrapperFactory, + CCSGNOMEValueChangeData *data, + CCSObjectAllocationInterface *ai); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/integration/gnome/gsettings/org.compiz.integrated.gschema.xml b/compizconfig/integration/gnome/gsettings/org.compiz.integrated.gschema.xml new file mode 100644 index 0000000000000000000000000000000000000000..3ff81473cda591b7844db8a0bfca5a84ad6a3f36 --- /dev/null +++ b/compizconfig/integration/gnome/gsettings/org.compiz.integrated.gschema.xml @@ -0,0 +1,111 @@ + + + + + false + + + "" + + + "" + + + "" + + + "" + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + "" + + + "" + + + "" + + + "" + + + "" + + + "" + + + "" + + + "" + + + "" + + + "" + + + "" + + + "" + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Disabled"] + + + ["Alt"] + + + + diff --git a/compizconfig/integration/gnome/gsettings/src/ccs_gnome_integration_gsettings_integrated_setting.c b/compizconfig/integration/gnome/gsettings/src/ccs_gnome_integration_gsettings_integrated_setting.c new file mode 100644 index 0000000000000000000000000000000000000000..12b21a696283891ad4e68af39fb29094f73e0846 --- /dev/null +++ b/compizconfig/integration/gnome/gsettings/src/ccs_gnome_integration_gsettings_integrated_setting.c @@ -0,0 +1,293 @@ +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include "ccs_gnome_integration_gsettings_integrated_setting.h" +#include "ccs_gnome_integrated_setting.h" +#include "ccs_gnome_integration_constants.h" + + +/* CCSGSettingsIntegratedSetting implementation */ +typedef struct _CCSGSettingsIntegratedSettingPrivate CCSGSettingsIntegratedSettingPrivate; + +struct _CCSGSettingsIntegratedSettingPrivate +{ + CCSGNOMEIntegratedSettingInfo *gnomeIntegratedSetting; + CCSGSettingsWrapper *wrapper; +}; + +SpecialOptionType +ccsGSettingsIntegratedSettingGetSpecialOptionType (CCSGNOMEIntegratedSettingInfo *setting) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + return ccsGNOMEIntegratedSettingInfoGetSpecialOptionType (priv->gnomeIntegratedSetting); +} + +const char * +ccsGSettingsIntegratedSettingGetGNOMEName (CCSGNOMEIntegratedSettingInfo *setting) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + return ccsGNOMEIntegratedSettingInfoGetGNOMEName (priv->gnomeIntegratedSetting); +} + +CCSSettingValue * +ccsGSettingsIntegratedSettingReadValue (CCSIntegratedSetting *setting, CCSSettingType type) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + CCSSettingValue *v = calloc (1, sizeof (CCSSettingValue)); + const char *gnomeKeyName = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting); + char *gsettingsTranslatedName = translateKeyForGSettings (gnomeKeyName); + + v->isListChild = FALSE; + v->parent = NULL; + v->refCount = 1; + + GVariant *variant = ccsGSettingsWrapperGetValue (priv->wrapper, gsettingsTranslatedName); + + if (!variant) + free (gsettingsTranslatedName); + + const GVariantType *variantType = G_VARIANT_TYPE (g_variant_get_type_string (variant)); + + switch (type) + { + case TypeInt: + if (!g_variant_type_equal (variantType, G_VARIANT_TYPE_INT32)) + { + ccsError ("Expected integer value"); + break; + } + + v->value.asInt = readIntFromVariant (variant); + break; + case TypeBool: + if (!g_variant_type_equal (variantType, G_VARIANT_TYPE_BOOLEAN)) + { + ccsError ("Expected boolean value"); + break; + } + + v->value.asBool = readBoolFromVariant (variant); + break; + case TypeString: + { + if (!g_variant_type_equal (variantType, G_VARIANT_TYPE_STRING)) + { + ccsError ("Expected string value"); + break; + } + + const char *str = readStringFromVariant (variant); + v->value.asString = strdup (str ? str : ""); + break; + } + case TypeKey: + { + if (!g_variant_type_equal (variantType, G_VARIANT_TYPE ("as"))) + { + ccsError ("Expected array-of-string value"); + break; + } + + gsize len; + const gchar **strv = g_variant_get_strv (variant, &len); + + if (strv) + v->value.asString = strdup (strv[0] ? strv[0] : ""); + else + v->value.asString = strdup (""); + + g_free (strv); + break; + } + default: + g_assert_not_reached (); + } + + g_variant_unref (variant); + free (gsettingsTranslatedName); + + return v; +} + +void +ccsGSettingsIntegratedSettingWriteValue (CCSIntegratedSetting *setting, CCSSettingValue *v, CCSSettingType type) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + const char *gnomeKeyName = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting); + char *gsettingsTranslatedName = translateKeyForGSettings (gnomeKeyName); + + GVariant *variant = ccsGSettingsWrapperGetValue (priv->wrapper, gsettingsTranslatedName); + GVariant *newVariant = NULL; + + if (!variant) + { + ccsError ("NULL encountered while reading GSettings value"); + free (gsettingsTranslatedName); + return; + } + + switch (type) + { + case TypeInt: + { + int currentValue = readIntFromVariant (variant); + + if ((currentValue != v->value.asInt)) + writeIntToVariant (v->value.asInt, &newVariant); + } + break; + case TypeBool: + { + gboolean currentValue = readBoolFromVariant (variant); + + if ((currentValue != v->value.asBool)) + writeBoolToVariant (v->value.asBool, &newVariant); + } + break; + case TypeString: + { + const char *defaultValue = ""; + const char *newValue = v->value.asString ? v->value.asString : defaultValue; + gsize len = 0; + const gchar *currentValue = g_variant_get_string (variant, &len); + + if (currentValue) + { + if (strcmp (currentValue, newValue) != 0) + writeStringToVariant (currentValue, &newVariant); + } + } + break; + case TypeKey: + { + const char *defaultValue = ""; + GVariantBuilder strvBuilder; + + g_variant_builder_init (&strvBuilder, G_VARIANT_TYPE ("as")); + g_variant_builder_add (&strvBuilder, "s", v->value.asString ? v->value.asString : defaultValue); + newVariant = g_variant_builder_end (&strvBuilder); + } + break; + default: + g_assert_not_reached (); + break; + } + + /* g_settings_set_value consumes the reference */ + if (newVariant) + ccsGSettingsWrapperSetValue (priv->wrapper, gsettingsTranslatedName, newVariant); + else + ccsGSettingsWrapperResetKey (priv->wrapper, gsettingsTranslatedName); + + g_variant_unref (variant); + free (gsettingsTranslatedName); +} + +const char * +ccsGSettingsIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *setting) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + return ccsIntegratedSettingInfoPluginName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSetting); +} + +const char * +ccsGSettingsIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *setting) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + return ccsIntegratedSettingInfoSettingName ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSetting); +} + +CCSSettingType +ccsGSettingsIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *setting) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + return ccsIntegratedSettingInfoGetType ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSetting); +} + +void +ccsGSettingsIntegratedSettingFree (CCSIntegratedSetting *setting) +{ + CCSGSettingsIntegratedSettingPrivate *priv = (CCSGSettingsIntegratedSettingPrivate *) ccsObjectGetPrivate (setting); + + if (priv->wrapper) + ccsGSettingsWrapperUnref (priv->wrapper); + + ccsIntegratedSettingInfoUnref ((CCSIntegratedSettingInfo *) priv->gnomeIntegratedSetting); + ccsObjectFinalize (setting); + + (*setting->object.object_allocation->free_) (setting->object.object_allocation->allocator, setting); +} + +void +ccsGSettingsIntegratedSettingInfoFree (CCSIntegratedSettingInfo *info) +{ + return ccsGSettingsIntegratedSettingFree ((CCSIntegratedSetting *) info); +} + +const CCSGNOMEIntegratedSettingInfoInterface ccsGSettingsGNOMEIntegratedSettingInterface = +{ + ccsGSettingsIntegratedSettingGetSpecialOptionType, + ccsGSettingsIntegratedSettingGetGNOMEName +}; + +const CCSIntegratedSettingInterface ccsGSettingsIntegratedSettingInterface = +{ + ccsGSettingsIntegratedSettingReadValue, + ccsGSettingsIntegratedSettingWriteValue, + ccsGSettingsIntegratedSettingFree +}; + +const CCSIntegratedSettingInfoInterface ccsGSettingsIntegratedSettingInfoInterface = +{ + ccsGSettingsIntegratedSettingInfoPluginName, + ccsGSettingsIntegratedSettingInfoSettingName, + ccsGSettingsIntegratedSettingInfoGetType, + ccsGSettingsIntegratedSettingInfoFree +}; + +CCSIntegratedSetting * +ccsGSettingsIntegratedSettingNew (CCSGNOMEIntegratedSettingInfo *base, + CCSGSettingsWrapper *wrapper, + CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSetting *setting = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSetting)); + + if (!setting) + return NULL; + + CCSGSettingsIntegratedSettingPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsIntegratedSettingPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, priv); + return NULL; + } + + priv->gnomeIntegratedSetting = base; + priv->wrapper = wrapper; + + ccsGSettingsWrapperRef (priv->wrapper); + + ccsObjectInit (setting, ai); + ccsObjectSetPrivate (setting, (CCSPrivate *) priv); + ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGSettingsIntegratedSettingInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInterface)); + ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGSettingsIntegratedSettingInfoInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInfoInterface)); + ccsObjectAddInterface (setting, (const CCSInterface *) &ccsGSettingsGNOMEIntegratedSettingInterface, GET_INTERFACE_TYPE (CCSGNOMEIntegratedSettingInfoInterface)); + ccsIntegratedSettingRef (setting); + + return setting; +} diff --git a/compizconfig/integration/gnome/gsettings/src/ccs_gnome_integration_gsettings_integrated_setting_factory.c b/compizconfig/integration/gnome/gsettings/src/ccs_gnome_integration_gsettings_integrated_setting_factory.c new file mode 100644 index 0000000000000000000000000000000000000000..d5483ad7dc9408aaff0aa119ab599b4db31e14d7 --- /dev/null +++ b/compizconfig/integration/gnome/gsettings/src/ccs_gnome_integration_gsettings_integrated_setting_factory.c @@ -0,0 +1,287 @@ +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +#include "ccs_gnome_integration.h" +#include "ccs_gnome_integrated_setting.h" +#include "ccs_gnome_integration_constants.h" +#include "ccs_gnome_integration_types.h" +#include "ccs_gnome_integration_gsettings_integrated_setting.h" +#include "ccs_gnome_integration_gsettings_integrated_setting_factory.h" + +INTERFACE_TYPE (CCSGNOMEIntegrationGSettingsWrapperFactoryInterface); + +CCSGSettingsWrapper * +ccsGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapper (CCSGNOMEIntegrationGSettingsWrapperFactory *factory, + const gchar *schemaName, + CCSGNOMEIntegrationGSettingsChangedCallback callback, + CCSGNOMEValueChangeData *data, + CCSObjectAllocationInterface *ai) +{ + return (*(GET_INTERFACE (CCSGNOMEIntegrationGSettingsWrapperFactoryInterface, factory))->newGSettingsWrapper) (factory, schemaName, callback, data, ai); +} + +/* CCSGNOMEIntegrationGSettingsWrapperFactory implementation */ +typedef struct _CCSGNOMEIntegrationGSettingsWrapperFactoryPrivate CCSGNOMEIntegrationGSettingsWrapperFactoryPrivate; +struct _CCSGNOMEIntegrationGSettingsWrapperFactoryPrivate +{ +}; + +CCSGSettingsWrapper * +ccsGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapperDefault (CCSGNOMEIntegrationGSettingsWrapperFactory *factory, + const gchar *schemaName, + CCSGNOMEIntegrationGSettingsChangedCallback callback, + CCSGNOMEValueChangeData *data, + CCSObjectAllocationInterface *ai) +{ + CCSGSettingsWrapper *wrapper = ccsGSettingsWrapperNewForSchema (schemaName, ai); + ccsGSettingsWrapperConnectToChangedSignal (wrapper, (GCallback) callback, data); + + return wrapper; +} + +const CCSGNOMEIntegrationGSettingsWrapperFactoryInterface ccsGNOMEIntegrationGSettingsWrapperFactoryInterface = +{ + ccsGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapperDefault +}; + +CCSGNOMEIntegrationGSettingsWrapperFactory * +ccsGNOMEIntegrationGSettingsWrapperDefaultImplNew (CCSObjectAllocationInterface *ai) +{ + CCSGNOMEIntegrationGSettingsWrapperFactory *wrapperFactory = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGNOMEIntegrationGSettingsWrapperFactory)); + + if (!wrapperFactory) + return NULL; + + CCSGNOMEIntegrationGSettingsWrapperFactoryPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGNOMEIntegrationGSettingsWrapperFactoryPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, wrapperFactory); + return NULL; + } + + ccsObjectInit (wrapperFactory, ai); + ccsObjectAddInterface (wrapperFactory, (const CCSInterface *) &ccsGNOMEIntegrationGSettingsWrapperFactoryInterface, GET_INTERFACE_TYPE (CCSGNOMEIntegrationGSettingsWrapperFactoryInterface)); + ccsObjectSetPrivate (wrapperFactory, (CCSPrivate *) priv); + + return wrapperFactory; +} + +void +ccsGNOMEIntegrationGSettingsWrapperDefaultImpl (CCSGNOMEIntegrationGSettingsWrapperFactory *factory) +{ + ccsObjectFinalize (factory); + (*factory->object.object_allocation->free_) (factory->object.object_allocation->allocator, factory); +} + +typedef struct _CCSGSettingsIntegratedSettingFactoryPrivate CCSGSettingsIntegratedSettingFactoryPrivate; + +struct _CCSGSettingsIntegratedSettingFactoryPrivate +{ + CCSGNOMEIntegrationGSettingsWrapperFactory *wrapperFactory; + GHashTable *pluginsToSettingsGSettingsWrapperQuarksHashTable; + GHashTable *quarksToGSettingsWrappersHashTable; + GHashTable *pluginsToSettingsSpecialTypesHashTable; + GHashTable *pluginsToSettingNameGNOMENameHashTable; + CCSGNOMEValueChangeData *valueChangeData; +}; + +static void +gnomeGSettingsValueChanged (GSettings *settings, + gchar *key, + gpointer user_data) +{ + CCSGNOMEValueChangeData *data = (CCSGNOMEValueChangeData *) user_data; + char *baseName = translateKeyForCCS (key); + + /* We don't care if integration is not enabled */ + if (!ccsGetIntegrationEnabled (data->context)) + return; + + CCSIntegratedSettingList settingList = ccsIntegratedSettingsStorageFindMatchingSettingsByPredicate (data->storage, + ccsGNOMEIntegrationFindSettingsMatchingPredicate, + baseName); + + ccsIntegrationUpdateIntegratedSettings (data->integration, + data->context, + settingList); + + g_free (baseName); + +} + +static CCSIntegratedSetting * +createNewGSettingsIntegratedSetting (CCSGSettingsWrapper *wrapper, + const char *gnomeName, + const char *pluginName, + const char *settingName, + CCSSettingType type, + SpecialOptionType specialOptionType, + CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSettingInfo *sharedIntegratedSettingInfo = ccsSharedIntegratedSettingInfoNew (pluginName, settingName, type, ai); + + if (!sharedIntegratedSettingInfo) + return NULL; + + CCSGNOMEIntegratedSettingInfo *gnomeIntegratedSettingInfo = ccsGNOMEIntegratedSettingInfoNew (sharedIntegratedSettingInfo, specialOptionType, gnomeName, ai); + + if (!gnomeIntegratedSettingInfo) + { + ccsIntegratedSettingInfoUnref (sharedIntegratedSettingInfo); + return NULL; + } + + CCSIntegratedSetting *gsettingsIntegratedSetting = ccsGSettingsIntegratedSettingNew (gnomeIntegratedSettingInfo, wrapper, ai); + + if (!gsettingsIntegratedSetting) + { + ccsIntegratedSettingInfoUnref ((CCSIntegratedSettingInfo *) gnomeIntegratedSettingInfo); + return NULL; + } + + return gsettingsIntegratedSetting; +} + +static void +ccsGSettingsWrapperUnrefWrapper (gpointer wrapper) +{ + ccsGSettingsWrapperUnref ((CCSGSettingsWrapper *) wrapper); +} + +static GHashTable * +initializeGSettingsWrappers (CCSGNOMEIntegrationGSettingsWrapperFactory *factory, + CCSGNOMEValueChangeData *data) +{ + const CCSGSettingsWrapperIntegratedSchemasQuarks *quarks = ccsGNOMEGSettingsWrapperQuarks (); + GHashTable *quarksToGSettingsWrappers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, ccsGSettingsWrapperUnrefWrapper); + + g_hash_table_insert (quarksToGSettingsWrappers, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED), + ccsGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapper (factory, + g_quark_to_string (quarks->ORG_COMPIZ_INTEGRATED), + gnomeGSettingsValueChanged, + data, + factory->object.object_allocation)); + g_hash_table_insert (quarksToGSettingsWrappers, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS), + ccsGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapper (factory, + g_quark_to_string (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS), + gnomeGSettingsValueChanged, + data, + factory->object.object_allocation)); + g_hash_table_insert (quarksToGSettingsWrappers, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES), + ccsGNOMEIntegrationGSettingsWrapperFactoryNewGSettingsWrapper (factory, + g_quark_to_string (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES), + gnomeGSettingsValueChanged, + data, + factory->object.object_allocation)); + + return quarksToGSettingsWrappers; +} + +CCSIntegratedSetting * +ccsGSettingsIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType (CCSIntegratedSettingFactory *factory, + CCSIntegration *integration, + const char *pluginName, + const char *settingName, + CCSSettingType type) +{ + CCSGSettingsIntegratedSettingFactoryPrivate *priv = (CCSGSettingsIntegratedSettingFactoryPrivate *) ccsObjectGetPrivate (factory); + GHashTable *settingsGSettingsWrapperQuarksHashTable = g_hash_table_lookup (priv->pluginsToSettingsGSettingsWrapperQuarksHashTable, pluginName); + GHashTable *settingsSpecialTypesHashTable = g_hash_table_lookup (priv->pluginsToSettingsSpecialTypesHashTable, pluginName); + GHashTable *settingsSettingNameGNOMENameHashTable = g_hash_table_lookup (priv->pluginsToSettingNameGNOMENameHashTable, pluginName); + + if (!priv->quarksToGSettingsWrappersHashTable) + priv->quarksToGSettingsWrappersHashTable = initializeGSettingsWrappers (priv->wrapperFactory, priv->valueChangeData); + + if (settingsGSettingsWrapperQuarksHashTable && + settingsSpecialTypesHashTable && + settingsSettingNameGNOMENameHashTable) + { + GQuark wrapperQuark = GPOINTER_TO_INT (g_hash_table_lookup (settingsGSettingsWrapperQuarksHashTable, settingName)); + CCSGSettingsWrapper *wrapper = g_hash_table_lookup (priv->quarksToGSettingsWrappersHashTable, GINT_TO_POINTER (wrapperQuark)); + SpecialOptionType specialType = (SpecialOptionType) GPOINTER_TO_INT (g_hash_table_lookup (settingsSpecialTypesHashTable, settingName)); + const gchar *integratedName = g_hash_table_lookup (settingsSettingNameGNOMENameHashTable, settingName); + + return createNewGSettingsIntegratedSetting (wrapper, + integratedName, + pluginName, + settingName, + type, + specialType, + factory->object.object_allocation); + } + + + return NULL; +} + +void +ccsGSettingsIntegratedSettingFactoryFree (CCSIntegratedSettingFactory *factory) +{ + CCSGSettingsIntegratedSettingFactoryPrivate *priv = (CCSGSettingsIntegratedSettingFactoryPrivate *) ccsObjectGetPrivate (factory); + + if (priv->pluginsToSettingsGSettingsWrapperQuarksHashTable) + g_hash_table_unref (priv->pluginsToSettingsGSettingsWrapperQuarksHashTable); + + if (priv->quarksToGSettingsWrappersHashTable) + g_hash_table_unref (priv->quarksToGSettingsWrappersHashTable); + + if (priv->pluginsToSettingsSpecialTypesHashTable) + g_hash_table_unref (priv->pluginsToSettingsSpecialTypesHashTable); + + if (priv->pluginsToSettingNameGNOMENameHashTable) + g_hash_table_unref (priv->pluginsToSettingNameGNOMENameHashTable); + + ccsObjectFinalize (factory); + (*factory->object.object_allocation->free_) (factory->object.object_allocation->allocator, factory); +} + + +const CCSIntegratedSettingFactoryInterface ccsGSettingsIntegratedSettingFactoryInterface = +{ + ccsGSettingsIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType, + ccsGSettingsIntegratedSettingFactoryFree +}; + +CCSIntegratedSettingFactory * +ccsGSettingsIntegratedSettingFactoryNew (CCSGNOMEIntegrationGSettingsWrapperFactory *wrapperFactory, + CCSGNOMEValueChangeData *valueChangeData, + CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSettingFactory *factory = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSettingFactory)); + + if (!factory) + return NULL; + + CCSGSettingsIntegratedSettingFactoryPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGSettingsIntegratedSettingFactoryPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, factory); + return NULL; + } + + priv->wrapperFactory = wrapperFactory; + priv->pluginsToSettingsGSettingsWrapperQuarksHashTable = ccsGNOMEGSettingsIntegrationPopulateSettingNameToIntegratedSchemasQuarksHashTable (); + priv->pluginsToSettingsSpecialTypesHashTable = ccsGNOMEIntegrationPopulateSpecialTypesHashTables (); + priv->pluginsToSettingNameGNOMENameHashTable = ccsGNOMEIntegrationPopulateSettingNameToGNOMENameHashTables (); + priv->valueChangeData = valueChangeData; + + ccsObjectInit (factory, ai); + ccsObjectSetPrivate (factory, (CCSPrivate *) priv); + ccsObjectAddInterface (factory, (const CCSInterface *) &ccsGSettingsIntegratedSettingFactoryInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingFactoryInterface)); + + return factory; +} + diff --git a/compizconfig/integration/gnome/include/ccs_gnome_integrated_setting.h b/compizconfig/integration/gnome/include/ccs_gnome_integrated_setting.h new file mode 100644 index 0000000000000000000000000000000000000000..265c54505e018c27d25166c0e109ddf9abc60ebe --- /dev/null +++ b/compizconfig/integration/gnome/include/ccs_gnome_integrated_setting.h @@ -0,0 +1,58 @@ +#ifndef _CCS_GNOME_INTEGRATED_SETTING_H +#define _CCS_GNOME_INTEGRATED_SETTING_H + +#include +#include + +#include "ccs_gnome_integration_types.h" + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSIntegratedSettingInfo CCSIntegratedSettingInfo; + +typedef struct _CCSGNOMEIntegratedSettingInfo CCSGNOMEIntegratedSettingInfo; +typedef struct _CCSGNOMEIntegratedSettingInfoInterface CCSGNOMEIntegratedSettingInfoInterface; + +typedef SpecialOptionType (*CCSGNOMEIntegratedSettingInfoGetSpecialOptionType) (CCSGNOMEIntegratedSettingInfo *); +typedef const char * (*CCSGNOMEIntegratedSettingInfoGetGNOMEName) (CCSGNOMEIntegratedSettingInfo *); + +struct _CCSGNOMEIntegratedSettingInfoInterface +{ + CCSGNOMEIntegratedSettingInfoGetSpecialOptionType getSpecialOptionType; + CCSGNOMEIntegratedSettingInfoGetGNOMEName getGNOMEName; +}; + +/** + * @brief The _CCSGNOMEIntegratedSetting struct + * + * CCSGNOMEIntegratedSetting represents an integrated setting in + * GNOME - it builds upon CCSSharedIntegratedSetting (which it composes + * and implements) and also adds the concept of an GNOME side keyname + * and option type for that keyname (as the types do not match 1-1) + */ +struct _CCSGNOMEIntegratedSettingInfo +{ + CCSObject object; +}; + +unsigned int ccsCCSGNOMEIntegratedSettingInfoInterfaceGetType (); + +Bool +ccsGNOMEIntegrationFindSettingsMatchingPredicate (CCSIntegratedSetting *setting, + void *userData); + +SpecialOptionType +ccsGNOMEIntegratedSettingInfoGetSpecialOptionType (CCSGNOMEIntegratedSettingInfo *); + +const char * +ccsGNOMEIntegratedSettingInfoGetGNOMEName (CCSGNOMEIntegratedSettingInfo *); + +CCSGNOMEIntegratedSettingInfo * +ccsGNOMEIntegratedSettingInfoNew (CCSIntegratedSettingInfo *base, + SpecialOptionType type, + const char *gnomeName, + CCSObjectAllocationInterface *ai); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/integration/gnome/include/ccs_gnome_integration.h b/compizconfig/integration/gnome/include/ccs_gnome_integration.h new file mode 100644 index 0000000000000000000000000000000000000000..729e721d38a38fb75f8da63378ea35fd62d921fb --- /dev/null +++ b/compizconfig/integration/gnome/include/ccs_gnome_integration.h @@ -0,0 +1,44 @@ +#ifndef _CCS_COMPIZCONFIG_GNOME_GCONF_INTEGRATION +#define _CCS_COMPIZCONFIG_GNOME_GCONF_INTEGRATION + +#include +#include "ccs_gnome_integration_types.h" + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSGNOMEValueChangeData +{ + CCSIntegration *integration; + CCSIntegratedSettingsStorage *storage; + CCSIntegratedSettingFactory *factory; + CCSContext *context; +} CCSGNOMEValueChangeData; + +/** + * @brief ccsGNOMEIntegrationBackendNew + * @param backend + * @param context + * @param factory + * @param storage + * @param ai + * @return A new CCSIntegration + * + * The GNOME implementation of desktop environment integration - requires + * a method to create new integrated settings, and a method to store them + * as well. + * + * CCSGNOMEIntegration is a pure composition in most respects - it just + * represents the process as to which settings should be written to + * what keys and vice versa, it doesn't represent how those keys should + * be written. + */ +CCSIntegration * +ccsGNOMEIntegrationBackendNew (CCSBackend *backend, + CCSContext *context, + CCSIntegratedSettingFactory *factory, + CCSIntegratedSettingsStorage *storage, + CCSObjectAllocationInterface *ai); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/integration/gnome/include/ccs_gnome_integration_constants.h b/compizconfig/integration/gnome/include/ccs_gnome_integration_constants.h new file mode 100644 index 0000000000000000000000000000000000000000..3311452a9f3d191051fc195d8a66e4e663b6f053 --- /dev/null +++ b/compizconfig/integration/gnome/include/ccs_gnome_integration_constants.h @@ -0,0 +1,216 @@ +#ifndef _CCS_GNOME_INTEGRATION_CONSTANTS_H +#define _CCS_GNOME_INTEGRATION_CONSTANTS_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +#include + +#define METACITY "/apps/metacity" +#define NUM_WATCHED_DIRS 3 + +typedef struct _CCSSettingIntegratedSettingPair CCSSettingIntegratedSettingPair; +struct _CCSSettingIntegratedSettingPair +{ + const char *compizName; + const char *gnomeName; +}; + +typedef struct _CCSGNOMEIntegratedSettingNames CCSGNOMEIntegratedSettingNames; +struct _CCSGNOMEIntegratedSettingNames +{ + CCSSettingIntegratedSettingPair CORE_AUDIBLE_BELL; + CCSSettingIntegratedSettingPair CORE_CLICK_TO_FOCUS; + CCSSettingIntegratedSettingPair CORE_RAISE_ON_CLICK; + CCSSettingIntegratedSettingPair CORE_AUTORAISE_DELAY; + CCSSettingIntegratedSettingPair CORE_AUTORAISE; + CCSSettingIntegratedSettingPair THUMBNAIL_CURRENT_VIEWPORT; + CCSSettingIntegratedSettingPair GNOMECOMPAT_COMMAND_TERMINAL; + CCSSettingIntegratedSettingPair GNOMECOMPAT_COMMAND_WINDOW_SCREENSHOT; + CCSSettingIntegratedSettingPair GNOMECOMPAT_COMMAND_SCREENSHOT; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_RIGHT_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_LEFT_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_12_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_11_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_10_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_9_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_8_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_7_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_6_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_5_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_4_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_3_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_2_WINDOW_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_1_WINDOW_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_BOTTOM_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_TOP_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_RIGHT_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_LEFT_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_BOTTOMRIGHT_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_BOTTOMLEFT_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_TOPRIGHT_KEY; + CCSSettingIntegratedSettingPair PUT_PUT_TOPLEFT_KEY; + CCSSettingIntegratedSettingPair WALL_DOWN_WINDOW_KEY; + CCSSettingIntegratedSettingPair WALL_UP_WINDOW_KEY; + CCSSettingIntegratedSettingPair WALL_RIGHT_WINDOW_KEY; + CCSSettingIntegratedSettingPair WALL_LEFT_WINDOW_KEY; + CCSSettingIntegratedSettingPair WALL_RIGHT_KEY; + CCSSettingIntegratedSettingPair WALL_LEFT_KEY; + CCSSettingIntegratedSettingPair WALL_DOWN_KEY; + CCSSettingIntegratedSettingPair WALL_UP_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_12_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_11_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_10_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_9_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_8_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_7_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_6_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_5_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_4_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_3_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_2_KEY; + CCSSettingIntegratedSettingPair VPSWITCH_SWITCH_TO_1_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_RIGHT_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_LEFT_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_12_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_11_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_10_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_9_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_8_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_7_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_6_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_5_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_4_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_3_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_2_KEY; + CCSSettingIntegratedSettingPair ROTATE_ROTATE_TO_1_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND11_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND10_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND9_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND8_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND7_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND6_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND5_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND4_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND3_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND2_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND1_KEY; + CCSSettingIntegratedSettingPair COMMANDS_RUN_COMMAND0_KEY; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND11; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND10; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND9; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND8; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND7; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND6; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND5; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND4; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND3; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND2; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND1; + CCSSettingIntegratedSettingPair COMMANDS_COMMAND0; + CCSSettingIntegratedSettingPair EXTRAWM_TOGGLE_FULLSCREEN_KEY; + CCSSettingIntegratedSettingPair EXTRAWM_TOGGLE_STICKY_KEY; + CCSSettingIntegratedSettingPair STATICSWITCHER_PREV_KEY; + CCSSettingIntegratedSettingPair STATICSWITCHER_NEXT_KEY; + CCSSettingIntegratedSettingPair FADE_FULLSCREEN_VISUAL_BELL; + CCSSettingIntegratedSettingPair FADE_VISUAL_BELL; + CCSSettingIntegratedSettingPair NULL_RESIZE_WITH_RIGHT_BUTTON; + CCSSettingIntegratedSettingPair NULL_MOUSE_BUTTON_MODIFIER; + CCSSettingIntegratedSettingPair CORE_WINDOW_MENU_BUTTON; + CCSSettingIntegratedSettingPair RESIZE_INITIATE_BUTTON; + CCSSettingIntegratedSettingPair MOVE_INITIATE_BUTTON; + CCSSettingIntegratedSettingPair CORE_WINDOW_MENU_KEY; + CCSSettingIntegratedSettingPair RESIZE_INITIATE_KEY; + CCSSettingIntegratedSettingPair MOVE_INITIATE_KEY; + CCSSettingIntegratedSettingPair CORE_SHOW_DESKTOP_KEY; + CCSSettingIntegratedSettingPair CORE_TOGGLE_WINDOW_SHADED_KEY; + CCSSettingIntegratedSettingPair CORE_CLOSE_WINDOW_KEY; + CCSSettingIntegratedSettingPair CORE_LOWER_WINDOW_KEY; + CCSSettingIntegratedSettingPair CORE_RAISE_WINDOW_KEY; + CCSSettingIntegratedSettingPair CORE_MAXIMIZE_WINDOW_VERTICALLY_KEY; + CCSSettingIntegratedSettingPair CORE_MAXIMIZE_WINDOW_HORIZONTALLY_KEY; + CCSSettingIntegratedSettingPair CORE_UNMAXIMIZE_WINDOW_KEY; + CCSSettingIntegratedSettingPair CORE_MAXIMIZE_WINDOW_KEY; + CCSSettingIntegratedSettingPair CORE_MINIMIZE_WINDOW_KEY; + CCSSettingIntegratedSettingPair CORE_TOGGLE_WINDOW_MAXIMIZED_KEY; + CCSSettingIntegratedSettingPair GNOMECOMPAT_RUN_COMMAND_TERMINAL_KEY; + CCSSettingIntegratedSettingPair GNOMECOMPAT_RUN_COMMAND_WINDOW_SCREENSHOT_KEY; + CCSSettingIntegratedSettingPair GNOMECOMPAT_RUN_COMMAND_SCREENSHOT_KEY; + CCSSettingIntegratedSettingPair GNOMECOMPAT_MAIN_MENU_KEY; + CCSSettingIntegratedSettingPair GNOMECOMPAT_RUN_KEY; + CCSSettingIntegratedSettingPair UNITYSHELL_SHOW_HUD; +}; + +extern const CCSGNOMEIntegratedSettingNames ccsGNOMEIntegratedSettingNames; + +typedef struct _CCSGConfIntegrationCategoires CCSGConfIntegrationCategories; + +struct _CCSGConfIntegrationCategoires +{ + const char *GENERAL; + const char *APPS; + const char *DESKTOP; + const char *KEYBINDING_COMMANDS; + const char *WINDOW_KEYBINDINGS; + const char *GLOBAL_KEYBINDINGS; +}; + +extern const CCSGConfIntegrationCategories ccsGConfIntegrationCategories; + +typedef struct _CCSGNOMEIntegratedPluginNames CCSGNOMEIntegratedPluginNames; + +struct _CCSGNOMEIntegratedPluginNames +{ + const char *CORE; + const char *THUMBNAIL; + const char *GNOMECOMPAT; + const char *ROTATE; + const char *PUT; + const char *WALL; + const char *VPSWITCH; + const char *COMMANDS; + const char *EXTRAWM; + const char *RESIZE; + const char *MOVE; + const char *STATICSWITCHER; + const char *FADE; + const char *UNITYSHELL; + const char *SPECIAL; +}; + +extern const CCSGNOMEIntegratedPluginNames ccsGNOMEIntegratedPluginNames; + +extern const char* watchedGConfGnomeDirectories[]; + +typedef struct _CCSGSettingsWrapperIntegratedSchemasQuarks +{ + GQuark ORG_GNOME_DESKTOP_WM_PREFERENCES; + GQuark ORG_GNOME_DESKTOP_WM_KEYBINDINGS; + GQuark ORG_COMPIZ_INTEGRATED; +} CCSGSettingsWrapperIntegratedSchemasQuarks; + +const CCSGSettingsWrapperIntegratedSchemasQuarks *ccsGNOMEGSettingsWrapperQuarks (); + +GHashTable * ccsGNOMEIntegrationPopulateCategoriesHashTables (); +GHashTable * ccsGNOMEIntegrationPopulateSpecialTypesHashTables (); +GHashTable * ccsGNOMEIntegrationPopulateSettingNameToGNOMENameHashTables (); +GHashTable * ccsGNOMEGSettingsIntegrationPopulateSettingNameToIntegratedSchemasQuarksHashTable (); + +/* We only have to use the #define here because + * C doesn't have a concept of "constants" setting + * the array size ... + */ +#define CCS_GNOME_INTEGRATED_SETTINGS_LIST_SIZE 119 + +typedef struct _CCSGNOMEIntegratedSettingsList +{ + const char *pluginName; + const char *settingName; +} CCSGNOMEIntegratedSettingsList; + +const CCSGNOMEIntegratedSettingsList * ccsGNOMEIntegratedSettingsList (); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/integration/gnome/include/ccs_gnome_integration_types.h b/compizconfig/integration/gnome/include/ccs_gnome_integration_types.h new file mode 100644 index 0000000000000000000000000000000000000000..a68a1fd7d7f1f168edbfc4a2524893d66e643140 --- /dev/null +++ b/compizconfig/integration/gnome/include/ccs_gnome_integration_types.h @@ -0,0 +1,26 @@ +#ifndef _CCS_GNOME_INTEGRATION_TYPES_H +#define _CCS_GNOME_INTEGRATION_TYPES_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSBackend CCSBackend; +typedef struct _CCSContext CCSContext; +typedef struct _CCSObjectAllocationInterface CCSObjectAllocationInterface; +typedef struct _CCSIntegration CCSIntegration; +typedef struct _CCSIntegratedSetting CCSIntegratedSetting; +typedef struct _CCSIntegratedSettingFactory CCSIntegratedSettingFactory; +typedef struct _CCSIntegratedSettingsStorage CCSIntegratedSettingsStorage; +typedef struct _GConfClient GConfClient; + +typedef enum { + OptionInt, + OptionBool, + OptionKey, + OptionString, + OptionSpecial, +} SpecialOptionType; + +#endif + diff --git a/compizconfig/integration/gnome/include/ccs_gnome_integration_types.h~ b/compizconfig/integration/gnome/include/ccs_gnome_integration_types.h~ new file mode 100644 index 0000000000000000000000000000000000000000..a68a1fd7d7f1f168edbfc4a2524893d66e643140 --- /dev/null +++ b/compizconfig/integration/gnome/include/ccs_gnome_integration_types.h~ @@ -0,0 +1,26 @@ +#ifndef _CCS_GNOME_INTEGRATION_TYPES_H +#define _CCS_GNOME_INTEGRATION_TYPES_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSBackend CCSBackend; +typedef struct _CCSContext CCSContext; +typedef struct _CCSObjectAllocationInterface CCSObjectAllocationInterface; +typedef struct _CCSIntegration CCSIntegration; +typedef struct _CCSIntegratedSetting CCSIntegratedSetting; +typedef struct _CCSIntegratedSettingFactory CCSIntegratedSettingFactory; +typedef struct _CCSIntegratedSettingsStorage CCSIntegratedSettingsStorage; +typedef struct _GConfClient GConfClient; + +typedef enum { + OptionInt, + OptionBool, + OptionKey, + OptionString, + OptionSpecial, +} SpecialOptionType; + +#endif + diff --git a/compizconfig/integration/gnome/src/ccs_gnome_integrated_setting.c b/compizconfig/integration/gnome/src/ccs_gnome_integrated_setting.c new file mode 100644 index 0000000000000000000000000000000000000000..ea5d536ad4783ae0bc595b6502bf2ce8a75f6f33 --- /dev/null +++ b/compizconfig/integration/gnome/src/ccs_gnome_integrated_setting.c @@ -0,0 +1,146 @@ +#include +#include + +#include + +#include +#include +#include + +#include "ccs_gnome_integrated_setting.h" +#include "ccs_gnome_integration_constants.h" + +INTERFACE_TYPE (CCSGNOMEIntegratedSettingInfoInterface); + +SpecialOptionType +ccsGNOMEIntegratedSettingInfoGetSpecialOptionType (CCSGNOMEIntegratedSettingInfo *info) +{ + return (*(GET_INTERFACE (CCSGNOMEIntegratedSettingInfoInterface, info))->getSpecialOptionType) (info); +} + +const char * +ccsGNOMEIntegratedSettingInfoGetGNOMEName (CCSGNOMEIntegratedSettingInfo *info) +{ + return (*(GET_INTERFACE (CCSGNOMEIntegratedSettingInfoInterface, info))->getGNOMEName) (info); +} + +/* CCSGNOMEIntegratedSettingDefaultImpl implementation */ + +typedef struct _CCSGNOMEIntegratedSettingInfoDefaultImplPrivate CCSGNOMEIntegratedSettingInfoDefaultImplPrivate; + +struct _CCSGNOMEIntegratedSettingInfoDefaultImplPrivate +{ + SpecialOptionType type; + const char *gnomeName; + CCSIntegratedSettingInfo *sharedIntegratedSettingInfo; +}; + +Bool +ccsGNOMEIntegrationFindSettingsMatchingPredicate (CCSIntegratedSetting *setting, + void *userData) +{ + const char *findGnomeName = (const char *) userData; + const char *gnomeNameOfSetting = ccsGNOMEIntegratedSettingInfoGetGNOMEName ((CCSGNOMEIntegratedSettingInfo *) setting); + + if (strcmp (findGnomeName, gnomeNameOfSetting) == 0) + return TRUE; + + return FALSE; +} + +SpecialOptionType +ccsGNOMEIntegratedSettingGetSpecialOptionDefault (CCSGNOMEIntegratedSettingInfo *info) +{ + CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *priv = (CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *) ccsObjectGetPrivate (info); + + return priv->type; +} + +const char * +ccsGNOMEIntegratedSettingGetGNOMENameDefault (CCSGNOMEIntegratedSettingInfo *info) +{ + CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *priv = (CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *) ccsObjectGetPrivate (info); + + return priv->gnomeName; +} + +const char * +ccsGNOMEIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *info) +{ + CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *priv = (CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *) ccsObjectGetPrivate (info); + + return ccsIntegratedSettingInfoPluginName (priv->sharedIntegratedSettingInfo); +} + +const char * +ccsGNOMEIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *info) +{ + CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *priv = (CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *) ccsObjectGetPrivate (info); + + return ccsIntegratedSettingInfoSettingName (priv->sharedIntegratedSettingInfo); +} + +CCSSettingType +ccsGNOMEIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *info) +{ + CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *priv = (CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *) ccsObjectGetPrivate (info); + + return ccsIntegratedSettingInfoGetType (priv->sharedIntegratedSettingInfo); +} + +void +ccsGNOMEIntegratedSettingInfoFree (CCSIntegratedSettingInfo *info) +{ + CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *priv = (CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *) ccsObjectGetPrivate (info); + + ccsIntegratedSettingInfoUnref (priv->sharedIntegratedSettingInfo); + ccsObjectFinalize (info); + + (*info->object.object_allocation->free_) (info->object.object_allocation->allocator, info); +} + +CCSGNOMEIntegratedSettingInfoInterface ccsGNOMEIntegratedSettingInfoDefaultImplInterface = +{ + ccsGNOMEIntegratedSettingGetSpecialOptionDefault, + ccsGNOMEIntegratedSettingGetGNOMENameDefault +}; + +const CCSIntegratedSettingInfoInterface ccsGNOMEIntegratedSettingInfoInterface = +{ + ccsGNOMEIntegratedSettingInfoPluginName, + ccsGNOMEIntegratedSettingInfoSettingName, + ccsGNOMEIntegratedSettingInfoGetType, + ccsGNOMEIntegratedSettingInfoFree +}; + +CCSGNOMEIntegratedSettingInfo * +ccsGNOMEIntegratedSettingInfoNew (CCSIntegratedSettingInfo *base, + SpecialOptionType type, + const char *gnomeName, + CCSObjectAllocationInterface *ai) +{ + CCSGNOMEIntegratedSettingInfo *info = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGNOMEIntegratedSettingInfo)); + + if (!info) + return NULL; + + CCSGNOMEIntegratedSettingInfoDefaultImplPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSGNOMEIntegratedSettingInfoDefaultImplPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, info); + return NULL; + } + + priv->sharedIntegratedSettingInfo = base; + priv->gnomeName = gnomeName; + priv->type = type; + + ccsObjectInit (info, ai); + ccsObjectSetPrivate (info, (CCSPrivate *) priv); + ccsObjectAddInterface (info, (const CCSInterface *) &ccsGNOMEIntegratedSettingInfoInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInfoInterface)); + ccsObjectAddInterface (info, (const CCSInterface *) &ccsGNOMEIntegratedSettingInfoDefaultImplInterface, GET_INTERFACE_TYPE (CCSGNOMEIntegratedSettingInfoInterface)); + ccsIntegratedSettingInfoRef ((CCSIntegratedSettingInfo *) info); + + return info; +} diff --git a/compizconfig/integration/gnome/src/ccs_gnome_integration.c b/compizconfig/integration/gnome/src/ccs_gnome_integration.c new file mode 100644 index 0000000000000000000000000000000000000000..313e65aec7e1a1d5b37ec957be36fef6a0eb5f58 --- /dev/null +++ b/compizconfig/integration/gnome/src/ccs_gnome_integration.c @@ -0,0 +1,690 @@ +/** + * + * compizconfig gnome integration backend + * + * gnome-integration.c + * + * Copyright (c) 2011 Canonical Ltd + * + * Based on the original compizconfig-backend-gconf + * + * Copyright (c) 2007 Danny Baumann + * + * Parts of this code are taken from libberylsettings + * gconf backend, written by: + * + * Copyright (c) 2006 Robert Carr + * Copyright (c) 2007 Dennis Kasprzyk + * + * 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. + * + * Authored By: + * Sam Spilsbury + * + **/ +#include +#include +#include +#include +#include +#include +#include "ccs_gnome_integration.h" +#include "ccs_gnome_integration_constants.h" +#include "ccs_gnome_integrated_setting.h" + +typedef struct _CCSGNOMEIntegrationBackendPrivate CCGNOMEIntegrationBackendPrivate; + +struct _CCSGNOMEIntegrationBackendPrivate +{ + CCSBackend *backend; + CCSContext *context; + CCSIntegratedSettingFactory *factory; + CCSIntegratedSettingsStorage *storage; + Bool noWrites; +}; + +static CCSSetting * +findDisplaySettingForPlugin (CCSContext *context, + const char *plugin, + const char *setting) +{ + CCSPlugin *p; + CCSSetting *s; + + p = ccsFindPlugin (context, plugin); + if (!p) + return NULL; + + s = ccsFindSetting (p, setting); + if (!s) + return NULL; + + return s; +} + +static void +unregisterAllIntegratedOptions (CCSIntegration *integration) +{ + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + + if (priv->storage) + ccsIntegratedSettingsStorageUnref (priv->storage); + + if (priv->factory) + ccsIntegratedSettingFactoryUnref (priv->factory); + + priv->storage = NULL; + priv->factory = NULL; +} + +static void +registerAllIntegratedOptions (CCSIntegration *integration) +{ + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + + unsigned int i = 0; + const CCSGNOMEIntegratedSettingsList *array = ccsGNOMEIntegratedSettingsList (); + + for (; i < CCS_GNOME_INTEGRATED_SETTINGS_LIST_SIZE; i++) + { + CCSIntegratedSetting *setting = ccsIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType (priv->factory, + integration, + array[i].pluginName, + array[i].settingName, + TypeInt); + + ccsIntegratedSettingsStorageAddSetting (priv->storage, setting); + } +} + +static CCSIntegratedSetting * +ccsGNOMEIntegrationBackendGetIntegratedSetting (CCSIntegration *integration, + const char *pluginName, + const char *settingName) +{ + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + + if (ccsIntegratedSettingsStorageEmpty (priv->storage)) + registerAllIntegratedOptions (integration); + + CCSIntegratedSettingList integratedSettings = ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName (priv->storage, + pluginName, + settingName); + + if (integratedSettings) + return integratedSettings->data; + + return NULL; +} + +static unsigned int +getGnomeMouseButtonModifier (CCSIntegratedSetting *mouseButtonModifierSetting) +{ + unsigned int modMask = 0; + CCSSettingType type = TypeString; + CCSSettingValue *v = ccsIntegratedSettingReadValue (mouseButtonModifierSetting, type); + + modMask = ccsStringToModifiers (v->value.asString); + + ccsFreeSettingValueWithType (v, type); + + return modMask; +} + +static unsigned int +getButtonBindingForSetting (CCSContext *context, + const char *plugin, + const char *setting) +{ + CCSSetting *s; + + s = findDisplaySettingForPlugin (context, plugin, setting); + if (!s) + return 0; + + if (ccsSettingGetType (s) != TypeButton) + return 0; + + return ccsSettingGetValue (s)->value.asButton.button; +} + +static Bool +ccsGNOMEIntegrationBackendReadOptionIntoSetting (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting) +{ + Bool ret = FALSE; + CCSSettingValue *v = NULL; + CCSSettingType type = TypeNum; + + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + + if (ccsIntegratedSettingsStorageEmpty (priv->storage)) + registerAllIntegratedOptions (integration); + + ret = ccsSettingIsReadableByBackend (setting); + + if (!ret) + return FALSE; + + switch (ccsGNOMEIntegratedSettingInfoGetSpecialOptionType ((CCSGNOMEIntegratedSettingInfo *) integratedSetting)) { + case OptionInt: + { + type = TypeInt; + v = ccsIntegratedSettingReadValue (integratedSetting, type); + ccsSetInt (setting, v->value.asInt, TRUE); + ret = TRUE; + } + break; + case OptionBool: + { + type = TypeBool; + v = ccsIntegratedSettingReadValue (integratedSetting, type); + ccsSetBool (setting, v->value.asBool, TRUE); + ret = TRUE; + } + break; + case OptionString: + { + type = TypeString; + v = ccsIntegratedSettingReadValue (integratedSetting, type); + char *str = v->value.asString; + + ccsSetString (setting, str, TRUE); + ret = TRUE; + } + break; + case OptionKey: + { + type = TypeKey; + v = ccsIntegratedSettingReadValue (integratedSetting, type); + + if (v->value.asString) + { + CCSSettingKeyValue key; + + memset (&key, 0, sizeof (CCSSettingKeyValue)); + ccsGetKey (setting, &key); + if (ccsStringToKeyBinding (v->value.asString, &key)) + { + ccsSetKey (setting, key, TRUE); + ret = TRUE; + } + } + } + break; + case OptionSpecial: + { + const char *settingName = ccsSettingGetName (setting); + const char *pluginName = ccsPluginGetName (ccsSettingGetParent (setting)); + + if (strcmp (settingName, "current_viewport") == 0) + { + type = TypeBool; + v = ccsIntegratedSettingReadValue (integratedSetting, type); + + Bool showAll = v->value.asBool; + ccsSetBool (setting, !showAll, TRUE); + ret = TRUE; + } + else if (strcmp (settingName, "fullscreen_visual_bell") == 0) + { + type = TypeString; + v = ccsIntegratedSettingReadValue (integratedSetting, type); + + const char *value = v->value.asString; + if (value) + { + Bool fullscreen; + + fullscreen = strcmp (value, "fullscreen") == 0; + ccsSetBool (setting, fullscreen, TRUE); + ret = TRUE; + } + } + else if (strcmp (settingName, "click_to_focus") == 0) + { + type = TypeString; + v = ccsIntegratedSettingReadValue (integratedSetting, type); + + const char *focusMode = v->value.asString; + + if (focusMode) + { + Bool clickToFocus = (strcmp (focusMode, "click") == 0); + ccsSetBool (setting, clickToFocus, TRUE); + ret = TRUE; + } + } + else if (((strcmp (settingName, "initiate_button") == 0) && + ((strcmp (pluginName, "move") == 0) || + (strcmp (pluginName, "resize") == 0))) || + ((strcmp (settingName, "window_menu_button") == 0) && + (strcmp (pluginName, "core") == 0))) + { + gboolean resizeWithRightButton; + CCSSettingButtonValue button; + + memset (&button, 0, sizeof (CCSSettingButtonValue)); + ccsGetButton (setting, &button); + + CCSIntegratedSettingList integratedSettingsMBM = ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName (priv->storage, + ccsGNOMEIntegratedPluginNames.SPECIAL, + ccsGNOMEIntegratedSettingNames.NULL_MOUSE_BUTTON_MODIFIER.compizName); + + button.buttonModMask = getGnomeMouseButtonModifier (integratedSettingsMBM->data); + + CCSIntegratedSettingList integratedSettings = ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName (priv->storage, + ccsGNOMEIntegratedPluginNames.SPECIAL, + ccsGNOMEIntegratedSettingNames.NULL_RESIZE_WITH_RIGHT_BUTTON.compizName); + + type = TypeBool; + v = ccsIntegratedSettingReadValue (integratedSettings->data, type); + + resizeWithRightButton = + v->value.asBool; + + if (strcmp (settingName, "window_menu_button") == 0) + button.button = resizeWithRightButton ? 2 : 3; + else if (strcmp (pluginName, "resize") == 0) + button.button = resizeWithRightButton ? 3 : 2; + else + button.button = 1; + + ccsSetButton (setting, button, TRUE); + ret = TRUE; + } + + } + break; + default: + break; + } + + if (v) + ccsFreeSettingValueWithType (v, type); + + return ret; +} + +static Bool +setGnomeMouseButtonModifier (CCSIntegratedSetting *setting, + unsigned int modMask) +{ + char *modifiers; + CCSSettingValue *v = calloc (1, sizeof (CCSSettingValue)); + + v->isListChild = FALSE; + v->parent = NULL; + v->refCount = 1; + + modifiers = ccsModifiersToString (modMask); + if (!modifiers) + { + ccsFreeSettingValueWithType (v, TypeString); + return FALSE; + } + + v->value.asString = modifiers; + ccsIntegratedSettingWriteValue (setting, v, TypeString); + + ccsFreeSettingValueWithType (v, TypeString); + + return TRUE; +} + +static void +setButtonBindingForSetting (CCSContext *context, + const char *plugin, + const char *setting, + unsigned int button, + unsigned int buttonModMask) +{ + CCSSetting *s; + CCSSettingButtonValue value; + + s = findDisplaySettingForPlugin (context, plugin, setting); + if (!s) + return; + + if (ccsSettingGetType (s) != TypeButton) + return; + + value = ccsSettingGetValue (s)->value.asButton; + + if ((value.button != button) || (value.buttonModMask != buttonModMask)) + { + value.button = button; + value.buttonModMask = buttonModMask; + + ccsSetButton (s, value, TRUE); + } +} + +static void +ccsGNOMEIntegrationBackendWriteOptionFromSetting (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting) +{ + GError *err = NULL; + CCSSettingType type = TypeNum; + + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + + if (ccsIntegratedSettingsStorageEmpty (priv->storage)) + registerAllIntegratedOptions (integration); + + if (priv->noWrites) + return; + + /* Do not allow recursing back into writeIntegratedSetting */ + ccsIntegrationDisallowIntegratedWrites (integration); + + CCSSettingValue *v = ccsSettingGetValue (setting); + + switch (ccsGNOMEIntegratedSettingInfoGetSpecialOptionType ((CCSGNOMEIntegratedSettingInfo *) integratedSetting)) + { + case OptionInt: + ccsIntegratedSettingWriteValue (integratedSetting, v, TypeInt); + break; + case OptionBool: + ccsIntegratedSettingWriteValue (integratedSetting, v, TypeBool); + break; + case OptionString: + ccsIntegratedSettingWriteValue (integratedSetting, v, TypeString); + break; + case OptionKey: + { + char *newValue; + + newValue = ccsKeyBindingToString (&(ccsSettingGetValue (setting)->value.asKey)); + if (newValue) + { + if (strcmp (newValue, "Disabled") == 0) + { + /* Metacity doesn't like "Disabled", it wants "disabled" */ + newValue[0] = 'd'; + } + + /* Really this is a lie - the writer expects a string + * but it needs to know if its a key or a string */ + type = TypeKey; + v->value.asString = newValue; + + ccsIntegratedSettingWriteValue (integratedSetting, v, type); + free (newValue); + } + } + break; + case OptionSpecial: + { + const char *settingName = ccsSettingGetName (setting); + const char *pluginName = ccsPluginGetName (ccsSettingGetParent (setting)); + CCSSettingValue *newValue = calloc (1, sizeof (CCSSettingValue)); + + newValue->isListChild = FALSE; + newValue->parent = NULL; + newValue->refCount = 1; + + if (strcmp (settingName, "current_viewport") == 0) + { + newValue->value.asBool = !v->value.asBool; + type = TypeBool; + + ccsIntegratedSettingWriteValue (integratedSetting, newValue, type); + } + else if (strcmp (settingName, "fullscreen_visual_bell") == 0) + { + const char *newValueString = v->value.asString ? "fullscreen" : "frame_flash"; + newValue->value.asString = strdup (newValueString); + type = TypeString; + + ccsIntegratedSettingWriteValue (integratedSetting, newValue, type); + } + else if (strcmp (settingName, "click_to_focus") == 0) + { + const char *newValueString = v->value.asString ? "click" : "sloppy"; + newValue->value.asString = strdup (newValueString); + type = TypeString; + + ccsIntegratedSettingWriteValue (integratedSetting, newValue, type); + } + else if (((strcmp (settingName, "initiate_button") == 0) && + ((strcmp (pluginName, "move") == 0) || + (strcmp (pluginName, "resize") == 0))) || + ((strcmp (settingName, "window_menu_button") == 0) && + (strcmp (pluginName, "core") == 0))) + { + unsigned int modMask; + Bool resizeWithRightButton = FALSE; + + if ((getButtonBindingForSetting (context, "resize", + "initiate_button") == 3) || + (getButtonBindingForSetting (context, "core", + "window_menu_button") == 2)) + { + resizeWithRightButton = TRUE; + } + + CCSIntegratedSettingList integratedSettings = ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName (priv->storage, + ccsGNOMEIntegratedPluginNames.SPECIAL, + ccsGNOMEIntegratedSettingNames.NULL_RESIZE_WITH_RIGHT_BUTTON.compizName); + + newValue->value.asBool = resizeWithRightButton; + type = TypeBool; + + ccsIntegratedSettingWriteValue (integratedSettings->data, newValue, type); + + CCSIntegratedSettingList integratedSettingsMBM = ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName (priv->storage, + ccsGNOMEIntegratedPluginNames.SPECIAL, + ccsGNOMEIntegratedSettingNames.NULL_MOUSE_BUTTON_MODIFIER.compizName); + + modMask = ccsSettingGetValue (setting)->value.asButton.buttonModMask; + if (setGnomeMouseButtonModifier (integratedSettingsMBM->data, modMask)) + { + setButtonBindingForSetting (context, "move", + "initiate_button", 1, modMask); + setButtonBindingForSetting (context, "resize", + "initiate_button", + resizeWithRightButton ? 3 : 2, + modMask); + setButtonBindingForSetting (context, "core", + "window_menu_button", + resizeWithRightButton ? 2 : 3, + modMask); + } + } + + if (newValue) + ccsFreeSettingValueWithType (newValue, type); + } + break; + } + + if (err) + { + ccsError ("%s", err->message); + g_error_free (err); + } + + /* we should immediately write changed settings */ + ccsWriteChangedSettings (priv->context); + ccsIntegrationAllowIntegratedWrites (integration); +} + +static void +ccsGNOMEIntegrationBackendUpdateIntegratedSettings (CCSIntegration *integration, + CCSContext *context, + CCSIntegratedSettingList integratedSettings) +{ + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + Bool needInit = TRUE; + + CCSIntegratedSettingList iter = integratedSettings; + + while (iter) + { + CCSIntegratedSetting *integrated = iter->data; + const char *settingName = ccsIntegratedSettingInfoSettingName ((CCSIntegratedSettingInfo *)integrated); + const char *pluginName = ccsIntegratedSettingInfoPluginName ((CCSIntegratedSettingInfo *) integrated); + + /* Special case for mouse button modifier etc */ + if ((strcmp (settingName, + "mouse_button_modifier") == 0) || + (strcmp (settingName, + "resize_with_right_button") == 0)) + { + CCSSetting *s; + + if (needInit) + { + ccsBackendReadInit (priv->backend, priv->context); + needInit = FALSE; + } + + s = findDisplaySettingForPlugin (priv->context, "core", + "window_menu_button"); + if (s) + ccsBackendReadSetting (priv->backend, priv->context, s); + + s = findDisplaySettingForPlugin (priv->context, "move", + "initiate_button"); + if (s) + ccsBackendReadSetting (priv->backend, priv->context, s); + + s = findDisplaySettingForPlugin (priv->context, "resize", + "initiate_button"); + if (s) + ccsBackendReadSetting (priv->backend, priv->context, s); + } + else + { + CCSPlugin *plugin = NULL; + CCSSetting *setting; + + plugin = ccsFindPlugin (priv->context, pluginName); + if (plugin) + { + setting = ccsFindSetting (plugin, settingName); + + if (setting) + { + if (needInit) + { + ccsBackendReadInit (priv->backend, priv->context); + needInit = FALSE; + } + + ccsBackendReadSetting (priv->backend, priv->context, setting); + } + } + } + + iter = iter->next; + } +} + +static void +ccsGNOMEIntegrationDisallowIntegratedWrites (CCSIntegration *integration) +{ + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + priv->noWrites = TRUE; +} + +static void +ccsGNOMEIntegrationAllowIntegratedWrites (CCSIntegration *integration) +{ + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + priv->noWrites = FALSE; +} + +static void +ccsGNOMEIntegrationBackendFree (CCSIntegration *integration) +{ + CCGNOMEIntegrationBackendPrivate *priv = (CCGNOMEIntegrationBackendPrivate *) ccsObjectGetPrivate (integration); + + unregisterAllIntegratedOptions (integration); + + priv->backend = NULL; + + ccsObjectFinalize (integration); + free (integration); +} + +const CCSIntegrationInterface ccsGNOMEIntegrationBackendInterface = +{ + ccsGNOMEIntegrationBackendGetIntegratedSetting, + ccsGNOMEIntegrationBackendReadOptionIntoSetting, + ccsGNOMEIntegrationBackendWriteOptionFromSetting, + ccsGNOMEIntegrationBackendUpdateIntegratedSettings, + ccsGNOMEIntegrationDisallowIntegratedWrites, + ccsGNOMEIntegrationAllowIntegratedWrites, + ccsGNOMEIntegrationBackendFree +}; + +static CCGNOMEIntegrationBackendPrivate * +addPrivate (CCSIntegration *backend, + CCSObjectAllocationInterface *ai) +{ + CCGNOMEIntegrationBackendPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCGNOMEIntegrationBackendPrivate)); + + if (!priv) + { + ccsObjectFinalize (backend); + free (backend); + } + + ccsObjectSetPrivate (backend, (CCSPrivate *) priv); + + return priv; +} + +static CCSIntegration * +ccsGNOMEIntegrationBackendNewCommon (CCSBackend *backend, + CCSContext *context, + CCSIntegratedSettingFactory *factory, + CCSIntegratedSettingsStorage *storage, + CCSObjectAllocationInterface *ai) +{ + CCSIntegration *integration = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegration)); + + if (!integration) + return NULL; + + ccsObjectInit (integration, ai); + + CCGNOMEIntegrationBackendPrivate *priv = addPrivate (integration, ai); + priv->backend = backend; + priv->context = context; + priv->factory = factory; + priv->storage = storage; + priv->noWrites = FALSE; + + ccsObjectAddInterface (integration, + (const CCSInterface *) &ccsGNOMEIntegrationBackendInterface, + GET_INTERFACE_TYPE (CCSIntegrationInterface)); + + ccsIntegrationRef (integration); + + return integration; +} + +CCSIntegration * +ccsGNOMEIntegrationBackendNew (CCSBackend *backend, + CCSContext *context, + CCSIntegratedSettingFactory *factory, + CCSIntegratedSettingsStorage *storage, + CCSObjectAllocationInterface *ai) +{ + return ccsGNOMEIntegrationBackendNewCommon (backend, context, factory, storage, ai); +} diff --git a/compizconfig/integration/gnome/src/ccs_gnome_integration_constants.c b/compizconfig/integration/gnome/src/ccs_gnome_integration_constants.c new file mode 100644 index 0000000000000000000000000000000000000000..9a9c5f950a02452b549d3118e330ae31166aec07 --- /dev/null +++ b/compizconfig/integration/gnome/src/ccs_gnome_integration_constants.c @@ -0,0 +1,1111 @@ +#include +#include "ccs_gnome_integration_constants.h" + +const char * watchedGConfGnomeDirectories[] = { + METACITY, + "/desktop/gnome/applications/terminal", + "/apps/panel/applets/window_list/prefs" +}; + +const CCSGNOMEIntegratedSettingNames ccsGNOMEIntegratedSettingNames = +{ + { "audible_bell", "audible_bell" }, + { "click_to_focus", "focus_mode" }, + { "raise_on_click", "raise_on_click" }, + { "autoraise_delay", "auto_raise_delay" }, + { "autoraise", "auto_raise" }, + { "current_viewport", "display_all_workspaces" }, + { "command_terminal", "exec" }, + { "command_window_screenshot", "command_window_screenshot" }, + { "command_screenshot", "command_screenshot" }, + { "rotate_right_window_key", "move_to_workspace_right" }, + { "rotate_left_window_key", "move_to_workspace_left" }, + { "rotate_to_12_window_key", "move_to_workspace_12" }, + { "rotate_to_11_window_key", "move_to_workspace_11" }, + { "rotate_to_10_window_key", "move_to_workspace_10" }, + { "rotate_to_9_window_key", "move_to_workspace_9" }, + { "rotate_to_8_window_key", "move_to_workspace_8" }, + { "rotate_to_7_window_key", "move_to_workspace_7" }, + { "rotate_to_6_window_key", "move_to_workspace_6" }, + { "rotate_to_5_window_key", "move_to_workspace_5" }, + { "rotate_to_4_window_key", "move_to_workspace_4" }, + { "rotate_to_3_window_key", "move_to_workspace_3" }, + { "rotate_to_2_window_key", "move_to_workspace_2" }, + { "rotate_to_1_window_key", "move_to_workspace_1" }, + { "put_bottom_key", "move_to_side_s" }, + { "put_top_key", "move_to_side_n" }, + { "put_right_key", "move_to_side_e" }, + { "put_left_key", "move_to_side_w" }, + { "put_bottomright_key", "move_to_corner_se" }, + { "put_bottomleft_key", "move_to_corner_sw" }, + { "put_topright_key", "move_to_corner_ne" }, + { "put_topleft_key", "move_to_corner_nw" }, + { "down_window_key", "move_to_workspace_down" }, + { "up_window_key", "move_to_workspace_up" }, + { "right_window_key", "move_to_workspace_right" }, + { "left_window_key", "move_to_workspace_left" }, + { "right_key", "switch_to_workspace_right" }, + { "left_key", "switch_to_workspace_left" }, + { "down_key", "switch_to_workspace_down" }, + { "up_key", "switch_to_workspace_up" }, + { "switch_to_12_key", "switch_to_workspace_12" }, + { "switch_to_11_key", "switch_to_workspace_11" }, + { "switch_to_10_key", "switch_to_workspace_10" }, + { "switch_to_9_key", "switch_to_workspace_9" }, + { "switch_to_8_key", "switch_to_workspace_8" }, + { "switch_to_7_key", "switch_to_workspace_7" }, + { "switch_to_6_key", "switch_to_workspace_6" }, + { "switch_to_5_key", "switch_to_workspace_5" }, + { "switch_to_4_key", "switch_to_workspace_4" }, + { "switch_to_3_key", "switch_to_workspace_3" }, + { "switch_to_2_key", "switch_to_workspace_2" }, + { "switch_to_1_key", "switch_to_workspace_1" }, + { "rotate_right_key", "switch_to_workspace_right" }, + { "rotate_left_key", "switch_to_workspace_left" }, + { "rotate_to_12_key", "switch_to_workspace_12" }, + { "rotate_to_11_key", "switch_to_workspace_11" }, + { "rotate_to_10_key", "switch_to_workspace_10" }, + { "rotate_to_9_key", "switch_to_workspace_9" }, + { "rotate_to_8_key", "switch_to_workspace_8" }, + { "rotate_to_7_key", "switch_to_workspace_7" }, + { "rotate_to_6_key", "switch_to_workspace_6" }, + { "rotate_to_5_key", "switch_to_workspace_5" }, + { "rotate_to_4_key", "switch_to_workspace_4" }, + { "rotate_to_3_key", "switch_to_workspace_3" }, + { "rotate_to_2_key", "switch_to_workspace_2" }, + { "rotate_to_1_key", "switch_to_workspace_1" }, + { "run_command11_key", "run_command_12" }, + { "run_command10_key", "run_command_11" }, + { "run_command9_key", "run_command_10" }, + { "run_command8_key", "run_command_9" }, + { "run_command7_key", "run_command_8" }, + { "run_command6_key", "run_command_7" }, + { "run_command5_key", "run_command_6" }, + { "run_command4_key", "run_command_5" }, + { "run_command3_key", "run_command_4" }, + { "run_command2_key", "run_command_3" }, + { "run_command1_key", "run_command_2" }, + { "run_command0_key", "run_command_1" }, + { "command11", "command_12" }, + { "command10", "command_11" }, + { "command9", "command_10" }, + { "command8", "command_9" }, + { "command7", "command_8" }, + { "command6", "command_7" }, + { "command5", "command_6" }, + { "command4", "command_5" }, + { "command3", "command_4" }, + { "command2", "command_3" }, + { "command1", "command_2" }, + { "command0", "command_1" }, + { "toggle_fullscreen_key", "toggle_fullscreen" }, + { "toggle_sticky_key", "toggle_on_all_workspaces" }, + { "prev_key", "switch_windows_backward" }, + { "next_key", "switch_windows" }, + { "fullscreen_visual_bell", "visual_bell_type" }, + { "visual_bell", "visual_bell" }, + { "resize_with_right_button", "resize_with_right_button" }, + { "mouse_button_modifier", "mouse_button_modifier" }, + { "window_menu_button", "activate_window_menu" }, + { "initiate_button", "begin_resize" }, + { "initiate_button", "begin_move" }, + { "window_menu_key", "activate_window_menu" }, + { "initiate_key", "begin_resize" }, + { "initiate_key", "begin_move" }, + { "show_desktop_key", "show_desktop" }, + { "toggle_window_shaded_key", "toggle_shaded" }, + { "close_window_key", "close" }, + { "lower_window_key", "lower" }, + { "raise_window_key", "raise" }, + { "maximize_window_vertically_key", "maximize_vertically" }, + { "maximize_window_horizontally_key", "maximize_horizontally" }, + { "unmaximize_window_key", "unmaximize" }, + { "maximize_window_key", "maximize" }, + { "minimize_window_key", "minimize" }, + { "toggle_window_maximized_key", "toggle_maximized" }, + { "run_command_terminal_key", "run_command_terminal" }, + { "run_command_window_screenshot_key", "run_command_window_screenshot" }, + { "run_command_screenshot_key", "run_command_screenshot" }, + { "main_menu_key", "panel_main_menu" }, + { "run_key", "panel_run_dialog" }, + { "show_hud", "show_hud" } +}; + +const CCSGConfIntegrationCategories ccsGConfIntegrationCategories = +{ + METACITY "/general/", + "/apps/panel/applets/window_list/prefs/", + "/desktop/gnome/applications/terminal/", + METACITY "/keybinding_commands/", + METACITY "/window_keybindings/", + METACITY "/global_keybindings/" +}; + +const CCSGNOMEIntegratedPluginNames ccsGNOMEIntegratedPluginNames = +{ + "core", + "thumbnail", + "gnomecompat", + "rotate", + "put", + "wall", + "vpswitch", + "commands", + "extrawm", + "resize", + "move", + "staticswitcher", + "fade", + "unityshell", + "__special" +}; + +static gpointer +ccsGNOMEIntegrationInitializeIntegratedSettingsList (gpointer data) +{ + CCSGNOMEIntegratedSettingsList *array = (CCSGNOMEIntegratedSettingsList *) data; + const CCSGNOMEIntegratedPluginNames *plugins = &ccsGNOMEIntegratedPluginNames; + const CCSGNOMEIntegratedSettingNames *settings = &ccsGNOMEIntegratedSettingNames; + + array[0].pluginName = plugins->CORE; + array[0].settingName = settings->CORE_AUDIBLE_BELL.compizName; + array[1].pluginName = plugins->CORE; + array[1].settingName = settings->CORE_CLICK_TO_FOCUS.compizName; + array[2].pluginName = plugins->CORE; + array[2].settingName = settings->CORE_RAISE_ON_CLICK.compizName; + array[3].pluginName = plugins->CORE; + array[3].settingName = settings->CORE_AUTORAISE_DELAY.compizName; + array[4].pluginName = plugins->CORE; + array[4].settingName = settings->CORE_AUTORAISE.compizName; + array[5].pluginName = plugins->THUMBNAIL; + array[5].settingName = settings->THUMBNAIL_CURRENT_VIEWPORT.compizName; + array[6].pluginName = plugins->GNOMECOMPAT; + array[6].settingName = settings->GNOMECOMPAT_COMMAND_TERMINAL.compizName; + array[7].pluginName = plugins->GNOMECOMPAT; + array[7].settingName = settings->GNOMECOMPAT_COMMAND_WINDOW_SCREENSHOT.compizName; + array[8].pluginName = plugins->GNOMECOMPAT; + array[8].settingName = settings->GNOMECOMPAT_COMMAND_SCREENSHOT.compizName; + array[9].pluginName = plugins->ROTATE; + array[9].settingName = settings->ROTATE_ROTATE_RIGHT_WINDOW_KEY.compizName; + array[10].pluginName = plugins->ROTATE; + array[10].settingName = settings->ROTATE_ROTATE_LEFT_WINDOW_KEY.compizName; + array[11].pluginName = plugins->ROTATE; + array[11].settingName = settings->ROTATE_ROTATE_TO_12_WINDOW_KEY.compizName; + array[12].pluginName = plugins->ROTATE; + array[12].settingName = settings->ROTATE_ROTATE_TO_11_WINDOW_KEY.compizName; + array[13].pluginName = plugins->ROTATE; + array[13].settingName = settings->ROTATE_ROTATE_TO_10_WINDOW_KEY.compizName; + array[14].pluginName = plugins->ROTATE; + array[14].settingName = settings->ROTATE_ROTATE_TO_9_WINDOW_KEY.compizName; + array[15].pluginName = plugins->ROTATE; + array[15].settingName = settings->ROTATE_ROTATE_TO_8_WINDOW_KEY.compizName; + array[16].pluginName = plugins->ROTATE; + array[16].settingName = settings->ROTATE_ROTATE_TO_7_WINDOW_KEY.compizName; + array[17].pluginName = plugins->ROTATE; + array[17].settingName = settings->ROTATE_ROTATE_TO_6_WINDOW_KEY.compizName; + array[18].pluginName = plugins->ROTATE; + array[18].settingName = settings->ROTATE_ROTATE_TO_5_WINDOW_KEY.compizName; + array[19].pluginName = plugins->ROTATE; + array[19].settingName = settings->ROTATE_ROTATE_TO_4_WINDOW_KEY.compizName; + array[20].pluginName = plugins->ROTATE; + array[20].settingName = settings->ROTATE_ROTATE_TO_3_WINDOW_KEY.compizName; + array[21].pluginName = plugins->ROTATE; + array[21].settingName = settings->ROTATE_ROTATE_TO_2_WINDOW_KEY.compizName; + array[22].pluginName = plugins->ROTATE; + array[22].settingName = settings->ROTATE_ROTATE_TO_1_WINDOW_KEY.compizName; + array[23].pluginName = plugins->PUT; + array[23].settingName = settings->PUT_PUT_BOTTOM_KEY.compizName; + array[24].pluginName = plugins->PUT; + array[24].settingName = settings->PUT_PUT_TOP_KEY.compizName; + array[25].pluginName = plugins->PUT; + array[25].settingName = settings->PUT_PUT_RIGHT_KEY.compizName; + array[26].pluginName = plugins->PUT; + array[26].settingName = settings->PUT_PUT_LEFT_KEY.compizName; + array[27].pluginName = plugins->PUT; + array[27].settingName = settings->PUT_PUT_BOTTOMRIGHT_KEY.compizName; + array[28].pluginName = plugins->PUT; + array[28].settingName = settings->PUT_PUT_BOTTOMLEFT_KEY.compizName; + array[29].pluginName = plugins->PUT; + array[29].settingName = settings->PUT_PUT_TOPRIGHT_KEY.compizName; + array[30].pluginName = plugins->PUT; + array[30].settingName = settings->PUT_PUT_TOPLEFT_KEY.compizName; + array[31].pluginName = plugins->WALL; + array[31].settingName = settings->WALL_DOWN_WINDOW_KEY.compizName; + array[32].pluginName = plugins->WALL; + array[32].settingName = settings->WALL_UP_WINDOW_KEY.compizName; + array[33].pluginName = plugins->WALL; + array[33].settingName = settings->WALL_RIGHT_WINDOW_KEY.compizName; + array[34].pluginName = plugins->WALL; + array[34].settingName = settings->WALL_LEFT_WINDOW_KEY.compizName; + array[35].pluginName = plugins->WALL; + array[35].settingName = settings->WALL_RIGHT_KEY.compizName; + array[36].pluginName = plugins->WALL; + array[36].settingName = settings->WALL_LEFT_KEY.compizName; + array[37].pluginName = plugins->WALL; + array[37].settingName = settings->WALL_DOWN_KEY.compizName; + array[38].pluginName = plugins->WALL; + array[38].settingName = settings->WALL_UP_KEY.compizName; + array[39].pluginName = plugins->VPSWITCH; + array[39].settingName = settings->VPSWITCH_SWITCH_TO_12_KEY.compizName; + array[40].pluginName = plugins->VPSWITCH; + array[40].settingName = settings->VPSWITCH_SWITCH_TO_11_KEY.compizName; + array[41].pluginName = plugins->VPSWITCH; + array[41].settingName = settings->VPSWITCH_SWITCH_TO_10_KEY.compizName; + array[42].pluginName = plugins->VPSWITCH; + array[42].settingName = settings->VPSWITCH_SWITCH_TO_9_KEY.compizName; + array[43].pluginName = plugins->VPSWITCH; + array[43].settingName = settings->VPSWITCH_SWITCH_TO_8_KEY.compizName; + array[44].pluginName = plugins->VPSWITCH; + array[44].settingName = settings->VPSWITCH_SWITCH_TO_7_KEY.compizName; + array[45].pluginName = plugins->VPSWITCH; + array[45].settingName = settings->VPSWITCH_SWITCH_TO_6_KEY.compizName; + array[46].pluginName = plugins->VPSWITCH; + array[46].settingName = settings->VPSWITCH_SWITCH_TO_5_KEY.compizName; + array[47].pluginName = plugins->VPSWITCH; + array[47].settingName = settings->VPSWITCH_SWITCH_TO_4_KEY.compizName; + array[48].pluginName = plugins->VPSWITCH; + array[48].settingName = settings->VPSWITCH_SWITCH_TO_3_KEY.compizName; + array[49].pluginName = plugins->VPSWITCH; + array[49].settingName = settings->VPSWITCH_SWITCH_TO_2_KEY.compizName; + array[50].pluginName = plugins->VPSWITCH; + array[50].settingName = settings->VPSWITCH_SWITCH_TO_1_KEY.compizName; + array[51].pluginName = plugins->ROTATE; + array[51].settingName = settings->ROTATE_ROTATE_RIGHT_KEY.compizName; + array[52].pluginName = plugins->ROTATE; + array[52].settingName = settings->ROTATE_ROTATE_LEFT_KEY.compizName; + array[53].pluginName = plugins->ROTATE; + array[53].settingName = settings->ROTATE_ROTATE_TO_12_KEY.compizName; + array[54].pluginName = plugins->ROTATE; + array[54].settingName = settings->ROTATE_ROTATE_TO_11_KEY.compizName; + array[55].pluginName = plugins->ROTATE; + array[55].settingName = settings->ROTATE_ROTATE_TO_10_KEY.compizName; + array[56].pluginName = plugins->ROTATE; + array[56].settingName = settings->ROTATE_ROTATE_TO_9_KEY.compizName; + array[57].pluginName = plugins->ROTATE; + array[57].settingName = settings->ROTATE_ROTATE_TO_8_KEY.compizName; + array[58].pluginName = plugins->ROTATE; + array[58].settingName = settings->ROTATE_ROTATE_TO_7_KEY.compizName; + array[59].pluginName = plugins->ROTATE; + array[59].settingName = settings->ROTATE_ROTATE_TO_6_KEY.compizName; + array[60].pluginName = plugins->ROTATE; + array[60].settingName = settings->ROTATE_ROTATE_TO_5_KEY.compizName; + array[61].pluginName = plugins->ROTATE; + array[61].settingName = settings->ROTATE_ROTATE_TO_4_KEY.compizName; + array[62].pluginName = plugins->ROTATE; + array[62].settingName = settings->ROTATE_ROTATE_TO_3_KEY.compizName; + array[63].pluginName = plugins->ROTATE; + array[63].settingName = settings->ROTATE_ROTATE_TO_2_KEY.compizName; + array[64].pluginName = plugins->ROTATE; + array[64].settingName = settings->ROTATE_ROTATE_TO_1_KEY.compizName; + array[65].pluginName = plugins->COMMANDS; + array[65].settingName = settings->COMMANDS_RUN_COMMAND11_KEY.compizName; + array[66].pluginName = plugins->COMMANDS; + array[66].settingName = settings->COMMANDS_RUN_COMMAND10_KEY.compizName; + array[67].pluginName = plugins->COMMANDS; + array[67].settingName = settings->COMMANDS_RUN_COMMAND9_KEY.compizName; + array[68].pluginName = plugins->COMMANDS; + array[68].settingName = settings->COMMANDS_RUN_COMMAND8_KEY.compizName; + array[69].pluginName = plugins->COMMANDS; + array[69].settingName = settings->COMMANDS_RUN_COMMAND7_KEY.compizName; + array[70].pluginName = plugins->COMMANDS; + array[70].settingName = settings->COMMANDS_RUN_COMMAND6_KEY.compizName; + array[71].pluginName = plugins->COMMANDS; + array[71].settingName = settings->COMMANDS_RUN_COMMAND5_KEY.compizName; + array[72].pluginName = plugins->COMMANDS; + array[72].settingName = settings->COMMANDS_RUN_COMMAND4_KEY.compizName; + array[73].pluginName = plugins->COMMANDS; + array[73].settingName = settings->COMMANDS_RUN_COMMAND3_KEY.compizName; + array[74].pluginName = plugins->COMMANDS; + array[74].settingName = settings->COMMANDS_RUN_COMMAND2_KEY.compizName; + array[75].pluginName = plugins->COMMANDS; + array[75].settingName = settings->COMMANDS_RUN_COMMAND1_KEY.compizName; + array[76].pluginName = plugins->COMMANDS; + array[76].settingName = settings->COMMANDS_RUN_COMMAND0_KEY.compizName; + array[77].pluginName = plugins->COMMANDS; + array[77].settingName = settings->COMMANDS_COMMAND11.compizName; + array[78].pluginName = plugins->COMMANDS; + array[78].settingName = settings->COMMANDS_COMMAND10.compizName; + array[79].pluginName = plugins->COMMANDS; + array[79].settingName = settings->COMMANDS_COMMAND9.compizName; + array[80].pluginName = plugins->COMMANDS; + array[80].settingName = settings->COMMANDS_COMMAND8.compizName; + array[81].pluginName = plugins->COMMANDS; + array[81].settingName = settings->COMMANDS_COMMAND7.compizName; + array[82].pluginName = plugins->COMMANDS; + array[82].settingName = settings->COMMANDS_COMMAND6.compizName; + array[83].pluginName = plugins->COMMANDS; + array[83].settingName = settings->COMMANDS_COMMAND5.compizName; + array[84].pluginName = plugins->COMMANDS; + array[84].settingName = settings->COMMANDS_COMMAND4.compizName; + array[85].pluginName = plugins->COMMANDS; + array[85].settingName = settings->COMMANDS_COMMAND3.compizName; + array[86].pluginName = plugins->COMMANDS; + array[86].settingName = settings->COMMANDS_COMMAND2.compizName; + array[87].pluginName = plugins->COMMANDS; + array[87].settingName = settings->COMMANDS_COMMAND1.compizName; + array[88].pluginName = plugins->COMMANDS; + array[88].settingName = settings->COMMANDS_COMMAND0.compizName; + array[89].pluginName = plugins->EXTRAWM; + array[89].settingName = settings->EXTRAWM_TOGGLE_FULLSCREEN_KEY.compizName; + array[90].pluginName = plugins->EXTRAWM; + array[90].settingName = settings->EXTRAWM_TOGGLE_STICKY_KEY.compizName; + array[91].pluginName = plugins->STATICSWITCHER; + array[91].settingName = settings->STATICSWITCHER_PREV_KEY.compizName; + array[92].pluginName = plugins->STATICSWITCHER; + array[92].settingName = settings->STATICSWITCHER_NEXT_KEY.compizName; + array[93].pluginName = plugins->FADE; + array[93].settingName = settings->FADE_FULLSCREEN_VISUAL_BELL.compizName; + array[94].pluginName = plugins->FADE; + array[94].settingName = settings->FADE_VISUAL_BELL.compizName; + array[95].pluginName = plugins->SPECIAL; + array[95].settingName = settings->NULL_RESIZE_WITH_RIGHT_BUTTON.compizName; + array[96].pluginName = plugins->SPECIAL; + array[96].settingName = settings->NULL_MOUSE_BUTTON_MODIFIER.compizName; + array[97].pluginName = plugins->CORE; + array[97].settingName = settings->CORE_WINDOW_MENU_BUTTON.compizName; + array[98].pluginName = plugins->RESIZE; + array[98].settingName = settings->RESIZE_INITIATE_BUTTON.compizName; + array[99].pluginName = plugins->MOVE; + array[99].settingName = settings->MOVE_INITIATE_BUTTON.compizName; + array[100].pluginName = plugins->CORE; + array[100].settingName = settings->CORE_WINDOW_MENU_KEY.compizName; + array[101].pluginName = plugins->RESIZE; + array[101].settingName = settings->RESIZE_INITIATE_KEY.compizName; + array[102].pluginName = plugins->MOVE; + array[102].settingName = settings->MOVE_INITIATE_KEY.compizName; + array[103].pluginName = plugins->CORE; + array[103].settingName = settings->CORE_SHOW_DESKTOP_KEY.compizName; + array[104].pluginName = plugins->CORE; + array[104].settingName = settings->CORE_TOGGLE_WINDOW_SHADED_KEY.compizName; + array[105].pluginName = plugins->CORE; + array[105].settingName = settings->CORE_CLOSE_WINDOW_KEY.compizName; + array[106].pluginName = plugins->CORE; + array[106].settingName = settings->CORE_LOWER_WINDOW_KEY.compizName; + array[107].pluginName = plugins->CORE; + array[107].settingName = settings->CORE_RAISE_WINDOW_KEY.compizName; + array[108].pluginName = plugins->CORE; + array[108].settingName = settings->CORE_MAXIMIZE_WINDOW_VERTICALLY_KEY.compizName; + array[109].pluginName = plugins->CORE; + array[109].settingName = settings->CORE_MAXIMIZE_WINDOW_HORIZONTALLY_KEY.compizName; + array[110].pluginName = plugins->CORE; + array[110].settingName = settings->CORE_UNMAXIMIZE_WINDOW_KEY.compizName; + array[111].pluginName = plugins->CORE; + array[111].settingName = settings->CORE_MAXIMIZE_WINDOW_KEY.compizName; + array[112].pluginName = plugins->CORE; + array[112].settingName = settings->CORE_MINIMIZE_WINDOW_KEY.compizName; + array[113].pluginName = plugins->CORE; + array[113].settingName = settings->CORE_TOGGLE_WINDOW_MAXIMIZED_KEY.compizName; + array[114].pluginName = plugins->GNOMECOMPAT; + array[114].settingName = settings->GNOMECOMPAT_RUN_COMMAND_TERMINAL_KEY.compizName; + array[115].pluginName = plugins->GNOMECOMPAT; + array[115].settingName = settings->GNOMECOMPAT_RUN_COMMAND_WINDOW_SCREENSHOT_KEY.compizName; + array[116].pluginName = plugins->GNOMECOMPAT; + array[116].settingName = settings->GNOMECOMPAT_RUN_COMMAND_SCREENSHOT_KEY.compizName; + array[117].pluginName = plugins->GNOMECOMPAT; + array[117].settingName = settings->GNOMECOMPAT_MAIN_MENU_KEY.compizName; + array[118].pluginName = plugins->GNOMECOMPAT; + array[118].settingName = settings->GNOMECOMPAT_RUN_KEY.compizName; + array[119].pluginName = plugins->UNITYSHELL; + array[119].settingName = settings->UNITYSHELL_SHOW_HUD.compizName; + + + return NULL; +} + +const CCSGNOMEIntegratedSettingsList * +ccsGNOMEIntegratedSettingsList () +{ + static GOnce initIntegratedSettings = G_ONCE_INIT; + static const CCSGNOMEIntegratedSettingsList settings[CCS_GNOME_INTEGRATED_SETTINGS_LIST_SIZE]; + + g_once (&initIntegratedSettings, ccsGNOMEIntegrationInitializeIntegratedSettingsList, (gpointer) settings); + + return settings; +} + +gpointer +ccsGNOMEGSettingsIntegrationInitializeIntegratedSchemasQuarks (gpointer data) +{ + CCSGSettingsWrapperIntegratedSchemasQuarks *quarks = (CCSGSettingsWrapperIntegratedSchemasQuarks *) data; + + static const char *org_compiz_integrated = "org.compiz.integrated"; + static const char *org_gnome_desktop_wm_keybindings = "org.gnome.desktop.wm.keybindings"; + static const char *org_gnome_desktop_wm_preferences = "org.gnome.desktop.wm.preferences"; + + quarks->ORG_COMPIZ_INTEGRATED = g_quark_from_string (org_compiz_integrated); + quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS = g_quark_from_string (org_gnome_desktop_wm_keybindings); + quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES = g_quark_from_string (org_gnome_desktop_wm_preferences); + + return NULL; +} + +const CCSGSettingsWrapperIntegratedSchemasQuarks * +ccsGNOMEGSettingsWrapperQuarks () +{ + static GOnce initIntegratedSchemaQuarks = G_ONCE_INIT; + static const CCSGSettingsWrapperIntegratedSchemasQuarks quarks; + + g_once (&initIntegratedSchemaQuarks, ccsGNOMEGSettingsIntegrationInitializeIntegratedSchemasQuarks, (gpointer) &quarks); + + return &quarks; +} + +static void destroyHashTableInternal (void *ht) +{ + g_hash_table_unref ((GHashTable *) ht); +} + +GHashTable * +ccsGNOMEGSettingsIntegrationPopulateSettingNameToIntegratedSchemasQuarksHashTable () +{ + GHashTable *masterHashTable = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, destroyHashTableInternal); + GHashTable *coreHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *thumbnailHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *gnomecompatHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *rotateHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *putHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *wallHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *vpswitchHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *commandsHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *extrawmHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *resizeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *moveHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *staticswitcherHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *fadeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *unityshellHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *specialHashTable = g_hash_table_new (g_str_hash, g_str_equal); + + const CCSGNOMEIntegratedSettingNames *names = &ccsGNOMEIntegratedSettingNames; + const CCSGNOMEIntegratedPluginNames *plugins = &ccsGNOMEIntegratedPluginNames; + const CCSGSettingsWrapperIntegratedSchemasQuarks *quarks = ccsGNOMEGSettingsWrapperQuarks (); + + g_hash_table_insert (masterHashTable, (gpointer) plugins->CORE, coreHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->THUMBNAIL, thumbnailHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->GNOMECOMPAT, gnomecompatHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->ROTATE, rotateHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->PUT, putHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->WALL, wallHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->VPSWITCH, vpswitchHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->COMMANDS, commandsHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->EXTRAWM, extrawmHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->STATICSWITCHER, staticswitcherHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->FADE, fadeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->RESIZE, resizeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->MOVE, moveHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->UNITYSHELL, unityshellHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->SPECIAL, specialHashTable); + + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUDIBLE_BELL.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLICK_TO_FOCUS.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_ON_CLICK.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE_DELAY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (thumbnailHashTable, (gpointer) names->THUMBNAIL_CURRENT_VIEWPORT.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_TERMINAL.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_WINDOW_SCREENSHOT.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_SCREENSHOT.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOM_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOP_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_RIGHT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_LEFT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMRIGHT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMLEFT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPRIGHT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPLEFT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_12_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_11_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_10_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_9_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_8_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_7_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_6_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_5_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_4_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_3_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_2_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_1_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND11_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND10_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND9_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND8_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND7_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND6_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND5_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND4_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND3_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND2_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND1_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND0_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND11.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND10.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND9.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND8.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND7.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND6.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND5.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND4.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND3.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND2.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND1.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND0.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_FULLSCREEN_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_STICKY_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_PREV_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_NEXT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_FULLSCREEN_VISUAL_BELL.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_VISUAL_BELL.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_RESIZE_WITH_RIGHT_BUTTON.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_MOUSE_BUTTON_MODIFIER.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_PREFERENCES)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_BUTTON.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_BUTTON.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_BUTTON.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_SHOW_DESKTOP_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_SHADED_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLOSE_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_LOWER_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_VERTICALLY_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_HORIZONTALLY_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_UNMAXIMIZE_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MINIMIZE_WINDOW_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_MAXIMIZED_KEY.compizName, GINT_TO_POINTER (quarks->ORG_GNOME_DESKTOP_WM_KEYBINDINGS)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_TERMINAL_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_WINDOW_SCREENSHOT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_SCREENSHOT_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_MAIN_MENU_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_KEY.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + g_hash_table_insert (unityshellHashTable, (gpointer) names->UNITYSHELL_SHOW_HUD.compizName, GINT_TO_POINTER (quarks->ORG_COMPIZ_INTEGRATED)); + + return masterHashTable; +} + +GHashTable * +ccsGNOMEIntegrationPopulateCategoriesHashTables () +{ + GHashTable *masterHashTable = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, destroyHashTableInternal); + GHashTable *coreHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *thumbnailHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *gnomecompatHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *rotateHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *putHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *wallHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *vpswitchHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *commandsHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *extrawmHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *resizeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *moveHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *staticswitcherHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *fadeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *unityshellHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *specialHashTable = g_hash_table_new (g_str_hash, g_str_equal); + + const CCSGNOMEIntegratedSettingNames *names = &ccsGNOMEIntegratedSettingNames; + const CCSGConfIntegrationCategories *categories = &ccsGConfIntegrationCategories; + const CCSGNOMEIntegratedPluginNames *plugins = &ccsGNOMEIntegratedPluginNames; + + g_hash_table_insert (masterHashTable, (gpointer) plugins->CORE, coreHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->THUMBNAIL, thumbnailHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->GNOMECOMPAT, gnomecompatHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->ROTATE, rotateHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->PUT, putHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->WALL, wallHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->VPSWITCH, vpswitchHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->COMMANDS, commandsHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->EXTRAWM, extrawmHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->STATICSWITCHER, staticswitcherHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->FADE, fadeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->RESIZE, resizeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->MOVE, moveHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->UNITYSHELL, unityshellHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->SPECIAL, specialHashTable); + + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUDIBLE_BELL.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLICK_TO_FOCUS.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_ON_CLICK.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE_DELAY.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (thumbnailHashTable, (gpointer) names->THUMBNAIL_CURRENT_VIEWPORT.compizName, (gpointer) categories->APPS); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_TERMINAL.compizName, (gpointer) categories->DESKTOP); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_WINDOW_SCREENSHOT.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_SCREENSHOT.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOM_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOP_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_RIGHT_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_LEFT_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMRIGHT_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMLEFT_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPRIGHT_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPLEFT_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_12_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_11_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_10_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_9_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_8_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_7_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_6_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_5_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_4_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_3_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_2_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_1_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND11_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND10_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND9_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND8_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND7_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND6_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND5_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND4_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND3_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND2_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND1_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND0_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND11.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND10.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND9.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND8.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND7.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND6.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND5.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND4.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND3.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND2.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND1.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND0.compizName, (gpointer) categories->KEYBINDING_COMMANDS); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_FULLSCREEN_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_STICKY_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_PREV_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_NEXT_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_FULLSCREEN_VISUAL_BELL.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_VISUAL_BELL.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_RESIZE_WITH_RIGHT_BUTTON.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_MOUSE_BUTTON_MODIFIER.compizName, (gpointer) categories->GENERAL); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_BUTTON.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_BUTTON.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_BUTTON.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_SHOW_DESKTOP_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_SHADED_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLOSE_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_LOWER_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_VERTICALLY_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_HORIZONTALLY_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_UNMAXIMIZE_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MINIMIZE_WINDOW_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_MAXIMIZED_KEY.compizName, (gpointer) categories->WINDOW_KEYBINDINGS); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_TERMINAL_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_WINDOW_SCREENSHOT_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_SCREENSHOT_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_MAIN_MENU_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_KEY.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + g_hash_table_insert (unityshellHashTable, (gpointer) names->UNITYSHELL_SHOW_HUD.compizName, (gpointer) categories->GLOBAL_KEYBINDINGS); + + return masterHashTable; +} + + +GHashTable * +ccsGNOMEIntegrationPopulateSpecialTypesHashTables () +{ + GHashTable *masterHashTable = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, destroyHashTableInternal); + GHashTable *coreHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *thumbnailHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *gnomecompatHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *rotateHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *putHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *wallHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *vpswitchHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *commandsHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *extrawmHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *resizeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *moveHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *staticswitcherHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *fadeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *unityshellHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *specialHashTable = g_hash_table_new (g_str_hash, g_str_equal); + + const CCSGNOMEIntegratedSettingNames *names = &ccsGNOMEIntegratedSettingNames; + const CCSGNOMEIntegratedPluginNames *plugins = &ccsGNOMEIntegratedPluginNames; + + g_hash_table_insert (masterHashTable, (gpointer) plugins->CORE, coreHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->THUMBNAIL, thumbnailHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->GNOMECOMPAT, gnomecompatHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->ROTATE, rotateHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->PUT, putHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->WALL, wallHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->VPSWITCH, vpswitchHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->COMMANDS, commandsHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->EXTRAWM, extrawmHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->STATICSWITCHER, staticswitcherHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->FADE, fadeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->RESIZE, resizeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->MOVE, moveHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->UNITYSHELL, unityshellHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->SPECIAL, specialHashTable); + + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUDIBLE_BELL.compizName, GINT_TO_POINTER (OptionBool)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLICK_TO_FOCUS.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_ON_CLICK.compizName, GINT_TO_POINTER (OptionBool)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE_DELAY.compizName, GINT_TO_POINTER (OptionInt)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE.compizName, GINT_TO_POINTER (OptionBool)); + g_hash_table_insert (thumbnailHashTable, (gpointer) names->THUMBNAIL_CURRENT_VIEWPORT.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_TERMINAL.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_WINDOW_SCREENSHOT.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_SCREENSHOT.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOM_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOP_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_RIGHT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_LEFT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMRIGHT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMLEFT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPRIGHT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPLEFT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_12_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_11_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_10_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_9_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_8_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_7_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_6_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_5_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_4_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_3_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_2_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_1_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND11_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND10_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND9_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND8_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND7_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND6_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND5_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND4_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND3_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND2_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND1_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND0_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND11.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND10.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND9.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND8.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND7.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND6.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND5.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND4.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND3.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND2.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND1.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND0.compizName, GINT_TO_POINTER (OptionString)); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_FULLSCREEN_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_STICKY_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_PREV_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_NEXT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_FULLSCREEN_VISUAL_BELL.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_VISUAL_BELL.compizName, GINT_TO_POINTER (OptionBool)); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_RESIZE_WITH_RIGHT_BUTTON.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_MOUSE_BUTTON_MODIFIER.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_BUTTON.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_BUTTON.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_BUTTON.compizName, GINT_TO_POINTER (OptionSpecial)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_SHOW_DESKTOP_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_SHADED_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLOSE_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_LOWER_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_VERTICALLY_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_HORIZONTALLY_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_UNMAXIMIZE_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MINIMIZE_WINDOW_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_MAXIMIZED_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_TERMINAL_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_WINDOW_SCREENSHOT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_SCREENSHOT_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_MAIN_MENU_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_KEY.compizName, GINT_TO_POINTER (OptionKey)); + g_hash_table_insert (unityshellHashTable, (gpointer) names->UNITYSHELL_SHOW_HUD.compizName, GINT_TO_POINTER (OptionKey)); + + return masterHashTable; +} + +GHashTable * +ccsGNOMEIntegrationPopulateSettingNameToGNOMENameHashTables () +{ + GHashTable *masterHashTable = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, destroyHashTableInternal); + GHashTable *coreHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *thumbnailHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *gnomecompatHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *rotateHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *putHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *wallHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *vpswitchHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *commandsHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *extrawmHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *resizeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *moveHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *staticswitcherHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *fadeHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *unityshellHashTable = g_hash_table_new (g_str_hash, g_str_equal); + GHashTable *specialHashTable = g_hash_table_new (g_str_hash, g_str_equal); + + const CCSGNOMEIntegratedSettingNames *names = &ccsGNOMEIntegratedSettingNames; + const CCSGNOMEIntegratedPluginNames *plugins = &ccsGNOMEIntegratedPluginNames; + + g_hash_table_insert (masterHashTable, (gpointer) plugins->CORE, coreHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->THUMBNAIL, thumbnailHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->GNOMECOMPAT, gnomecompatHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->ROTATE, rotateHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->PUT, putHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->WALL, wallHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->VPSWITCH, vpswitchHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->COMMANDS, commandsHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->EXTRAWM, extrawmHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->STATICSWITCHER, staticswitcherHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->FADE, fadeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->RESIZE, resizeHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->MOVE, moveHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->UNITYSHELL, unityshellHashTable); + g_hash_table_insert (masterHashTable, (gpointer) plugins->SPECIAL, specialHashTable); + + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUDIBLE_BELL.compizName, (gpointer) names->CORE_AUDIBLE_BELL.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLICK_TO_FOCUS.compizName, (gpointer) names->CORE_CLICK_TO_FOCUS.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_ON_CLICK.compizName, (gpointer) names->CORE_RAISE_ON_CLICK.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE_DELAY.compizName, (gpointer) names->CORE_AUTORAISE_DELAY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_AUTORAISE.compizName, (gpointer) names->CORE_AUTORAISE.gnomeName); + g_hash_table_insert (thumbnailHashTable, (gpointer) names->THUMBNAIL_CURRENT_VIEWPORT.compizName, (gpointer) names->THUMBNAIL_CURRENT_VIEWPORT.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_TERMINAL.compizName, (gpointer) names->GNOMECOMPAT_COMMAND_TERMINAL.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_WINDOW_SCREENSHOT.compizName, (gpointer) names->GNOMECOMPAT_COMMAND_WINDOW_SCREENSHOT.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_COMMAND_SCREENSHOT.compizName, (gpointer) names->GNOMECOMPAT_COMMAND_SCREENSHOT.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_RIGHT_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_LEFT_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_12_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_11_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_10_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_9_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_8_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_7_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_6_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_5_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_4_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_3_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_2_WINDOW_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_WINDOW_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_1_WINDOW_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOM_KEY.compizName, (gpointer) names->PUT_PUT_BOTTOM_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOP_KEY.compizName, (gpointer) names->PUT_PUT_TOP_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_RIGHT_KEY.compizName, (gpointer) names->PUT_PUT_RIGHT_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_LEFT_KEY.compizName, (gpointer) names->PUT_PUT_LEFT_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMRIGHT_KEY.compizName, (gpointer) names->PUT_PUT_BOTTOMRIGHT_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_BOTTOMLEFT_KEY.compizName, (gpointer) names->PUT_PUT_BOTTOMLEFT_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPRIGHT_KEY.compizName, (gpointer) names->PUT_PUT_TOPRIGHT_KEY.gnomeName); + g_hash_table_insert (putHashTable, (gpointer) names->PUT_PUT_TOPLEFT_KEY.compizName, (gpointer) names->PUT_PUT_TOPLEFT_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_WINDOW_KEY.compizName, (gpointer) names->WALL_DOWN_WINDOW_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_WINDOW_KEY.compizName, (gpointer) names->WALL_UP_WINDOW_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_WINDOW_KEY.compizName, (gpointer) names->WALL_RIGHT_WINDOW_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_WINDOW_KEY.compizName, (gpointer) names->WALL_LEFT_WINDOW_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_RIGHT_KEY.compizName, (gpointer) names->WALL_RIGHT_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_LEFT_KEY.compizName, (gpointer) names->WALL_LEFT_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_DOWN_KEY.compizName, (gpointer) names->WALL_DOWN_KEY.gnomeName); + g_hash_table_insert (wallHashTable, (gpointer) names->WALL_UP_KEY.compizName, (gpointer) names->WALL_UP_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_12_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_12_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_11_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_11_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_10_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_10_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_9_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_9_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_8_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_8_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_7_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_7_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_6_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_6_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_5_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_5_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_4_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_4_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_3_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_3_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_2_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_2_KEY.gnomeName); + g_hash_table_insert (vpswitchHashTable, (gpointer) names->VPSWITCH_SWITCH_TO_1_KEY.compizName, (gpointer) names->VPSWITCH_SWITCH_TO_1_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_RIGHT_KEY.compizName, (gpointer) names->ROTATE_ROTATE_RIGHT_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_LEFT_KEY.compizName, (gpointer) names->ROTATE_ROTATE_LEFT_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_12_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_12_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_11_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_11_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_10_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_10_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_9_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_9_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_8_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_8_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_7_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_7_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_6_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_6_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_5_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_5_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_4_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_4_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_3_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_3_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_2_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_2_KEY.gnomeName); + g_hash_table_insert (rotateHashTable, (gpointer) names->ROTATE_ROTATE_TO_1_KEY.compizName, (gpointer) names->ROTATE_ROTATE_TO_1_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND11_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND11_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND10_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND10_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND9_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND9_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND8_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND8_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND7_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND7_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND6_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND6_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND5_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND5_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND4_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND4_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND3_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND3_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND2_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND2_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND1_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND1_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_RUN_COMMAND0_KEY.compizName, (gpointer) names->COMMANDS_RUN_COMMAND0_KEY.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND11.compizName, (gpointer) names->COMMANDS_COMMAND11.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND10.compizName, (gpointer) names->COMMANDS_COMMAND10.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND9.compizName, (gpointer) names->COMMANDS_COMMAND9.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND8.compizName, (gpointer) names->COMMANDS_COMMAND8.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND7.compizName, (gpointer) names->COMMANDS_COMMAND7.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND6.compizName, (gpointer) names->COMMANDS_COMMAND6.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND5.compizName, (gpointer) names->COMMANDS_COMMAND5.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND4.compizName, (gpointer) names->COMMANDS_COMMAND4.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND3.compizName, (gpointer) names->COMMANDS_COMMAND3.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND2.compizName, (gpointer) names->COMMANDS_COMMAND2.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND1.compizName, (gpointer) names->COMMANDS_COMMAND1.gnomeName); + g_hash_table_insert (commandsHashTable, (gpointer) names->COMMANDS_COMMAND0.compizName, (gpointer) names->COMMANDS_COMMAND0.gnomeName); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_FULLSCREEN_KEY.compizName, (gpointer) names->EXTRAWM_TOGGLE_FULLSCREEN_KEY.gnomeName); + g_hash_table_insert (extrawmHashTable, (gpointer) names->EXTRAWM_TOGGLE_STICKY_KEY.compizName, (gpointer) names->EXTRAWM_TOGGLE_STICKY_KEY.gnomeName); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_PREV_KEY.compizName, (gpointer) names->STATICSWITCHER_PREV_KEY.gnomeName); + g_hash_table_insert (staticswitcherHashTable, (gpointer) names->STATICSWITCHER_NEXT_KEY.compizName, (gpointer) names->STATICSWITCHER_NEXT_KEY.gnomeName); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_FULLSCREEN_VISUAL_BELL.compizName, (gpointer) names->FADE_FULLSCREEN_VISUAL_BELL.gnomeName); + g_hash_table_insert (fadeHashTable, (gpointer) names->FADE_VISUAL_BELL.compizName, (gpointer) names->FADE_VISUAL_BELL.gnomeName); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_RESIZE_WITH_RIGHT_BUTTON.compizName, (gpointer) names->NULL_RESIZE_WITH_RIGHT_BUTTON.gnomeName); + g_hash_table_insert (specialHashTable, (gpointer) names->NULL_MOUSE_BUTTON_MODIFIER.compizName, (gpointer) names->NULL_MOUSE_BUTTON_MODIFIER.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_BUTTON.compizName, (gpointer) names->CORE_WINDOW_MENU_BUTTON.gnomeName); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_BUTTON.compizName, (gpointer) names->RESIZE_INITIATE_BUTTON.gnomeName); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_BUTTON.compizName, (gpointer) names->MOVE_INITIATE_BUTTON.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_WINDOW_MENU_KEY.compizName, (gpointer) names->CORE_WINDOW_MENU_KEY.gnomeName); + g_hash_table_insert (resizeHashTable, (gpointer) names->RESIZE_INITIATE_KEY.compizName, (gpointer) names->RESIZE_INITIATE_KEY.gnomeName); + g_hash_table_insert (moveHashTable, (gpointer) names->MOVE_INITIATE_KEY.compizName, (gpointer) names->MOVE_INITIATE_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_SHOW_DESKTOP_KEY.compizName, (gpointer) names->CORE_SHOW_DESKTOP_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_SHADED_KEY.compizName, (gpointer) names->CORE_TOGGLE_WINDOW_SHADED_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_CLOSE_WINDOW_KEY.compizName, (gpointer) names->CORE_CLOSE_WINDOW_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_LOWER_WINDOW_KEY.compizName, (gpointer) names->CORE_LOWER_WINDOW_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_RAISE_WINDOW_KEY.compizName, (gpointer) names->CORE_RAISE_WINDOW_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_VERTICALLY_KEY.compizName, (gpointer) names->CORE_MAXIMIZE_WINDOW_VERTICALLY_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_HORIZONTALLY_KEY.compizName, (gpointer) names->CORE_MAXIMIZE_WINDOW_HORIZONTALLY_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_UNMAXIMIZE_WINDOW_KEY.compizName, (gpointer) names->CORE_UNMAXIMIZE_WINDOW_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MAXIMIZE_WINDOW_KEY.compizName, (gpointer) names->CORE_MAXIMIZE_WINDOW_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_MINIMIZE_WINDOW_KEY.compizName, (gpointer) names->CORE_MINIMIZE_WINDOW_KEY.gnomeName); + g_hash_table_insert (coreHashTable, (gpointer) names->CORE_TOGGLE_WINDOW_MAXIMIZED_KEY.compizName, (gpointer) names->CORE_TOGGLE_WINDOW_MAXIMIZED_KEY.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_TERMINAL_KEY.compizName, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_TERMINAL_KEY.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_WINDOW_SCREENSHOT_KEY.compizName, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_WINDOW_SCREENSHOT_KEY.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_SCREENSHOT_KEY.compizName, (gpointer) names->GNOMECOMPAT_RUN_COMMAND_SCREENSHOT_KEY.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_MAIN_MENU_KEY.compizName, (gpointer) names->GNOMECOMPAT_MAIN_MENU_KEY.gnomeName); + g_hash_table_insert (gnomecompatHashTable, (gpointer) names->GNOMECOMPAT_RUN_KEY.compizName, (gpointer) names->GNOMECOMPAT_RUN_KEY.gnomeName); + g_hash_table_insert (unityshellHashTable, (gpointer) names->UNITYSHELL_SHOW_HUD.compizName, (gpointer) names->UNITYSHELL_SHOW_HUD.gnomeName); + + return masterHashTable; +} diff --git a/compizconfig/libcompizconfig/backend/src/ini.c b/compizconfig/libcompizconfig/backend/src/ini.c index 1fb83a6426d8f7249a86c85f62b401e75a7cd8fc..36f7a35f0c878f7801aefae01571cc82e0c3af1f 100644 --- a/compizconfig/libcompizconfig/backend/src/ini.c +++ b/compizconfig/libcompizconfig/backend/src/ini.c @@ -50,29 +50,9 @@ typedef struct _IniPrivData IniPrivData; -static IniPrivData *privData = NULL; - -static int privDataSize = 0; - /* forward declaration */ static void setProfile (IniPrivData *data, char *profile); -static IniPrivData* -findPrivFromContext (CCSContext *context) -{ - int i; - IniPrivData *data; - - for (i = 0, data = privData; i < privDataSize; i++, data++) - if (data->context == context) - break; - - if (i == privDataSize) - return NULL; - - return data; -} - static char* getIniFileName (char *profile) { @@ -180,28 +160,26 @@ setProfile (IniPrivData *data, } static Bool -initBackend (CCSContext * context) +initBackend (CCSBackend *backend, CCSContext * context) { IniPrivData *newData; - privData = realloc (privData, (privDataSize + 1) * sizeof (IniPrivData)); - newData = privData + privDataSize; + newData = calloc (1, sizeof (IniPrivData)); /* initialize the newly allocated part */ - memset (newData, 0, sizeof (IniPrivData)); newData->context = context; - privDataSize++; + ccsObjectSetPrivate (backend, (CCSPrivate *) newData); return TRUE; } static Bool -finiBackend (CCSContext * context) +finiBackend (CCSBackend * backend) { IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return FALSE; @@ -215,36 +193,31 @@ finiBackend (CCSContext * context) if (data->lastProfile) free (data->lastProfile); - privDataSize--; - - if (privDataSize) - privData = realloc (privData, privDataSize * sizeof (IniPrivData)); - else - { - free (privData); - privData = NULL; - } + free (data); + ccsObjectSetPrivate (backend, NULL); return TRUE; } static Bool -readInit (CCSContext * context) +readInit (CCSBackend *backend, + CCSContext * context) { - char *currentProfile; + const char *currentProfileCCS; + char *currentProfile; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return FALSE; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); if (!data->lastProfile || (strcmp (data->lastProfile, currentProfile) != 0)) setProfile (data, currentProfile); @@ -258,14 +231,15 @@ readInit (CCSContext * context) } static void -readSetting (CCSContext *context, +readSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { Bool status = FALSE; char *keyName; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return; @@ -414,27 +388,28 @@ readSetting (CCSContext *context, } static void -readDone (CCSContext * context) +readDone (CCSBackend *backend, CCSContext * context) { } static Bool -writeInit (CCSContext * context) +writeInit (CCSBackend *backend, CCSContext * context) { + const char *currentProfileCCS; char *currentProfile; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return FALSE; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); if (!data->lastProfile || (strcmp (data->lastProfile, currentProfile) != 0)) setProfile (data, currentProfile); @@ -450,13 +425,14 @@ writeInit (CCSContext * context) } static void -writeSetting (CCSContext *context, +writeSetting (CCSBackend *backend, + CCSContext *context, CCSSetting *setting) { char *keyName; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return; @@ -569,23 +545,24 @@ writeSetting (CCSContext *context, } static void -writeDone (CCSContext * context) +writeDone (CCSBackend *backend, CCSContext * context) { /* export the data to ensure the changes are on disk */ char *fileName; - char *currentProfile; + const char *currentProfileCCS; + char *currentProfile; IniPrivData *data; - data = findPrivFromContext (context); + data = (IniPrivData *) ccsObjectGetPrivate (backend); if (!data) return; - currentProfile = ccsGetProfile (context); + currentProfileCCS = ccsGetProfile (context); - if (!currentProfile || !strlen (currentProfile)) + if (!currentProfileCCS || !strlen (currentProfileCCS)) currentProfile = strdup (DEFAULTPROF); else - currentProfile = strdup (currentProfile); + currentProfile = strdup (currentProfileCCS); fileName = getIniFileName (currentProfile); @@ -598,8 +575,18 @@ writeDone (CCSContext * context) free (fileName); } +static void +updateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + if (readInit (backend, context)) + { + readSetting (backend, context, setting); + readDone (backend, context); + } +} + static Bool -getSettingIsReadOnly (CCSSetting * setting) +getSettingIsReadOnly (CCSBackend *backend, CCSSetting * setting) { /* FIXME */ return FALSE; @@ -652,7 +639,7 @@ scanConfigDir (char * filePath) } static CCSStringList -getExistingProfiles (CCSContext * context) +getExistingProfiles (CCSBackend *backend, CCSContext * context) { CCSStringList ret = NULL; char *filePath = NULL; @@ -689,7 +676,7 @@ getExistingProfiles (CCSContext * context) } static Bool -deleteProfile (CCSContext * context, char * profile) +deleteProfile (CCSBackend *backend, CCSContext * context, char * profile) { char *fileName; @@ -704,13 +691,24 @@ deleteProfile (CCSContext * context, char * profile) return TRUE; } - -static CCSBackendVTable iniVTable = { +const CCSBackendInfo iniBackendInfo = +{ "ini", "Flat-file Configuration Backend", "Flat file Configuration Backend for libccs", FALSE, TRUE, + 1 +}; + +static const CCSBackendInfo * +getInfo (CCSBackend *backend) +{ + return &iniBackendInfo; +} + +static CCSBackendInterface iniVTable = { + getInfo, NULL, initBackend, finiBackend, @@ -720,13 +718,14 @@ static CCSBackendVTable iniVTable = { writeInit, writeSetting, writeDone, + updateSetting, NULL, getSettingIsReadOnly, getExistingProfiles, deleteProfile }; -CCSBackendVTable * +CCSBackendInterface * getBackendInfo (void) { return &iniVTable; diff --git a/compizconfig/libcompizconfig/config/CMakeLists.txt b/compizconfig/libcompizconfig/config/CMakeLists.txt index f3ff733cfcc1f6b48d1f55e590024110855c66ea..c4a09fce563996fe6f1d69e73b7d091a841b5b6e 100644 --- a/compizconfig/libcompizconfig/config/CMakeLists.txt +++ b/compizconfig/libcompizconfig/config/CMakeLists.txt @@ -1,6 +1,9 @@ set (_config_file config) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config_test + ${CMAKE_CURRENT_BINARY_DIR}/compiz-1/compizconfig/config) + compiz_opt_install_file (${CMAKE_CURRENT_SOURCE_DIR}/${_config_file} ${COMPIZ_SYSCONFDIR}/compizconfig/${_config_file}) add_custom_target ( diff --git a/compizconfig/libcompizconfig/config/config_test b/compizconfig/libcompizconfig/config/config_test new file mode 100644 index 0000000000000000000000000000000000000000..fdf477b7871c8cee7f0d2133a95d7f9a36bce063 --- /dev/null +++ b/compizconfig/libcompizconfig/config/config_test @@ -0,0 +1,3 @@ +[general] +backend = ini +plugin_list_autosort = true diff --git a/compizconfig/libcompizconfig/include/CMakeLists.txt b/compizconfig/libcompizconfig/include/CMakeLists.txt index 0544e0169ee2fb3f07243c67bd4e6e484b37ee63..7fab10dccc244d40a5286a657e6d3b08f2c49b1f 100644 --- a/compizconfig/libcompizconfig/include/CMakeLists.txt +++ b/compizconfig/libcompizconfig/include/CMakeLists.txt @@ -1,5 +1,9 @@ set (_headers ccs-backend.h + ccs-defs.h + ccs-list.h + ccs-object.h + ccs-string.h ccs.h ) diff --git a/compizconfig/libcompizconfig/include/ccs-backend.h b/compizconfig/libcompizconfig/include/ccs-backend.h index 1377a64d5a4fc9053a8e4915f2a4d8ad02aa837e..c9d1f84aaafffa6a1df9e307cc41f4d83a681445 100644 --- a/compizconfig/libcompizconfig/include/ccs-backend.h +++ b/compizconfig/libcompizconfig/include/ccs-backend.h @@ -22,72 +22,552 @@ #ifndef CCS_BACKEND_H #define CCS_BACKEND_H -#include +#include +#include +#include +#include +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSSetting CCSSetting; +typedef struct _CCSPlugin CCSPlugin; +typedef struct _CCSContext CCSContext; typedef struct _CCSBackend CCSBackend; -typedef struct _CCSBackendVTable CCSBackendVTable; +typedef struct _CCSBackendInfo CCSBackendInfo; +typedef struct _CCSBackendPrivate CCSBackendPrivate; +typedef struct _CCSBackendInterface CCSBackendInterface; +typedef struct _CCSIntegration CCSIntegration; + +typedef struct _CCSSettingValue CCSSettingValue; +typedef enum _CCSSettingType CCSSettingType; + +typedef struct _CCSIntegratedSettingInfo CCSIntegratedSettingInfo; +typedef struct _CCSIntegratedSettingInfoInterface CCSIntegratedSettingInfoInterface; + +typedef const char * (*CCSIntegratedSettingInfoPluginName) (CCSIntegratedSettingInfo *); +typedef const char * (*CCSIntegratedSettingInfoSettingName) (CCSIntegratedSettingInfo *); +typedef CCSSettingType (*CCSIntegratedSettingInfoGetType) (CCSIntegratedSettingInfo *); +typedef void (*CCSIntegratedSettingInfoFree) (CCSIntegratedSettingInfo *); + +struct _CCSIntegratedSettingInfoInterface +{ + CCSIntegratedSettingInfoPluginName pluginName; + CCSIntegratedSettingInfoSettingName settingName; + CCSIntegratedSettingInfoGetType getType; + CCSIntegratedSettingInfoFree free; +}; + +/** + * @brief The _CCSIntegratedSettingInfo struct + * + * This interface represents some basic information about a DE + * integrated setting, it cannot be operated upon itself + */ +struct _CCSIntegratedSettingInfo +{ + CCSObject object; +}; + +typedef struct _CCSIntegratedSetting CCSIntegratedSetting; +typedef struct _CCSIntegratedSettingInterface CCSIntegratedSettingInterface; + +typedef CCSSettingValue * (*CCSIntegratedSettingReadValue) (CCSIntegratedSetting *, CCSSettingType); +typedef void (*CCSIntegratedSettingWriteValue) (CCSIntegratedSetting *, CCSSettingValue *, CCSSettingType); +typedef void (*CCSIntegratedSettingFree) (CCSIntegratedSetting *); + +struct _CCSIntegratedSettingInterface +{ + CCSIntegratedSettingReadValue readValue; + CCSIntegratedSettingWriteValue writeValue; + CCSIntegratedSettingFree free; +}; + +const char * ccsIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *); +const char * ccsIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *); +CCSSettingType ccsIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *); +void ccsFreeIntegratedSettingInfo (CCSIntegratedSettingInfo *); + +CCSREF_HDR (IntegratedSettingInfo, CCSIntegratedSettingInfo); +CCSLIST_HDR (IntegratedSettingInfo, CCSIntegratedSettingInfo); + +unsigned int ccsCCSIntegratedSettingInfoInterfaceGetType (); + +/** + * @brief The _CCSIntegratedSetting struct + * + * A CCSIntegratedSetting represents an desktop environment setting which + * we are "integrated" with - its functionality is more or less a subset + * of CCSSetting, values can be written and read from it but not much else. + */ +struct _CCSIntegratedSetting +{ + CCSObject object; +}; + +CCSSettingValue * ccsIntegratedSettingReadValue(CCSIntegratedSetting *, CCSSettingType); +void ccsIntegratedSettingWriteValue (CCSIntegratedSetting *, CCSSettingValue *, CCSSettingType); +void ccsFreeIntegratedSetting (CCSIntegratedSetting *); + +CCSREF_HDR (IntegratedSetting, CCSIntegratedSetting); +CCSLIST_HDR (IntegratedSetting, CCSIntegratedSetting); + +unsigned int ccsCCSIntegratedSettingInterfaceGetType (); + +/** + * @brief ccsSharedIntegratedInfoSettingNew + * @param pluginName Plugin name of the integrated setting + * @param settingName Compiz name of the integrated setting + * @param type A CCSSettingType + * @param ai A CCSObjectAllocationInterface * + * @return a new CCSIntegratedSettingInfo + * + * ccsSharedIntegratedSettingInfoNew () returns the most fundamental + * implementation of a CCSIntegratedSettingInfo *, which is basic + * information about it, the plugin name, setting name, and type. + */ +CCSIntegratedSettingInfo * +ccsSharedIntegratedSettingInfoNew (const char *pluginName, + const char *settingName, + CCSSettingType type, + CCSObjectAllocationInterface *ai); + +typedef struct _CCSIntegratedSettingsStorage CCSIntegratedSettingsStorage; +typedef struct _CCSIntegratedSettingsStorageInterface CCSIntegratedSettingsStorageInterface; + +/** + * A predicate definition to find a CCSIntegratedSetting in a + * CCSIntegratedSettingStorage object. Returns true if the user + * predicate matches. The void * is some user-specified data + */ +typedef Bool (*CCSIntegratedSettingsStorageFindPredicate) (CCSIntegratedSetting *, void *); + +typedef CCSIntegratedSettingList (*CCSIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName) (CCSIntegratedSettingsStorage *storage, + const char *pluginName, + const char *settingName); +typedef void (*CCSIntegratedSettingsStorageAddSetting) (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSetting *setting); + +typedef CCSIntegratedSettingList (*CCSIntegratedSettingsStorageFindMatchingSettingsByPredicate) (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSettingsStorageFindPredicate pred, + void *data); + +typedef Bool (*CCSIntegratedSettingsStorageEmpty) (CCSIntegratedSettingsStorage *storage); + +typedef void (*CCSIntegratedSettingsStorageFree) (CCSIntegratedSettingsStorage *storage); + +struct _CCSIntegratedSettingsStorageInterface +{ + CCSIntegratedSettingsStorageFindMatchingSettingsByPredicate findMatchingSettingsByPredicate; + CCSIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName findMatchingSettingsByPluginAndSettingName; + CCSIntegratedSettingsStorageAddSetting addSetting; + CCSIntegratedSettingsStorageEmpty empty; + CCSIntegratedSettingsStorageFree free; +}; + +/** + * @brief The _CCSIntegratedSettingsStorage struct + * + * CCSIntegratedSettingsStorage represents a list of currently active integrated + * DE settings. Access is restricted such that settings can only be added and + * the list can only be searched by predicates. + */ +struct _CCSIntegratedSettingsStorage +{ + CCSObject object; +}; + +CCSREF_HDR (IntegratedSettingsStorage, CCSIntegratedSettingsStorage); + +/** + * @brief ccsIntegratedSettingsStorageFindMatchingSettingsByPredicate + * @param storage + * @param pred + * @param data + * @return a CCSIntegratedSettingList of CCSIntegratedSetting objects + * matching CCSIntegratedSettingsStorageFindPredicate + */ +CCSIntegratedSettingList +ccsIntegratedSettingsStorageFindMatchingSettingsByPredicate (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSettingsStorageFindPredicate pred, + void *data); + +/** + * @brief ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName + * @param storage + * @param pluginName + * @param settingName + * @return a CCSIntegratedSettingList of CCSIntegratedSetting objects + * with the specified plugin and setting names. + */ +CCSIntegratedSettingList +ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName (CCSIntegratedSettingsStorage *storage, + const char *pluginName, + const char *settingName); + +void +ccsIntegratedSettingsStorageAddSetting (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSetting *setting); + +Bool +ccsIntegratedSettingsStorageEmpty (CCSIntegratedSettingsStorage *storage); + +void +ccsFreeIntegratedSettingsStorage (CCSIntegratedSettingsStorage *storage); + +unsigned int ccsCCSIntegratedSettingsStorageInterfaceGetType (); + +CCSIntegratedSettingsStorage * +ccsIntegratedSettingsStorageDefaultImplNew (CCSObjectAllocationInterface *ai); + +typedef struct _CCSIntegratedSettingFactory CCSIntegratedSettingFactory; +typedef struct _CCSIntegratedSettingFactoryInterface CCSIntegratedSettingFactoryInterface; + +typedef CCSIntegratedSetting * (*CCSIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType) (CCSIntegratedSettingFactory *factory, + CCSIntegration *integration, + const char *pluginName, + const char *settingName, + CCSSettingType type); + +typedef void (*CCSIntegratedSettingFactoryFree) (CCSIntegratedSettingFactory *); + +struct _CCSIntegratedSettingFactoryInterface +{ + CCSIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType createIntegratedSettingForCCSSettingNameAndType; + CCSIntegratedSettingFactoryFree free; +}; + +/** + * @brief The _CCSIntegratedSettingFactory struct + * + * CCSIntegratedSettingFactory is an interface for creating a CCSIntegratedSetting + * for a particular integration backend when appropriate. It doesn't make sense to load + * such information on startup until we need it as we might never write to these settings + * and loading them is an expensive process. In addition, we need to allow a place + * for testing code to prevent CCSIntegratedSetting objects from pulling + * in dependencies that they shouldn't. + */ +struct _CCSIntegratedSettingFactory +{ + CCSObject object; +}; + +CCSREF_HDR (IntegratedSettingFactory, CCSIntegratedSettingFactory); +unsigned int ccsCCSIntegratedSettingFactoryInterfaceGetType (); + +CCSIntegratedSetting * +ccsIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType (CCSIntegratedSettingFactory *factory, + CCSIntegration *integration, + const char *pluginName, + const char *settingName, + CCSSettingType type); + +void +ccsFreeIntegratedSettingFactory (CCSIntegratedSettingFactory *factory); + +typedef struct _CCSIntegration CCSIntegration; +typedef struct _CCSIntegrationInterface CCSIntegrationInterface; + +typedef CCSIntegratedSetting * (*CCSIntegrationGetIntegratedSetting) (CCSIntegration *integration, + const char *pluginName, + const char *settingName); +typedef Bool (*CCSIntegrationReadOptionIntoSetting) (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting); +typedef void (*CCSIntegrationWriteSettingIntoOption) (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting); +typedef void (*CCSIntegrationUpdateIntegratedSettings) (CCSIntegration *integration, + CCSContext *context, + CCSIntegratedSettingList integratedSettings); +typedef void (*CCSIntegrationDisallowIntegratedWrites) (CCSIntegration *integration); +typedef void (*CCSIntegrationAllowIntegratedWrites) (CCSIntegration *integration); +typedef void (*CCSFreeIntegrationBackend) (CCSIntegration *integration); + +struct _CCSIntegrationInterface +{ + CCSIntegrationGetIntegratedSetting getIntegratedSetting; + CCSIntegrationReadOptionIntoSetting readOptionIntoSetting; + CCSIntegrationWriteSettingIntoOption writeSettingIntoOption; + CCSIntegrationUpdateIntegratedSettings updateIntegratedSettings; + CCSIntegrationDisallowIntegratedWrites disallowIntegratedWrites; + CCSIntegrationAllowIntegratedWrites allowIntegratedWrites; + CCSFreeIntegrationBackend freeIntegrationBackend; +}; + +/** + * @brief The _CCSIntegration struct + * + * An object that represents integration with a desktop environment. Generally + * these objects store a list of hardcoded settings that can be retrieved using + * ccsIntegrationGetIntegratedOptionIndex and then written to and read + * from using the readOptionIntoSetting and writeOptionIntoSetting. + */ +struct _CCSIntegration +{ + CCSObject object; +}; + +CCSREF_HDR (Integration, CCSIntegration) + +unsigned int ccsCCSIntegrationInterfaceGetType (); + +CCSIntegratedSetting * ccsIntegrationGetIntegratedSetting (CCSIntegration *integration, + const char *pluginName, + const char *settingName); +Bool ccsIntegrationReadOptionIntoSetting (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting); +void ccsIntegrationWriteSettingIntoOption (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting); + +void ccsIntegrationUpdateIntegratedSettings (CCSIntegration *integration, + CCSContext *context, + CCSIntegratedSettingList integratedSettings); + +void ccsIntegrationDisallowIntegratedWrites (CCSIntegration *integration); +void ccsIntegrationAllowIntegratedWrites (CCSIntegration *integration); + +void ccsFreeIntegration (CCSIntegration *integration); + +CCSIntegration * +ccsNullIntegrationBackendNew (CCSObjectAllocationInterface *ai); + +/** + * @brief CCSBackend + * + * This object represents CCSBackend directly in memory. It does + * not represent the details that come with a loaded backend. + * + * Backends are capable of reading, writing and updating settings + * from intergrated locations. Clients should check if these functions + * are supported first as the function pointers are permitted to be NULL. + */ struct _CCSBackend { - void *dlhand; - CCSBackendVTable *vTable; + CCSObject object; +}; + +struct _CCSBackendInfo +{ + const char *name; /* name of the backend */ + const char *shortDesc; /* backend's short description */ + const char *longDesc; /* backend's long description */ + Bool integrationSupport; /* does the backend support DE integration? */ + Bool profileSupport; /* does the backend support profiles? */ + unsigned int refCount; /* reference count */ }; -typedef CCSBackendVTable * (*BackendGetInfoProc) (void); +typedef CCSBackendInterface * (*BackendGetInfoProc) (void); -typedef void (*CCSExecuteEventsFunc) (unsigned int flags); +typedef void (*CCSBackendExecuteEventsFunc) (CCSBackend *backend, unsigned int flags); -typedef Bool (*CCSInitBackendFunc) (CCSContext * context); -typedef Bool (*CCSFiniBackendFunc) (CCSContext * context); +typedef Bool (*CCSBackendInitFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendFiniFunc) (CCSBackend *); -typedef Bool (*CCSContextReadInitFunc) (CCSContext * context); -typedef void (*CCSContextReadSettingFunc) -(CCSContext * context, CCSSetting * setting); -typedef void (*CCSContextReadDoneFunc) (CCSContext * context); +typedef Bool (*CCSBackendReadInitFunc) (CCSBackend *, CCSContext * context); +typedef void (*CCSBackendReadSettingFunc) +(CCSBackend *, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendReadDoneFunc) (CCSBackend *backend, CCSContext * context); -typedef Bool (*CCSContextWriteInitFunc) (CCSContext * context); -typedef void (*CCSContextWriteSettingFunc) -(CCSContext * context, CCSSetting * setting); -typedef void (*CCSContextWriteDoneFunc) (CCSContext * context); +typedef Bool (*CCSBackendWriteInitFunc) (CCSBackend *backend, CCSContext * context); +typedef void (*CCSBackendWriteSettingFunc) +(CCSBackend *, CCSContext * context, CCSSetting * setting); +typedef void (*CCSBackendWriteDoneFunc) (CCSBackend *, CCSContext * context); -typedef Bool (*CCSGetIsIntegratedFunc) (CCSSetting * setting); -typedef Bool (*CCSGetIsReadOnlyFunc) (CCSSetting * setting); +typedef void (*CCSBackendUpdateFunc) (CCSBackend *, CCSContext *, CCSPlugin *, CCSSetting *); -typedef CCSStringList (*CCSGetExistingProfilesFunc) (CCSContext * context); -typedef Bool (*CCSDeleteProfileFunc) (CCSContext * context, char * name); +typedef Bool (*CCSBackendGetSettingIsIntegratedFunc) (CCSBackend *, CCSSetting * setting); +typedef Bool (*CCSBackendGetSettingIsReadOnlyFunc) (CCSBackend *, CCSSetting * setting); -struct _CCSBackendVTable +typedef CCSStringList (*CCSBackendGetExistingProfilesFunc) (CCSBackend *, CCSContext * context); +typedef Bool (*CCSBackendDeleteProfileFunc) (CCSBackend *, CCSContext * context, char * name); + +typedef void (*CCSBackendSetIntegration) (CCSBackend *, CCSIntegration *); + +typedef const CCSBackendInfo * (*CCSBackendGetInfoFunc) (CCSBackend *); + +struct _CCSBackendInterface { - char *name; - char *shortDesc; - char *longDesc; - Bool integrationSupport; - Bool profileSupport; + CCSBackendGetInfoFunc backendGetInfo; /* something like a event loop call for the backend, so it can check for file changes (gconf changes in the gconf backend) no need for reload settings signals anymore */ - CCSExecuteEventsFunc executeEvents; + CCSBackendExecuteEventsFunc executeEvents; - CCSInitBackendFunc backendInit; - CCSFiniBackendFunc backendFini; + CCSBackendInitFunc backendInit; + CCSBackendFiniFunc backendFini; - CCSContextReadInitFunc readInit; - CCSContextReadSettingFunc readSetting; - CCSContextReadDoneFunc readDone; + CCSBackendReadInitFunc readInit; + CCSBackendReadSettingFunc readSetting; + CCSBackendReadDoneFunc readDone; - CCSContextWriteInitFunc writeInit; - CCSContextWriteSettingFunc writeSetting; - CCSContextWriteDoneFunc writeDone; + CCSBackendWriteInitFunc writeInit; + CCSBackendWriteSettingFunc writeSetting; + CCSBackendWriteDoneFunc writeDone; + CCSBackendUpdateFunc updateSetting; - CCSGetIsIntegratedFunc getSettingIsIntegrated; - CCSGetIsReadOnlyFunc getSettingIsReadOnly; + CCSBackendGetSettingIsIntegratedFunc getSettingIsIntegrated; + CCSBackendGetSettingIsReadOnlyFunc getSettingIsReadOnly; - CCSGetExistingProfilesFunc getExistingProfiles; - CCSDeleteProfileFunc deleteProfile; + CCSBackendGetExistingProfilesFunc getExistingProfiles; + CCSBackendDeleteProfileFunc deleteProfile; + CCSBackendSetIntegration setIntegration; }; -CCSBackendVTable* getBackendInfo (void); +unsigned int ccsCCSBackendInterfaceGetType (); + +/** + * @brief ccsBackendGetInfo + * @param backend a CCSBackend * + * @return a const CCSBackendInfo * for this backend + * + * This function returns some basic info about this backend, what its + * name is, what it suppoirts etc + */ +const CCSBackendInfo * ccsBackendGetInfo (CCSBackend *backend); + +/** + * @brief ccsBackendExecuteEvents + * @param backend a CCSBackend * + * @param flags ProcessEventsGlibMainLoopMask or 0 + * + * something like a event loop call for the backend, + * so it can check for file changes (gconf changes in the gconf backend) + */ +void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags); + +/** + * @brief ccsBackendInit + * @param backend + * @param context + * @return + * + * Initializes a backend for a context + */ +Bool ccsBackendInit (CCSBackend *backend, CCSContext *context); + +/** + * @brief ccsBackendFini + * @param backend + * @param context + * @return + * + * Cleans up the backend + */ +Bool ccsBackendFini (CCSBackend *backend); +Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context); +void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); +void ccsBackendReadDone (CCSBackend *backend, CCSContext *context); +Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context); +void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting); +void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context); + +/** + * @brief ccsBackendUpdateSetting + * @param backend The backend on which the update should be processed + * @param context The context on which the backend resides. + * @param plugin The plugin for the setting + * @param setting The setting itself. + * + * This causes the specified setting to be re-read from the configuration + * database and re-written to any integrated keys. It should genrally + * be called by calback functions which know that the value + * has changed. + */ +void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting); +Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting); +Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting); + +/** + * @brief ccsBackendGetExistingProfiles + * @param backend + * @param context + * @return a CCSStringist of available profiles for this backend + */ +CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context); +Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name); +void ccsBackendSetIntegration (CCSBackend *backend, CCSIntegration *integration); +void ccsFreeBackend (CCSBackend *backend); + +typedef struct _CCSDynamicBackend CCSDynamicBackend; +typedef struct _CCSDynamicBackendPrivate CCSDynamicBackendPrivate; +typedef struct _CCSDynamicBackendInterface CCSDynamicBackendInterface; +typedef struct _CCSInterfaceTable CCSInterfaceTable; + +/** + * @brief The _CCSDynamicBackend struct + * + * This object represents a CCSBackend loaded in memory as a dlopen + * object. It implements the CCSBackend interface and provides an + * interface of its own for managing the dynamic backend and checking + * its capabilities. + * + * All function pointers are fully implemented and are safe to call + */ +struct _CCSDynamicBackend +{ + CCSObject object; +}; + +typedef const char * (*CCSDynamicBackendGetBackendName) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsRead) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsWrite) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsProfiles) (CCSDynamicBackend *); +typedef Bool (*CCSDynamicBackendSupportsIntegration) (CCSDynamicBackend *); +typedef CCSBackend * (*CCSDynamicBackendGetRawBackend) (CCSDynamicBackend *); + +struct _CCSDynamicBackendInterface +{ + CCSDynamicBackendGetBackendName getBackendName; + CCSDynamicBackendSupportsRead supportsRead; + CCSDynamicBackendSupportsWrite supportsWrite; + CCSDynamicBackendSupportsProfiles supportsProfiles; + CCSDynamicBackendSupportsIntegration supportsIntegration; + CCSDynamicBackendGetRawBackend getRawBackend; +}; + +const char * ccsDynamicBackendGetBackendName (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *); +Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *); +CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *); + +unsigned int ccsCCSDynamicBackendInterfaceGetType (); + +void ccsFreeDynamicBackend (CCSDynamicBackend *); + +/** + * @brief ccsOpenBackend + * @param name the name of the backend to open + * @param interface storage for this backend's interface + * @return a dlopen handle for this backend + */ +CCSBackend * ccsOpenBackend (const CCSInterfaceTable *, CCSContext *context, const char *name); + +/** + * @brief ccsBackendNewWithDynamicInterface + * @param context + * @param interface + * @param dlhand + * @return + * + * Creates a new CCSBackend for a CCSBackendInterface and dlopen handle + * dlhand + */ +CCSBackend * +ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface); + +CCSBackendInterface* getBackendInfo (void); + +COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/include/ccs-defs.h b/compizconfig/libcompizconfig/include/ccs-defs.h new file mode 100644 index 0000000000000000000000000000000000000000..c63c6570829938a6990c622aab3d730f7ee48581 --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-defs.h @@ -0,0 +1,93 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_DEFS_H +#define _CCS_DEFS_H + +#include /* for NULL */ + +#ifdef __cplusplus +# define COMPIZCONFIG_BEGIN_DECLS extern "C" { +# define COMPIZCONFIG_END_DECLS } +#else +# define COMPIZCONFIG_BEGIN_DECLS +# define COMPIZCONFIG_END_DECLS +#endif + + +COMPIZCONFIG_BEGIN_DECLS + +#ifndef Bool +#define Bool int +#endif + +#ifndef TRUE +#define TRUE ~0 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +/** + * reference counting + * + * ccsSettingRef + * References the settings object so it can be kept in a list and + * unreferenced later with freeObj (mixed with objects that need + * to be freed and need not be freed) + * + * ccsSettingUnref + * Unreferences the settings object, when the reference count reaches + * zero, the object is freed + * + */ + +#define CCSREF_HDR(type,dtype) \ + void ccs##type##Ref (dtype *); \ + void ccs##type##Unref (dtype *); + +#define CCSREF_OBJ(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + ccsObjectRef (d); \ + } \ + \ + void ccs##type##Unref (dtype *d) \ + { \ + ccsObjectUnref (d, ccsFree##type); \ + } \ + +#define CCSREF(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + d->refCount++; \ + } \ + void ccs##type##Unref (dtype *d) \ + { \ + d->refCount--; \ + if (d->refCount == 0) \ + ccsFree##type (d); \ + } \ + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-list.h b/compizconfig/libcompizconfig/include/ccs-list.h new file mode 100644 index 0000000000000000000000000000000000000000..9e758223f346cd0fd620ee79b830262ada50b9ea --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-list.h @@ -0,0 +1,85 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_LIST_H +#define _CCS_LIST_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +/** + * list functions: + * for each list there is a set of functions, explained using String as example + * + * ccsStringListAppend (list, item) + * Adds an item at the end of the list. Returns the new list. + * + * ccsStringListPrepend (list, item) + * Adds an item at the beginning of the list. Returns the new list. + * + * ccsStringListInsert (list, item, position) + * Adds an item at a given position. Position is 0-based. If position is + * larger than the amount of items in the list, the item is inserted at the + * end of the list. Returns the new list. + * + * ccsStringListInsertBefore (list, sibling, item) + * Inserts item before sibling into the list. If sibling is no list member, + * item is inserted at the end. Returns the new list. + * + * ccsStringListLength (list) + * Returns the amount of items in list. + * + * ccsStringListFind (list, item) + * Finds and returns an item matching . If nothing is found, returns NULL. + * + * ccsStringListGetItem (list, index) + * Returns the list item at position . If index is larger than the + * amount of items in the list, returns NULL. + * + * ccsStringListRemove (list, item, freeObj) + * Removes item from the list. If freeObj is TRUE, also frees the data item. + * Returns the new list. + * + * ccsStringListFree (list, freeObj) + * Frees the complete list. If freeObj is TRUE, also frees the data items. + * Returns the new list (NULL). + */ +#define CCSLIST_HDR(type,dtype) \ + typedef struct _CCS##type##List * CCS##type##List;\ + struct _CCS##type##List \ + { \ + dtype * data; \ + CCS##type##List next; \ + }; \ + CCS##type##List ccs##type##ListAppend (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListPrepend (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListInsert (CCS##type##List list, dtype *data, int position); \ + CCS##type##List ccs##type##ListInsertBefore (CCS##type##List list, CCS##type##List sibling, dtype *data); \ + unsigned int ccs##type##ListLength (CCS##type##List list); \ + CCS##type##List ccs##type##ListFind (CCS##type##List list, dtype *data); \ + CCS##type##List ccs##type##ListGetItem (CCS##type##List list, unsigned int index); \ + CCS##type##List ccs##type##ListRemove (CCS##type##List list, dtype *data, Bool freeObj); \ + CCS##type##List ccs##type##ListFree (CCS##type##List list, Bool freeObj); + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-object.h b/compizconfig/libcompizconfig/include/ccs-object.h new file mode 100644 index 0000000000000000000000000000000000000000..65ea4deac8251b742a484a297b02fff39d17bc88 --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-object.h @@ -0,0 +1,215 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2012 Canonical Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authored By: Sam Spilsbury + */ + +#ifndef _CCS_OBJECT_H +#define _CCS_OBJECT_H + +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ +typedef struct _CCSPrivate CCSPrivate; /* Dummy typedef */ +typedef struct _CCSObject CCSObject; + +typedef void * (*reallocObjectProc) (void *, void *, size_t); +typedef void * (*mallocObjectProc) (void *, size_t); +typedef void * (*callocObjectProc) (void *, size_t, size_t); +typedef void (*freeObjectProc) (void *, void *); + +/** + * An interface which specifies how objects should be allocated + * + * The purpose of this interface is to provide wrappers around + * the standard realloc, malloc, calloc and free functions. + * + * ccsObjectInit takes this allocation interface as a means of + * being able to test what happens when an allocation fails. + * + * Any other objects which implement CCSObject should also take + * this interface and pass it to ccsObjectInit. They should also + * use this interface as a means to allocate their own data so + * that tests for those objects can test allocation failures + */ +typedef struct _CCSObjectAllocationInterface +{ + reallocObjectProc realloc_; + mallocObjectProc malloc_; + callocObjectProc calloc_; + freeObjectProc free_; + void *allocator; +} CCSObjectAllocationInterface; + +extern CCSObjectAllocationInterface ccsDefaultObjectAllocator; + +/** + * + * CCSObject - a generic C based object + * + * CCSObject is a generic C based object system for compizconfig. + * Any structure that wishes to behave in an object oriented way + * should have a CCSObject as its first and only member, and with + * the name "object". (The macros that use CCSObject require this + * in order to use it safely). + * + * CCSObject only provides two facilites to clients - implementation + * of interfaces (which are just structs of function pointers) and + * private data storage. + * + * They can also be refcounted, however, this is only ever done safely + * if the object implements a virtual destructor method in its interface + * so that the macro CCSREF_OBJ knows what to destroy first. + * + * CCSObjects must be initialized before they are used. This can be + * done by calling ccsObjectInit and passing in the allocated memory + * block containing the object and a CCSObjectAllocationInterface * which + * ccsObjectInit will store in the object and use for all future + * allocations. + * + * Objects can implement interfaces by storing a struct of function pointers + * pertaining to that interface associated with that interface's unique type + * id generated at runtime. Eg + * + * ccsObjectAddInterface (object, (const CCSInterface *) &interface, + * GET_INTERFACE_TYPE (Interface)); + * + * Then you can retreive that interface and access its methods as follows: + * + * GET_INTERFACE (Interface, object)->method + * + * Objects also have one pointer available for private storage. It is + * recommended that all nonvirtual data lives in such storage. Add + * a private using: + * + * ccsObjectSetPrivate (object, (CCSPrivate *) priv); + * + * Setting a private member does NOT free the existing private member if + * it is set. It is the object's responsibility to do this if it wishes + * to set a new private member, or set the existing one to NULL. + * + * To finalize an object and free all related data, use ccsObjectFinalize + * + * ccsObjectFinalize (object); + * + * This will free all private data, interface arrays and other data + * using the provided CCSObjectAllocationInterface on ccsObjectInit. + */ +struct _CCSObject +{ + CCSPrivate *priv; /* Private pointer for object storage */ + + const CCSInterface **interfaces; /* An array of interfaces that this object implements */ + int *interface_types; /* An array of interface types */ + unsigned int n_interfaces; + unsigned int n_allocated_interfaces; + + CCSObjectAllocationInterface *object_allocation; + + unsigned int refcnt; /* Reference count of this object */ +}; + +Bool +ccsObjectInit_ (CCSObject *object, CCSObjectAllocationInterface *interface); + +#define ccsObjectInit(o, interface) (ccsObjectInit_) (&(o)->object, interface) + +Bool +ccsObjectAddInterface_ (CCSObject *object, const CCSInterface *interface, int interface_type); + +#define ccsObjectAddInterface(o, interface, type) (ccsObjectAddInterface_) (&(o)->object, interface, type); + +Bool +ccsObjectRemoveInterface_ (CCSObject *object, int interface_type); + +#define ccsObjectRemoveInterface(o, interface_type) (ccsObjectRemoveInterface_) (&(o)->object, interface_type); + +const CCSInterface * ccsObjectGetInterface_ (CCSObject *object, int interface_type); + +#define ccsObjectGetInterface(o, interface_type) (ccsObjectGetInterface_) (&(o)->object, interface_type) + +#define ccsObjectRef(o) \ + do { ((o)->object).refcnt++; } while (FALSE) + +#define ccsObjectUnref(o, freeFunc) \ + do \ + { \ + ((o)->object).refcnt--; \ + if (!((o)->object).refcnt) \ + freeFunc (o); \ + } while (FALSE) + +CCSPrivate * +ccsObjectGetPrivate_ (CCSObject *object); + +#define ccsObjectGetPrivate(o) (ccsObjectGetPrivate_) (&(o)->object) + +void +ccsObjectSetPrivate_ (CCSObject *object, CCSPrivate *priv); + +#define ccsObjectSetPrivate(o, priv) (ccsObjectSetPrivate_) (&(o)->object, priv) + +void +ccsObjectFinalize_ (CCSObject *object); + +#define ccsObjectFinalize(o) (ccsObjectFinalize_) (&(o)->object) + +/** + * Internal method to allocate a type. + * + * @brief ccsAllocateType + * @return a new type + */ +unsigned int +ccsAllocateType (); + +#define GET_INTERFACE_TYPE(Interface) \ + ccs##Interface##GetType () + +/** + * Used to define a new interface type - you should do this if any CCSObject + * is to implement this interface */ +#define INTERFACE_TYPE(Interface) \ + unsigned int ccs##Interface##GetType () \ + { \ + static unsigned int type_id = 0; \ + if (!type_id) \ + type_id = ccsAllocateType (); \ + \ + return type_id; \ + } + +#define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) + +#define CCSREF_OBJ(type,dtype) \ + void ccs##type##Ref (dtype *d) \ + { \ + ccsObjectRef (d); \ + } \ + \ + void ccs##type##Unref (dtype *d) \ + { \ + ccsObjectUnref (d, ccsFree##type); \ + } \ + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-setting-types.h b/compizconfig/libcompizconfig/include/ccs-setting-types.h new file mode 100644 index 0000000000000000000000000000000000000000..b8cca0da3213cf33b21d96512b7dc3c39fa4485e --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-setting-types.h @@ -0,0 +1,50 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef _COMPIZCONFIG_CCS_SETTING_TYPES +#define _COMPIZCONFIG_CCS_SETTING_TYPES + +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef enum _CCSSettingType +{ + /* This needs to be in the same order as CompOptionType for consistency */ + TypeBool, + TypeInt, + TypeFloat, + TypeString, + TypeColor, + TypeAction, + TypeKey, + TypeButton, + TypeEdge, + TypeBell, + TypeMatch, + TypeList, + TypeNum +} CCSSettingType; + +COMPIZCONFIG_END_DECLS + +#endif diff --git a/compizconfig/libcompizconfig/include/ccs-string.h b/compizconfig/libcompizconfig/include/ccs-string.h new file mode 100644 index 0000000000000000000000000000000000000000..48dabde5e5a23f3733f61aaf4431dcd55c2286fa --- /dev/null +++ b/compizconfig/libcompizconfig/include/ccs-string.h @@ -0,0 +1,47 @@ +/* + * Compiz configuration system library + * + * Copyright (C) 2007 Dennis Kasprzyk + * Copyright (C) 2007 Danny Baumann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library 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 + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _CCS_STRING_H +#define _CCS_STRING_H + +/* Doesn't seem to make sense to have this header + * dependency, but we can only declare a typed list + * once */ +#include + +COMPIZCONFIG_BEGIN_DECLS + +typedef struct _CCSString CCSString; + +struct _CCSString +{ + char *value; + unsigned int refCount; +}; + +void ccsFreeString (CCSString *str); + +CCSLIST_HDR (String, CCSString); + +COMPIZCONFIG_END_DECLS + +#endif + diff --git a/compizconfig/libcompizconfig/include/ccs.h b/compizconfig/libcompizconfig/include/ccs.h index dafc505f06f3345fe4bc562bd18818ea957a3b19..31e1743035154dbabec4385fa0d829584ea2f3dd 100644 --- a/compizconfig/libcompizconfig/include/ccs.h +++ b/compizconfig/libcompizconfig/include/ccs.h @@ -23,23 +23,14 @@ #define _CSS_H #include /* for NULL */ +#include +#include +#include +#include +#include +#include -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifndef Bool -#define Bool int -#endif - -#ifndef TRUE -#define TRUE ~0 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif +COMPIZCONFIG_BEGIN_DECLS #ifndef CCS_LOG_DOMAIN #define CCS_LOG_DOMAIN NULL @@ -78,60 +69,6 @@ typedef enum void ccsLog (const char *domain, CCSLogLevel level, const char *fmt, ...); -/** - * list functions: - * for each list there is a set of functions, explained using String as example - * - * ccsStringListAppend (list, item) - * Adds an item at the end of the list. Returns the new list. - * - * ccsStringListPrepend (list, item) - * Adds an item at the beginning of the list. Returns the new list. - * - * ccsStringListInsert (list, item, position) - * Adds an item at a given position. Position is 0-based. If position is - * larger than the amount of items in the list, the item is inserted at the - * end of the list. Returns the new list. - * - * ccsStringListInsertBefore (list, sibling, item) - * Inserts item before sibling into the list. If sibling is no list member, - * item is inserted at the end. Returns the new list. - * - * ccsStringListLength (list) - * Returns the amount of items in list. - * - * ccsStringListFind (list, item) - * Finds and returns an item matching . If nothing is found, returns NULL. - * - * ccsStringListGetItem (list, index) - * Returns the list item at position . If index is larger than the - * amount of items in the list, returns NULL. - * - * ccsStringListRemove (list, item, freeObj) - * Removes item from the list. If freeObj is TRUE, also frees the data item. - * Returns the new list. - * - * ccsStringListFree (list, freeObj) - * Frees the complete list. If freeObj is TRUE, also frees the data items. - * Returns the new list (NULL). - */ -#define CCSLIST_HDR(type,dtype) \ - typedef struct _CCS##type##List * CCS##type##List;\ - struct _CCS##type##List \ - { \ - dtype * data; \ - CCS##type##List next; \ - }; \ - CCS##type##List ccs##type##ListAppend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListPrepend (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListInsert (CCS##type##List list, dtype *data, int position); \ - CCS##type##List ccs##type##ListInsertBefore (CCS##type##List list, CCS##type##List sibling, dtype *data); \ - unsigned int ccs##type##ListLength (CCS##type##List list); \ - CCS##type##List ccs##type##ListFind (CCS##type##List list, dtype *data); \ - CCS##type##List ccs##type##ListGetItem (CCS##type##List list, unsigned int index); \ - CCS##type##List ccs##type##ListRemove (CCS##type##List list, dtype *data, Bool freeObj); \ - CCS##type##List ccs##type##ListFree (CCS##type##List list, Bool freeObj); - typedef struct _CCSContext CCSContext; typedef struct _CCSPlugin CCSPlugin; typedef struct _CCSSetting CCSSetting; @@ -144,11 +81,9 @@ typedef struct _CCSBackendInfo CCSBackendInfo; typedef struct _CCSIntDesc CCSIntDesc; typedef struct _CCSStrRestriction CCSStrRestriction; typedef struct _CCSStrExtension CCSStrExtension; -typedef struct _CCSString CCSString; CCSLIST_HDR (Plugin, CCSPlugin) CCSLIST_HDR (Setting, CCSSetting) -CCSLIST_HDR (String, CCSString) CCSLIST_HDR (Group, CCSGroup) CCSLIST_HDR (SubGroup, CCSSubGroup) CCSLIST_HDR (SettingValue, CCSSettingValue) @@ -158,124 +93,10 @@ CCSLIST_HDR (IntDesc, CCSIntDesc) CCSLIST_HDR (StrRestriction, CCSStrRestriction) CCSLIST_HDR (StrExtension, CCSStrExtension) -typedef struct _CCSInterface CCSInterface; /* Dummy typedef */ -typedef struct _CCSPrivate CCSPrivate; /* Dummy typedef */ -typedef struct _CCSObject CCSObject; - -typedef void * (*reallocObjectProc) (void *, void *, size_t); -typedef void * (*mallocObjectProc) (void *, size_t); -typedef void * (*callocObjectProc) (void *, size_t, size_t); -typedef void (*freeObjectProc) (void *, void *); - -typedef struct _CCSObjectAllocationInterface -{ - reallocObjectProc realloc_; - mallocObjectProc malloc_; - callocObjectProc calloc_; - freeObjectProc free_; - void *allocator; -} CCSObjectAllocationInterface; - -extern CCSObjectAllocationInterface ccsDefaultObjectAllocator; - -struct _CCSObject -{ - CCSPrivate *priv; /* Private pointer for object storage */ - - const CCSInterface **interfaces; /* An array of interfaces that this object implements */ - int *interface_types; /* An array of interface types */ - unsigned int n_interfaces; - unsigned int n_allocated_interfaces; - - CCSObjectAllocationInterface *object_allocation; - - unsigned int refcnt; /* Reference count of this object */ -}; - -Bool -ccsObjectInit_ (CCSObject *object, CCSObjectAllocationInterface *interface); - -#define ccsObjectInit(o, interface) (ccsObjectInit_) (&(o)->object, interface) - -Bool -ccsObjectAddInterface_ (CCSObject *object, const CCSInterface *interface, int interface_type); - -#define ccsObjectAddInterface(o, interface, type) (ccsObjectAddInterface_) (&(o)->object, interface, type); - -Bool -ccsObjectRemoveInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectRemoveInterface(o, interface_type) (ccsObjectRemoveInterface_) (&(o)->object, interface_type); - -const CCSInterface * ccsObjectGetInterface_ (CCSObject *object, int interface_type); - -#define ccsObjectGetInterface(o, interface_type) (ccsObjectGetInterface_) (&(o)->object, interface_type) - -#define ccsObjectRef(o) \ - do { ((o)->object).refcnt++; } while (FALSE) - -#define ccsObjectUnref(o, freeFunc) \ - do \ - { \ - ((o)->object).refcnt--; \ - if (!((o)->object).refcnt) \ - freeFunc (o); \ - } while (FALSE) - -CCSPrivate * -ccsObjectGetPrivate_ (CCSObject *object); - -#define ccsObjectGetPrivate(o) (ccsObjectGetPrivate_) (&(o)->object) - -void -ccsObjectSetPrivate_ (CCSObject *object, CCSPrivate *priv); - -#define ccsObjectSetPrivate(o, priv) (ccsObjectSetPrivate_) (&(o)->object, priv) - -void -ccsObjectFinalize_ (CCSObject *object); - -#define ccsObjectFinalize(o) (ccsObjectFinalize_) (&(o)->object) - -unsigned int -ccsAllocateType (); - -#define GET_INTERFACE_TYPE(Interface) \ - ccs##Interface##GetType () - -#define INTERFACE_TYPE(Interface) \ - unsigned int ccs##Interface##GetType () \ - { \ - static unsigned int type_id = 0; \ - if (!type_id) \ - type_id = ccsAllocateType (); \ - \ - return type_id; \ - } - -#define GET_INTERFACE(CType, o) (CType *) ccsObjectGetInterface (o, GET_INTERFACE_TYPE(CType)) - -/** - * reference counting - * - * ccsSettingRef - * References the settings object so it can be kept in a list and - * unreferenced later with freeObj (mixed with objects that need - * to be freed and need not be freed) - * - * ccsSettingUnref - * Unreferences the settings object, when the reference count reaches - * zero, the object is freed - * - */ - -#define CCSREF_HDR(type,dtype) \ - void ccs##type##Ref (dtype *); \ - void ccs##type##Unref (dtype *); - CCSREF_HDR (Plugin, CCSPlugin) CCSREF_HDR (Setting, CCSSetting) CCSREF_HDR (String, CCSString) +CCSREF_HDR (Backend, CCSBackend) CCSREF_HDR (Group, CCSGroup) CCSREF_HDR (SubGroup, CCSSubGroup) CCSREF_HDR (SettingValue, CCSSettingValue) @@ -289,12 +110,15 @@ typedef struct _CCSInterfaceTable CCSInterfaceTable; typedef struct _CCSContextInterface CCSContextInterface; typedef struct _CCSPluginInterface CCSPluginInterface; typedef struct _CCSSettingInterface CCSSettingInterface; +typedef struct _CCSDynamicBackendInterface CCSDynamicBackendInterface; struct _CCSInterfaceTable { const CCSContextInterface *contextInterface; const CCSPluginInterface *pluginInterface; const CCSSettingInterface *settingInterface; + const CCSBackendInterface *dynamicBackendWrapperInterface; + const CCSDynamicBackendInterface *dynamicBackendInterface; }; extern const CCSInterfaceTable ccsDefaultInterfaceTable; @@ -315,11 +139,11 @@ typedef Bool (*CCSContextPluginIsActive) (CCSContext *context, char *name); typedef CCSPluginList (*CCSContextGetActivePluginList) (CCSContext *context); typedef CCSStringList (*CCSContextGetSortedPluginStringList) (CCSContext *context); typedef Bool (*CCSContextSetBackend) (CCSContext *context, char *name); -typedef char * (*CCSContextGetBackend) (CCSContext *context); +typedef const char * (*CCSContextGetBackend) (CCSContext *context); typedef void (*CCSContextSetIntegrationEnabled) (CCSContext *context, Bool value); typedef void (*CCSContextSetProfile) (CCSContext *context, char *name); typedef void (*CCSContextSetPluginListAutoSort) (CCSContext *context, Bool value); -typedef char * (*CCSContextGetProfile) (CCSContext *context); +typedef const char * (*CCSContextGetProfile) (CCSContext *context); typedef Bool (*CCSContextGetIntegrationEnabled) (CCSContext *context); typedef Bool (*CCSContextGetPluginListAutoSort) (CCSContext *context); typedef void (*CCSContextProcessEvents) (CCSContext *context, unsigned int flags); @@ -334,6 +158,7 @@ typedef CCSStringList (*CCSContextGetExistingProfiles) (CCSContext *context); typedef void (*CCSContextDeleteProfile) (CCSContext *context, char *name); typedef Bool (*CCSContextCheckForSettingsUpgrade) (CCSContext *context); typedef void (*CCSContextLoadPlugins) (CCSContext *context); +typedef void (*CCSContextDestructor) (CCSContext *context); struct _CCSContextInterface { @@ -371,6 +196,7 @@ struct _CCSContextInterface CCSContextDeleteProfile contextDeleteProfile; CCSContextCheckForSettingsUpgrade contextCheckForSettingsUpgrade; CCSContextLoadPlugins contextLoadPlugins; + CCSContextDestructor contextDestructor; }; unsigned int ccsCCSContextInterfaceGetType (); @@ -396,16 +222,6 @@ struct _CCSContext CCSObject object; }; -struct _CCSBackendInfo -{ - char *name; /* name of the backend */ - char *shortDesc; /* backend's short description */ - char *longDesc; /* backend's long description */ - Bool integrationSupport; /* does the backend support DE integration? */ - Bool profileSupport; /* does the backend support profiles? */ - unsigned int refCount; /* reference count */ -}; - /* CCSPluginInterface */ typedef char * (*CCSPluginGetName) (CCSPlugin *plugin); typedef char * (*CCSPluginGetShortDesc) (CCSPlugin *plugin); @@ -431,6 +247,8 @@ typedef CCSGroupList (*CCSPluginGetPluginGroups) (CCSPlugin *plugin); typedef void (*CCSPluginReadPluginSettings) (CCSPlugin *plugin); typedef CCSStrExtensionList (*CCSPluginGetPluginStrExtensions) (CCSPlugin *plugin); +typedef void (*CCSPluginDestructor) (CCSPlugin *plugin); + unsigned int ccsCCSPluginInterfaceGetType (); struct _CCSPluginInterface @@ -454,6 +272,7 @@ struct _CCSPluginInterface CCSPluginGetPluginGroups pluginGetPluginGroups; CCSPluginReadPluginSettings pluginReadPluginSettings; CCSPluginGetPluginStrExtensions pluginGetPluginStrExtensions; + CCSPluginDestructor pluginDestructor; }; /* CCSPlugin accessor functions */ @@ -482,24 +301,6 @@ struct _CCSPlugin CCSObject object; }; -typedef enum _CCSSettingType -{ - /* This needs to be in the same order as CompOptionType for consistency */ - TypeBool, - TypeInt, - TypeFloat, - TypeString, - TypeColor, - TypeAction, - TypeKey, - TypeButton, - TypeEdge, - TypeBell, - TypeMatch, - TypeList, - TypeNum -} CCSSettingType; - struct _CCSSubGroup { char *name; /* sub group name in current locale */ @@ -538,12 +339,6 @@ struct _CCSPluginConflict union _CCSSettingInfo; -struct _CCSString -{ - char *value; - unsigned int refCount; -}; - struct _CCSIntDesc { int value; /* value the description is assigned to */ @@ -760,6 +555,9 @@ Bool ccsSettingIsIntegrated (CCSSetting *setting); /* Checks if a given setting is read-only. */ Bool ccsSettingIsReadOnly (CCSSetting *setting); +/* Checks if a setting is readable by backends */ +Bool ccsSettingIsReadableByBackend (CCSSetting *setting); + typedef char * (*CCSSettingGetName) (CCSSetting *); typedef char * (*CCSSettingGetShortDesc) (CCSSetting *); typedef char * (*CCSSettingGetLongDesc) (CCSSetting *); @@ -800,6 +598,7 @@ typedef Bool (*CCSSettingGetList) (CCSSetting *setting, CCSSettingValueList *dat typedef void (*CCSSettingResetToDefault) (CCSSetting *setting, Bool processChanged); typedef Bool (*CCSSettingIsIntegrated) (CCSSetting *setting); typedef Bool (*CCSSettingIsReadOnly) (CCSSetting *setting); +typedef Bool (*CCSSettingIsReadableByBackend) (CCSSetting *setting); typedef void (*CCSSettingDestructor) (CCSSetting *setting); unsigned int ccsCCSSettingInterfaceGetType (); @@ -846,6 +645,7 @@ struct _CCSSettingInterface CCSSettingResetToDefault settingResetToDefault; CCSSettingIsIntegrated settingIsIntegrated; CCSSettingIsReadOnly settingIsReadOnly; + CCSSettingIsReadableByBackend settingIsReadableByBackend; CCSSettingDestructor settingDestructor; }; @@ -906,12 +706,13 @@ void ccsFreeSetting (CCSSetting *setting); void ccsFreeGroup (CCSGroup *group); void ccsFreeSubGroup (CCSSubGroup *subGroup); void ccsFreeSettingValue (CCSSettingValue *value); +void ccsFreeSettingValueWithType (CCSSettingValue *v, + CCSSettingType type); void ccsFreePluginConflict (CCSPluginConflict *value); void ccsFreeBackendInfo (CCSBackendInfo *value); void ccsFreeIntDesc (CCSIntDesc *value); void ccsFreeStrRestriction (CCSStrRestriction *restriction); void ccsFreeStrExtension (CCSStrExtension *extension); -void ccsFreeString (CCSString *str); @@ -924,6 +725,10 @@ Bool ccsIsEqualKey (CCSSettingKeyValue c1, Bool ccsIsEqualButton (CCSSettingButtonValue c1, CCSSettingButtonValue c2); +/* Compares lists */ +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, + CCSSettingListInfo info); + /* Retrieves a list of settings in a plugin */ CCSSettingList ccsGetPluginSettings (CCSPlugin *plugin); @@ -964,12 +769,16 @@ Bool * ccsGetBoolArrayFromValueList (CCSSettingValueList list, CCSSettingColorValue* ccsGetColorArrayFromValueList (CCSSettingValueList list, int *num); +/* Deep copies value lists */ +CCSSettingValueList +ccsCopyList (CCSSettingValueList l1, CCSSetting * setting); + /* Converts an array of data items to a setting value list. Behaves similar to ccsGetListFromStringArray */ -CCSSettingValueList ccsGetValueListFromStringArray (char **array, +CCSSettingValueList ccsGetValueListFromStringArray (const char **array, int num, CCSSetting *parent); -CCSSettingValueList ccsGetValueListFromMatchArray (char **array, +CCSSettingValueList ccsGetValueListFromMatchArray (const char **array, int num, CCSSetting *parent); CCSSettingValueList ccsGetValueListFromIntArray (int *array, @@ -997,7 +806,7 @@ CCSStringList ccsGetSortedPluginStringList (CCSContext *context); Bool ccsSetBackend (CCSContext *context, char *name); /* Retrieves the name of the backend active for the context. */ -char * ccsGetBackend (CCSContext *context); +const char * ccsGetBackend (CCSContext *context); /* Enable/disable DE integration for a context. */ void ccsSetIntegrationEnabled (CCSContext *context, @@ -1012,7 +821,7 @@ void ccsSetPluginListAutoSort (CCSContext *context, Bool value); /* Retrieve current profile of the context. */ -char * ccsGetProfile (CCSContext *context); +const char * ccsGetProfile (CCSContext *context); /* Retrieves current DE integration status for a context */ Bool ccsGetIntegrationEnabled (CCSContext *context); @@ -1261,13 +1070,16 @@ CCSStringList ccsGetExistingProfiles (CCSContext * context); void ccsDeleteProfile (CCSContext *context, char *name); +/* Copies backend info out from backend */ +CCSBackendInfo * +ccsCopyBackendInfoFromBackend (CCSBackend *backend, + const CCSBackendInterface *backendInterface); + /* Enumerates the available backends. */ -CCSBackendInfoList ccsGetExistingBackends (void); +CCSBackendInfoList ccsGetExistingBackends (CCSContext *); CCSStrExtensionList ccsGetPluginStrExtensions (CCSPlugin *plugin); -#ifdef __cplusplus -} -#endif +COMPIZCONFIG_END_DECLS #endif diff --git a/compizconfig/libcompizconfig/src/CMakeLists.txt b/compizconfig/libcompizconfig/src/CMakeLists.txt index 919668a625e91cd85ad7793d34eab1836fb94924..4f308ac77c34edb95a6aa4080325ad2a44ec4542 100644 --- a/compizconfig/libcompizconfig/src/CMakeLists.txt +++ b/compizconfig/libcompizconfig/src/CMakeLists.txt @@ -68,6 +68,14 @@ target_link_libraries ( compizconfig ${LIBCOMPIZCONFIG_LIBRARIES} m ) +# +# Tell CMake that targets using compizconfig should NOT re-import the +# libraries that compizconfig depends on (contains). +# +set_target_properties (compizconfig PROPERTIES + LINK_INTERFACE_LIBRARIES "" +) + set (COMPIZCONFIG_LIBS "") foreach (_val ${LIBCOMPIZCONFIG_LDFLAGS}) set (COMPIZCONFIG_LIBS "${COMPIZCONFIG_LIBS}${_val} ") diff --git a/compizconfig/libcompizconfig/src/ccs-private.h b/compizconfig/libcompizconfig/src/ccs-private.h index c24cef8b3b3d6c4853a8e12fbb130e10877be889..d43353bbcdf49376d32b5370b348dd94417879ca 100644 --- a/compizconfig/libcompizconfig/src/ccs-private.h +++ b/compizconfig/libcompizconfig/src/ccs-private.h @@ -25,18 +25,14 @@ #include #include -#define CONTEXT_PRIV(c) \ - CCSContextPrivate *cPrivate = (CCSContextPrivate *) ccsObjectGetPrivate (c); -#define PLUGIN_PRIV(p) \ - CCSPluginPrivate *pPrivate = (CCSPluginPrivate *) ccsObjectGetPrivate (p); -#define SETTING_PRIV(s) \ - CCSSettingPrivate *sPrivate = (CCSSettingPrivate *) ccsObjectGetPrivate (s); +#define GET_PRIVATE(Private, obj) \ + (Private *) ccsObjectGetPrivate (obj); extern Bool basicMetadata; typedef struct _CCSContextPrivate { - CCSBackend *backend; + CCSDynamicBackend *backend; CCSPluginList plugins; /* list of plugins settings were loaded for */ CCSPluginCategory *categories; /* list of plugin categories */ @@ -120,6 +116,12 @@ typedef struct _CCSSettingPrivate void *privatePtr; /* private pointer for usage by the caller */ } CCSSettingPrivate; +typedef struct _CCSDynamicBackendPrivate +{ + void *dlhand; + CCSBackend *backend; +} CCSDynamicBackendPrivate; + typedef struct _CCSSettingsUpgrade { char *profile; diff --git a/compizconfig/libcompizconfig/src/compiz.cpp b/compizconfig/libcompizconfig/src/compiz.cpp index ea4a723951240a66610208885356c61bb94805ec..0bc7965382a052121d013ac4c726ee02d9e2b408 100644 --- a/compizconfig/libcompizconfig/src/compiz.cpp +++ b/compizconfig/libcompizconfig/src/compiz.cpp @@ -561,7 +561,8 @@ addOptionForPluginPB (CCSPlugin * plugin, return; } - CONTEXT_PRIV (ccsPluginGetContext (plugin)); + CCSContext *context = ccsPluginGetContext (plugin); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); setting = (CCSSetting *) calloc (1, sizeof (CCSSetting)); @@ -582,7 +583,7 @@ addOptionForPluginPB (CCSPlugin * plugin, ccsObjectAddInterface (setting, (CCSInterface *) cPrivate->object_interfaces->settingInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); ccsSettingRef (setting); - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); sPrivate->parent = plugin; sPrivate->isDefault = TRUE; @@ -716,7 +717,7 @@ addOptionForPluginPB (CCSPlugin * plugin, } } - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); pPrivate->settings = ccsSettingListAppend (pPrivate->settings, setting); } @@ -818,7 +819,7 @@ addStringExtensionFromPB (CCSPlugin * plugin, ccsAddRestrictionToStringExtension (extension, name, value); } - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); pPrivate->stringExtensions = ccsStrExtensionListAppend (pPrivate->stringExtensions, extension); @@ -838,7 +839,7 @@ initStringExtensionsFromPB (CCSPlugin * plugin, static void initRulesFromPB (CCSPlugin * plugin, const PluginInfoMetadata & pluginInfoPB) { - PLUGIN_PRIV (plugin) + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin) addStringsFromPB (&pPrivate->providesFeature, pluginInfoPB.feature ()); @@ -865,7 +866,7 @@ addPluginFromPB (CCSContext * context, CCSPlugin *plugin; CCSPluginPrivate *pPrivate; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); name = pluginInfoPB.name ().c_str (); @@ -949,7 +950,7 @@ addCoreSettingsFromPB (CCSContext * context, if (ccsFindPlugin (context, "core")) return; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); plugin = (CCSPlugin*) calloc (1, sizeof (CCSPlugin)); @@ -2021,7 +2022,8 @@ addOptionForPlugin (CCSPlugin * plugin, if (getOptionType (type) == TypeNum) return; - CONTEXT_PRIV (ccsPluginGetContext (plugin)); + CCSContext *context = ccsPluginGetContext (plugin); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); setting = (CCSSetting *) calloc (1, sizeof (CCSSetting)); @@ -2042,7 +2044,7 @@ addOptionForPlugin (CCSPlugin * plugin, ccsObjectAddInterface (setting, (CCSInterface *) cPrivate->object_interfaces->settingInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); ccsSettingRef (setting); - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) sPrivate->parent = plugin; sPrivate->isDefault = TRUE; @@ -2210,7 +2212,7 @@ addOptionForPlugin (CCSPlugin * plugin, return; } // printSetting (setting); - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); pPrivate->settings = ccsSettingListAppend (pPrivate->settings, setting); } @@ -2427,7 +2429,7 @@ addStringExtensionFromXMLNode (CCSPlugin * plugin, } free (nodes); - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); pPrivate->stringExtensions = ccsStrExtensionListAppend (pPrivate->stringExtensions, extension); @@ -2483,7 +2485,7 @@ initRulesFromRootNode (CCSPlugin * plugin, xmlNode * node, void * pluginInfoPBv) } #endif - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); addStringsFromPath (&pPrivate->providesFeature, "feature", node, featureListPBv); @@ -2529,7 +2531,7 @@ addPluginFromXMLNode (CCSContext * context, CCSPlugin *plugin; CCSPluginPrivate *pPrivate; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!node) return FALSE; @@ -2620,7 +2622,7 @@ addCoreSettingsFromXMLNode (CCSContext * context, CCSPlugin *plugin; CCSPluginPrivate *pPrivate; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!node) return FALSE; @@ -2811,7 +2813,7 @@ updatePBFilePath (CCSContext * context, char *name, char *pbFilePath) CCSPlugin *plugin = ccsFindPlugin (context, name); if (plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (pPrivate->pbFilePath) free (pPrivate->pbFilePath); @@ -2981,7 +2983,7 @@ addPluginNamed (CCSContext * context, char *name) CCSPlugin *plugin; CCSPluginPrivate *pPrivate; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (ccsFindPlugin (context, name)) return; @@ -3172,7 +3174,7 @@ loadOptionsStringExtensionsFromXML (CCSPlugin * plugin, void * pluginPBv, struct stat *xmlStat) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); xmlDoc *doc = NULL; xmlNode **nodes; @@ -3211,7 +3213,7 @@ ccsLoadPluginSettings (CCSPlugin * plugin) initPBLoading (); #endif - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (pPrivate->loaded) return; diff --git a/compizconfig/libcompizconfig/src/ini.c b/compizconfig/libcompizconfig/src/ini.c index 6e44619bb417033a0aac871621368ef9c53aedb0..1284e836bcda1e65ca31c3844078353ae0df80aa 100644 --- a/compizconfig/libcompizconfig/src/ini.c +++ b/compizconfig/libcompizconfig/src/ini.c @@ -397,7 +397,7 @@ ccsIniParseList (const char *str, token = strsep (&valueString, ";"); } - list = ccsGetValueListFromStringArray (array, nItems, parent); + list = ccsGetValueListFromStringArray ((const char **) array, nItems, parent); for (i = 0; i < nItems; i++) free (array[i]); diff --git a/compizconfig/libcompizconfig/src/lists.c b/compizconfig/libcompizconfig/src/lists.c index 1c80817825bf5561538f95fc4d38b8875a0062b1..2f374dea7d7807a18ff5292f507928f751c2b316 100644 --- a/compizconfig/libcompizconfig/src/lists.c +++ b/compizconfig/libcompizconfig/src/lists.c @@ -182,6 +182,7 @@ CCSLIST (BackendInfo, CCSBackendInfo, FALSE, 0) CCSLIST (IntDesc, CCSIntDesc, FALSE, 0) CCSLIST (StrRestriction, CCSStrRestriction, FALSE, 0) CCSLIST (StrExtension, CCSStrExtension, FALSE, 0) +CCSLIST (IntegratedSetting, CCSIntegratedSetting, FALSE, 0) CCSSettingValueList ccsGetValueListFromStringList (CCSStringList list, CCSSetting *parent) @@ -392,7 +393,7 @@ CCSSettingColorValue * ccsGetColorArrayFromValueList (CCSSettingValueList list, return rv; } -CCSSettingValueList ccsGetValueListFromStringArray (char ** array, int num, +CCSSettingValueList ccsGetValueListFromStringArray (const char ** array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; @@ -414,7 +415,7 @@ CCSSettingValueList ccsGetValueListFromStringArray (char ** array, int num, return l; } -CCSSettingValueList ccsGetValueListFromMatchArray (char ** array, int num, +CCSSettingValueList ccsGetValueListFromMatchArray (const char ** array, int num, CCSSetting *parent) { CCSSettingValueList l = NULL; diff --git a/compizconfig/libcompizconfig/src/main.c b/compizconfig/libcompizconfig/src/main.c index 1426125fb31aba3ad6b3b4382f3576e43701e456..32524f1174c669da07c4451e98b8ad9839a0a89d 100644 --- a/compizconfig/libcompizconfig/src/main.c +++ b/compizconfig/libcompizconfig/src/main.c @@ -231,6 +231,13 @@ ccsAllocateType () INTERFACE_TYPE (CCSContextInterface) INTERFACE_TYPE (CCSPluginInterface) INTERFACE_TYPE (CCSSettingInterface) +INTERFACE_TYPE (CCSBackendInterface); +INTERFACE_TYPE (CCSDynamicBackendInterface); +INTERFACE_TYPE (CCSIntegrationInterface); +INTERFACE_TYPE (CCSIntegratedSettingInfoInterface); +INTERFACE_TYPE (CCSIntegratedSettingInterface); +INTERFACE_TYPE (CCSIntegratedSettingsStorageInterface); +INTERFACE_TYPE (CCSIntegratedSettingFactoryInterface); Bool basicMetadata = FALSE; @@ -239,7 +246,6 @@ ccsSetBasicMetadata (Bool value) { basicMetadata = value; } - static void initGeneralOptions (CCSContext * context) { @@ -308,7 +314,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte ccsObjectSetPrivate (context, (CCSPrivate *) ccsPrivate); - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); cPrivate->object_interfaces = object_interfaces; cPrivate->screenNum = screenNum; @@ -319,11 +325,12 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte cPrivate->configWatchId = ccsAddConfigWatch (context, configChangeNotify); if (cPrivate->backend) - ccsInfo ("Backend : %s", cPrivate->backend->vTable->name); - ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); - ccsInfo ("Profile : %s", - (cPrivate->profile && strlen (cPrivate->profile)) ? - cPrivate->profile : "default"); + ccsInfo ("Backend : %s", ccsDynamicBackendGetBackendName (cPrivate->backend)); + + ccsInfo ("Integration : %s", cPrivate->deIntegration ? "true" : "false"); + ccsInfo ("Profile : %s", + (cPrivate->profile && strlen (cPrivate->profile)) ? + cPrivate->profile : "default"); return context; } @@ -331,7 +338,7 @@ ccsEmptyContextNew (unsigned int screenNum, const CCSInterfaceTable *object_inte static void * ccsContextGetPrivatePtrDefault (CCSContext *context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->privatePtr; } @@ -339,7 +346,7 @@ ccsContextGetPrivatePtrDefault (CCSContext *context) static void ccsContextSetPrivatePtrDefault (CCSContext *context, void *ptr) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); cPrivate->privatePtr = ptr; } @@ -347,7 +354,7 @@ ccsContextSetPrivatePtrDefault (CCSContext *context, void *ptr) static CCSPluginList ccsContextGetPluginsDefault (CCSContext *context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->plugins; } @@ -355,7 +362,7 @@ ccsContextGetPluginsDefault (CCSContext *context) static CCSPluginCategory * ccsContextGetCategoriesDefault (CCSContext *context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->categories; } @@ -363,7 +370,7 @@ ccsContextGetCategoriesDefault (CCSContext *context) static CCSSettingList ccsContextGetChangedSettingsDefault (CCSContext *context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->changedSettings; } @@ -371,7 +378,7 @@ ccsContextGetChangedSettingsDefault (CCSContext *context) static unsigned int ccsContextGetScreenNumDefault (CCSContext *context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->screenNum; } @@ -379,7 +386,7 @@ ccsContextGetScreenNumDefault (CCSContext *context) static Bool ccsContextAddChangedSettingDefault (CCSContext *context, CCSSetting *setting) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); cPrivate->changedSettings = ccsSettingListAppend (cPrivate->changedSettings, setting); @@ -389,7 +396,7 @@ ccsContextAddChangedSettingDefault (CCSContext *context, CCSSetting *setting) static Bool ccsContextClearChangedSettingsDefault (CCSContext *context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -399,7 +406,7 @@ ccsContextClearChangedSettingsDefault (CCSContext *context) static CCSSettingList ccsContextStealChangedSettingsDefault (CCSContext *context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); CCSSettingList l = cPrivate->changedSettings; @@ -486,11 +493,11 @@ ccsSetActivePluginList (CCSContext * context, CCSStringList list) CCSPluginList l; CCSPlugin *plugin; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); for (l = cPrivate->plugins; l; l = l->next) { - PLUGIN_PRIV (l->data); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, l->data); pPrivate->active = FALSE; } @@ -500,7 +507,7 @@ ccsSetActivePluginList (CCSContext * context, CCSStringList list) if (plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); pPrivate->active = TRUE; } } @@ -509,7 +516,7 @@ ccsSetActivePluginList (CCSContext * context, CCSStringList list) plugin = ccsFindPlugin (context, "core"); if (plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); pPrivate->active = TRUE; } } @@ -557,7 +564,7 @@ ccsFindPluginDefault (CCSContext * context, const char *name) if (!name) name = ""; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); CCSPluginList l = cPrivate->plugins; while (l) @@ -583,7 +590,7 @@ ccsFindSettingDefault (CCSPlugin * plugin, const char *name) if (!plugin) return NULL; - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (!name) name = ""; @@ -622,7 +629,7 @@ ccsPluginIsActiveDefault (CCSContext * context, char *name) if (!plugin) return FALSE; - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->active; } @@ -702,12 +709,21 @@ collateGroups (CCSPluginPrivate * p) } void -ccsFreeContext (CCSContext * c) +ccsFreeContext (CCSContext *c) { if (!c) return; - CONTEXT_PRIV (c); + (*(GET_INTERFACE (CCSContextInterface, c))->contextDestructor) (c); +} + +static void +ccsFreeContextDefault (CCSContext * c) +{ + if (!c) + return; + + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, c); if (cPrivate->profile) free (cPrivate->profile); @@ -725,12 +741,21 @@ ccsFreeContext (CCSContext * c) } void -ccsFreePlugin (CCSPlugin * p) +ccsFreePlugin (CCSPlugin *p) +{ + if (!p) + return; + + (*(GET_INTERFACE (CCSPluginInterface, p))->pluginDestructor) (p); +} + +static void +ccsFreePluginDefault (CCSPlugin * p) { if (!p) return; - PLUGIN_PRIV (p); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, p); free (pPrivate->name); free (pPrivate->shortDesc); @@ -768,7 +793,7 @@ ccsFreePlugin (CCSPlugin * p) static void ccsFreeSettingDefault (CCSSetting *s) { - SETTING_PRIV (s); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, s); free (sPrivate->name); free (sPrivate->shortDesc); @@ -838,20 +863,10 @@ ccsFreeSubGroup (CCSSubGroup * s) free (s); } -void -ccsFreeSettingValue (CCSSettingValue * v) +static void +ccsFreeSettingValueCommon (CCSSettingValue *v, + CCSSettingType type) { - if (!v) - return; - - if (!v->parent) - return; - - CCSSettingType type = ccsSettingGetType (v->parent); - - if (v->isListChild) - type = ccsSettingGetInfo (v->parent)->forList.listType; - switch (type) { case TypeString: @@ -867,11 +882,40 @@ ccsFreeSettingValue (CCSSettingValue * v) default: break; } +} + +void +ccsFreeSettingValue (CCSSettingValue * v) +{ + if (!v) + return; + + if (!v->parent) + { + ccsError ("cannot free value without parent - use ccsFreeSettingValueWithType and specify type instead"); + return; + } + + CCSSettingType type = ccsSettingGetType (v->parent); + + if (v->isListChild) + type = ccsSettingGetInfo (v->parent)->forList.listType; + + ccsFreeSettingValueCommon (v, type); if (v != ccsSettingGetDefaultValue (v->parent)) free (v); } +void +ccsFreeSettingValueWithType (CCSSettingValue *v, + CCSSettingType type) +{ + ccsFreeSettingValueCommon (v, type); + + free (v); +} + void ccsFreePluginConflict (CCSPluginConflict * c) { @@ -885,20 +929,47 @@ ccsFreePluginConflict (CCSPluginConflict * c) free (c); } -void -ccsFreeBackendInfo (CCSBackendInfo * b) +CCSBackendInfo * +ccsCopyBackendInfoFromBackend (CCSBackend *backend, + const CCSBackendInterface *interface) { - if (!b) - return; + const CCSBackendInfo *backendInfo = (*interface->backendGetInfo) (backend); + + if (!backendInfo) + return NULL; + + CCSBackendInfo *info = calloc (1, sizeof (CCSBackendInfo)); + + if (!info) + return NULL; + + memcpy (info, backendInfo, sizeof (CCSBackendInfo)); + + /* This is an abuse here - + * in order to minimize code duplication ccsGetBackendInfo returns + * const static data, but when we're dealing with the copies we're + * dealing with heap allocated memory, since you can't access the + * const data in the case that the libraries are not open. + * Thus the cast. */ + + info->name = (const char *) strdup (backendInfo->name); + info->shortDesc = (const char *) strdup (backendInfo->shortDesc); + info->longDesc = (const char *) strdup (backendInfo->longDesc); + + return info; +} +void +ccsFreeBackendInfo (CCSBackendInfo *b) +{ if (b->name) - free (b->name); + free ((char *) b->name); if (b->shortDesc) - free (b->shortDesc); + free ((char *) b->shortDesc); if (b->longDesc) - free (b->longDesc); + free ((char *) b->longDesc); free (b); } @@ -954,19 +1025,6 @@ ccsFreeString (CCSString *str) free (str); } -#define CCSREF(type,dtype) \ - void ccs##type##Ref (dtype *d) \ - { \ - d->refCount++; \ - } \ - void ccs##type##Unref (dtype *d) \ - { \ - d->refCount--; \ - if (d->refCount == 0) \ - ccsFree##type (d); \ - } \ - - CCSREF (String, CCSString) CCSREF (Group, CCSGroup) CCSREF (SubGroup, CCSSubGroup) @@ -977,22 +1035,18 @@ CCSREF (IntDesc, CCSIntDesc) CCSREF (StrRestriction, CCSStrRestriction) CCSREF (StrExtension, CCSStrExtension) -#define CCSREF_OBJ(type,dtype) \ - void ccs##type##Ref (dtype *d) \ - { \ - ccsObjectRef (d); \ - } \ - \ - void ccs##type##Unref (dtype *d) \ - { \ - ccsObjectUnref (d, ccsFree##type); \ - } \ - CCSREF_OBJ (Plugin, CCSPlugin) CCSREF_OBJ (Setting, CCSSetting) +CCSREF_OBJ (Backend, CCSBackend) +CCSREF_OBJ (DynamicBackend, CCSDynamicBackend) +CCSREF_OBJ (Integration, CCSIntegration) +CCSREF_OBJ (IntegratedSetting, CCSIntegratedSetting); +CCSREF_OBJ (IntegratedSettingInfo, CCSIntegratedSettingInfo); +CCSREF_OBJ (IntegratedSettingFactory, CCSIntegratedSettingFactory); +CCSREF_OBJ (IntegratedSettingsStorage, CCSIntegratedSettingsStorage); static void * -openBackend (char *backend) +openBackend (const char *backend) { char *home = getenv ("HOME"); char *override_backend = getenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); @@ -1047,79 +1101,641 @@ openBackend (char *backend) return dlhand; } +void +ccsFreeBackend (CCSBackend *backend) +{ + ccsBackendFini (backend); + ccsObjectFinalize (backend); + free (backend); +} + +void +ccsFreeDynamicBackend (CCSDynamicBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + ccsBackendUnref (dbPrivate->backend); + + if (dbPrivate->dlhand) + dlclose (dbPrivate->dlhand); + + ccsObjectFinalize (backend); + free (backend); +} + +CCSBackend * +ccsBackendNewWithDynamicInterface (CCSContext *context, const CCSBackendInterface *interface) +{ + CCSBackend *backend = calloc (1, sizeof (CCSBackend)); + + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + ccsBackendRef (backend); + + ccsObjectAddInterface (backend, (CCSInterface *) interface, GET_INTERFACE_TYPE (CCSBackendInterface)); + + return backend; +} + +CCSDynamicBackend * +ccsDynamicBackendWrapLoadedBackend (const CCSInterfaceTable *interfaces, CCSBackend *backend, void *dlhand) +{ + CCSDynamicBackend *dynamicBackend = calloc (1, sizeof (CCSDynamicBackend)); + CCSDynamicBackendPrivate *dbPrivate = NULL; + + if (!dynamicBackend) + return NULL; + + ccsObjectInit (dynamicBackend, &ccsDefaultObjectAllocator); + ccsDynamicBackendRef (dynamicBackend); + + dbPrivate = calloc (1, sizeof (CCSDynamicBackendPrivate)); + + if (!dbPrivate) + { + ccsDynamicBackendUnref (dynamicBackend); + return NULL; + } + + dbPrivate->dlhand = dlhand; + dbPrivate->backend = backend; + + ccsObjectSetPrivate (dynamicBackend, (CCSPrivate *) dbPrivate); + ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendWrapperInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); + ccsObjectAddInterface (dynamicBackend, (CCSInterface *) interfaces->dynamicBackendInterface, GET_INTERFACE_TYPE (CCSDynamicBackendInterface)); + + return dynamicBackend; +} + +CCSBackend * +ccsOpenBackend (const CCSInterfaceTable *interfaces, CCSContext *context, const char *name) +{ + CCSBackendInterface *vt; + void *dlhand = openBackend (name); + + if (!dlhand) + return NULL; + + BackendGetInfoProc getInfo = dlsym (dlhand, "getBackendInfo"); + if (!getInfo) + { + dlclose (dlhand); + return NULL; + } + + vt = getInfo (); + if (!vt) + { + dlclose (dlhand); + return NULL; + } + + CCSBackend *backend = ccsBackendNewWithDynamicInterface (context, vt); + + if (!backend) + { + dlclose (dlhand); + return NULL; + } + + CCSDynamicBackend *backendWrapper = ccsDynamicBackendWrapLoadedBackend (interfaces, backend, dlhand); + + if (!backendWrapper) + { + dlclose (dlhand); + ccsBackendUnref (backend); + return NULL; + } + + return (CCSBackend *) backendWrapper; +} + Bool ccsSetBackendDefault (CCSContext * context, char *name) { Bool fallbackMode = FALSE; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (cPrivate->backend) { /* no action needed if the backend is the same */ - if (strcmp (cPrivate->backend->vTable->name, name) == 0) + if (strcmp (ccsDynamicBackendGetBackendName (cPrivate->backend), name) == 0) return TRUE; - if (cPrivate->backend->vTable->backendFini) - cPrivate->backend->vTable->backendFini (context); - - dlclose (cPrivate->backend->dlhand); - free (cPrivate->backend); + ccsDynamicBackendUnref (cPrivate->backend); cPrivate->backend = NULL; } - void *dlhand = openBackend (name); - if (!dlhand) + CCSBackend *backend = ccsOpenBackend (cPrivate->object_interfaces, context, name); + + if (!backend) { + ccsWarning ("unable to open backend %s, falling back to ini", name); + + backend = ccsOpenBackend (cPrivate->object_interfaces, context, "ini"); + if (!backend) + { + ccsError ("failed to open any backends, aborting"); + abort (); + } + fallbackMode = TRUE; - name = "ini"; - dlhand = openBackend (name); } - if (!dlhand) - return FALSE; + cPrivate->backend = (CCSDynamicBackend *) backend; - BackendGetInfoProc getInfo = dlsym (dlhand, "getBackendInfo"); - if (!getInfo) - { - dlclose (dlhand); - return FALSE; - } + CCSBackendInitFunc backendInit = (GET_INTERFACE (CCSBackendInterface, cPrivate->backend))->backendInit; + + if (backendInit) + (*backendInit) ((CCSBackend *) cPrivate->backend, context); + + ccsDisableFileWatch (cPrivate->configWatchId); + if (!fallbackMode) + ccsWriteConfig (OptionBackend, name); + ccsEnableFileWatch (cPrivate->configWatchId); + + return TRUE; +} + +Bool +ccsSetBackend (CCSContext *context, char *name) +{ + return (*(GET_INTERFACE (CCSContextInterface, context))->contextSetBackend) (context, name); +} + +CCSIntegratedSetting * ccsIntegrationGetIntegratedSetting (CCSIntegration *integration, + const char *pluginName, + const char *settingName) +{ + return (*(GET_INTERFACE (CCSIntegrationInterface, integration))->getIntegratedSetting) (integration, pluginName, settingName); +} + +Bool ccsIntegrationReadOptionIntoSetting (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting) +{ + return (*(GET_INTERFACE (CCSIntegrationInterface, integration))->readOptionIntoSetting) (integration, context, setting, integratedSetting); +} + +void ccsIntegrationWriteSettingIntoOption (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integratedSetting) +{ + (*(GET_INTERFACE (CCSIntegrationInterface, integration))->writeSettingIntoOption) (integration, context, setting, integratedSetting); +} + +void ccsIntegrationUpdateIntegratedSettings (CCSIntegration *integration, + CCSContext *context, + CCSIntegratedSettingList integratedSettings) +{ + (*(GET_INTERFACE (CCSIntegrationInterface, integration))->updateIntegratedSettings) (integration, context, integratedSettings); +} + +void ccsIntegrationDisallowIntegratedWrites (CCSIntegration *integration) +{ + (*(GET_INTERFACE (CCSIntegrationInterface, integration))->disallowIntegratedWrites) (integration); +} + +void ccsIntegrationAllowIntegratedWrites (CCSIntegration *integration) +{ + (*(GET_INTERFACE (CCSIntegrationInterface, integration))->allowIntegratedWrites) (integration); +} + +void ccsFreeIntegration (CCSIntegration *integration) +{ + (*(GET_INTERFACE (CCSIntegrationInterface, integration))->freeIntegrationBackend) (integration); +} + +static CCSIntegratedSetting * +ccsNullIntegrationBackendGetIntegratedSetting (CCSIntegration *integration, + const char *pluginName, + const char *settingName) +{ + return NULL; +} + +static Bool +ccsNullIntegrationBackendReadOptionIntoSetting (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integrated) +{ + return FALSE; +} + +static void +ccsNullIntegrationBackendWriteSettingIntoOption (CCSIntegration *integration, + CCSContext *context, + CCSSetting *setting, + CCSIntegratedSetting *integrated) +{ +} + +static void +ccsNullIntegrationBackendUpdateIntegratedSettings (CCSIntegration *integration, + CCSContext *context, + CCSIntegratedSettingList settings) +{ +} + +void +ccsNullIntegrationBackendFree (CCSIntegration *integration) +{ + ccsObjectFinalize (integration); + (*integration->object.object_allocation->free_) (integration->object.object_allocation->allocator, integration); +} + +const CCSIntegrationInterface ccsNullIntegrationBackendInterface = +{ + ccsNullIntegrationBackendGetIntegratedSetting, + ccsNullIntegrationBackendReadOptionIntoSetting, + ccsNullIntegrationBackendWriteSettingIntoOption, + ccsNullIntegrationBackendUpdateIntegratedSettings, + ccsNullIntegrationBackendFree +}; + +CCSIntegration * +ccsNullIntegrationBackendNew (CCSObjectAllocationInterface *ai) +{ + CCSIntegration *integration = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegration)); + + if (!integration) + return NULL; + + ccsObjectInit (integration, ai); + ccsObjectAddInterface (integration, (const CCSInterface *) &ccsNullIntegrationBackendInterface, GET_INTERFACE_TYPE (CCSIntegrationInterface)); + return integration; +} + +const CCSBackendInfo * ccsBackendGetInfo (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendGetInfo) (backend); +} + +static Bool +ccsDynamicBackendSupportsIntegrationDefault (CCSDynamicBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendGetInfo (dbPrivate->backend)->integrationSupport; +} + +const char * ccsDynamicBackendGetBackendName (CCSDynamicBackend *backend) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->getBackendName) (backend); +} + +Bool ccsDynamicBackendSupportsRead (CCSDynamicBackend *backend) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsRead) (backend); +} + +Bool ccsDynamicBackendSupportsWrite (CCSDynamicBackend *backend) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsWrite) (backend); +} + +Bool ccsDynamicBackendSupportsProfiles (CCSDynamicBackend *backend) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsProfiles) (backend); +} + +Bool ccsDynamicBackendSupportsIntegration (CCSDynamicBackend *backend) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->supportsIntegration) (backend); +} + +CCSBackend * ccsDynamicBackendGetRawBackend (CCSDynamicBackend *backend) +{ + return (*(GET_INTERFACE (CCSDynamicBackendInterface, backend))->getRawBackend) (backend); +} + +Bool ccsBackendHasExecuteEvents (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->executeEvents != NULL; +} + +void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags) +{ + (*(GET_INTERFACE (CCSBackendInterface, backend))->executeEvents) (backend, flags); +} + +Bool ccsBackendInit (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendInit) (backend, context); +} + +Bool ccsBackendFini (CCSBackend *backend) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->backendFini) (backend); +} + +static Bool ccsBackendHasReadInit (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->readInit != NULL; +} + +Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readInit) (backend, context); +} + +static Bool ccsBackendHasReadSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->readSetting != NULL; +} + +void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + (*(GET_INTERFACE (CCSBackendInterface, backend))->readSetting) (backend, context, setting); +} + +static Bool ccsBackendHasReadDone (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->readDone != NULL; +} + +void ccsBackendReadDone (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->readDone) (backend, context); +} + +static Bool ccsBackendHasWriteInit (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->writeInit != NULL; +} + +Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeInit) (backend, context); +} + +static Bool ccsBackendHasWriteSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->writeSetting != NULL; +} + +void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + (*(GET_INTERFACE (CCSBackendInterface, backend))->writeSetting) (backend, context, setting); +} + +static Bool ccsBackendHasWriteDone (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->writeDone != NULL; +} + +void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->writeDone) (backend, context); +} + +static Bool ccsBackendHasUpdateSetting (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->updateSetting != NULL; +} + +void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->updateSetting) (backend, context, plugin, setting); +} + +static Bool ccsBackendHasGetSettingIsIntegrated (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated != NULL; +} + +Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsIntegrated) (backend, setting); +} + +static Bool ccsBackendHasGetSettingIsReadOnly (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly != NULL; +} + +Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getSettingIsReadOnly) (backend, setting); +} + +static Bool ccsBackendHasGetExistingProfiles (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles != NULL; +} + +CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->getExistingProfiles) (backend, context); +} + +static Bool ccsBackendHasDeleteProfile (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile != NULL; +} + +Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->deleteProfile) (backend, context, name); +} + +static Bool ccsBackendHasSetIntegration (CCSBackend *backend) +{ + return (GET_INTERFACE (CCSBackendInterface, backend))->setIntegration != NULL; +} + +void ccsBackendSetIntegration (CCSBackend *backend, CCSIntegration *integration) +{ + return (*(GET_INTERFACE (CCSBackendInterface, backend))->setIntegration) (backend, integration); +} + +static const char * +ccsDynamicBackendGetBackendNameDefault (CCSDynamicBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendGetInfo (dbPrivate->backend)->name; +} + +static Bool +ccsDynamicBackendSupportsReadDefault (CCSDynamicBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendHasReadSetting (dbPrivate->backend); +} + +static Bool +ccsDynamicBackendSupportsWriteDefault (CCSDynamicBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendHasWriteSetting (dbPrivate->backend); +} + +static Bool +ccsDynamicBackendSupportsProfilesDefault (CCSDynamicBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendGetInfo (dbPrivate->backend)->profileSupport; + +} + +static CCSBackend * ccsDynamicBackendGetRawBackendDefault (CCSDynamicBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return dbPrivate->backend; +} + +static const CCSBackendInfo * ccsDynamicBackendGetInfoWrapper (CCSBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendGetInfo (dbPrivate->backend); +} + +static Bool ccsDynamicBackendInitWrapper (CCSBackend *backend, CCSContext *context) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendInit (dbPrivate->backend, context); +} + +static Bool ccsDynamicBackendFiniWrapper (CCSBackend *backend) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + return ccsBackendFini (dbPrivate->backend); +} + +static void ccsDynamicBackendExecuteEventsWrapper (CCSBackend *backend, unsigned int flags) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasExecuteEvents (dbPrivate->backend)) + ccsBackendExecuteEvents (dbPrivate->backend, flags); +} + +static Bool ccsDynamicBackendReadInitWrapper (CCSBackend *backend, CCSContext *context) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasReadInit (dbPrivate->backend)) + return ccsBackendReadInit (dbPrivate->backend, context); + + return TRUE; +} + +static void ccsDynamicBackendReadSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasReadSetting (dbPrivate->backend)) + ccsBackendReadSetting (dbPrivate->backend, context, setting); +} + +static void ccsDynamicBackendReadDoneWrapper (CCSBackend *backend, CCSContext *context) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasReadDone (dbPrivate->backend)) + ccsBackendReadDone (dbPrivate->backend, context); +} + +static Bool ccsDynamicBackendWriteInitWrapper (CCSBackend *backend, CCSContext *context) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasWriteInit (dbPrivate->backend)) + return ccsBackendWriteInit (dbPrivate->backend, context); + + return TRUE; +} + +static void ccsDynamicBackendWriteSettingWrapper (CCSBackend *backend, CCSContext *context, CCSSetting *setting) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasWriteSetting (dbPrivate->backend)) + ccsBackendWriteSetting (dbPrivate->backend, context, setting); +} + +static void ccsDynamicBackendWriteDoneWrapper (CCSBackend *backend, CCSContext *context) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasWriteDone (dbPrivate->backend)) + ccsBackendWriteDone (dbPrivate->backend, context); +} + +static void ccsDynamicBackendUpdateSettingWrapper (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasUpdateSetting (dbPrivate->backend)) + ccsBackendUpdateSetting (dbPrivate->backend, context, plugin, setting); +} + +static Bool ccsDynamicBackendGetSettingIsIntegratedWrapper (CCSBackend *backend, CCSSetting *setting) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasGetSettingIsIntegrated (dbPrivate->backend) && + ccsDynamicBackendSupportsIntegration ((CCSDynamicBackend *) backend)) + return ccsBackendGetSettingIsIntegrated (dbPrivate->backend, setting); + + return FALSE; +} + +static Bool ccsDynamicBackendGetSettingIsReadOnlyWrapper (CCSBackend *backend, CCSSetting *setting) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasGetSettingIsReadOnly (dbPrivate->backend)) + return ccsBackendGetSettingIsReadOnly (dbPrivate->backend, setting); + + return FALSE; +} + +static CCSStringList ccsDynamicBackendGetExistingProfilesWrapper (CCSBackend *backend, CCSContext *context) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); - CCSBackendVTable *vt = getInfo (); - if (!vt) - { - dlclose (dlhand); - return FALSE; - } + if (ccsBackendHasGetExistingProfiles (dbPrivate->backend) && + ccsDynamicBackendSupportsProfiles ((CCSDynamicBackend *) backend)) + return ccsBackendGetExistingProfiles (dbPrivate->backend, context); - cPrivate->backend = calloc (1, sizeof (CCSBackend)); - if (!cPrivate->backend) - { - dlclose (dlhand); - return FALSE; - } - cPrivate->backend->dlhand = dlhand; - cPrivate->backend->vTable = vt; + static CCSStringList sl = NULL; - if (cPrivate->backend->vTable->backendInit) - cPrivate->backend->vTable->backendInit (context); + return sl; +} - ccsDisableFileWatch (cPrivate->configWatchId); - if (!fallbackMode) - ccsWriteConfig (OptionBackend, name); - ccsEnableFileWatch (cPrivate->configWatchId); +static Bool ccsDynamicBackendDeleteProfileWrapper (CCSBackend *backend, CCSContext *context, char *profile) +{ + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); - return TRUE; + if (ccsBackendHasDeleteProfile (dbPrivate->backend) && + ccsDynamicBackendSupportsProfiles ((CCSDynamicBackend *) backend)) + return ccsBackendDeleteProfile (dbPrivate->backend, context, profile); + + return FALSE; } -Bool -ccsSetBackend (CCSContext *context, char *name) +static void ccsDynamicBackendSetIntegrationWrapper (CCSBackend *backend, CCSIntegration *integration) { - return (*(GET_INTERFACE (CCSContextInterface, context))->contextSetBackend) (context, name); + CCSDynamicBackendPrivate *dbPrivate = GET_PRIVATE (CCSDynamicBackendPrivate, backend); + + if (ccsBackendHasSetIntegration (backend) && + ccsDynamicBackendSupportsIntegration ((CCSDynamicBackend *) backend)) + return ccsBackendSetIntegration (dbPrivate->backend, integration); } -static Bool +Bool ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, CCSSettingListInfo info) { @@ -1132,8 +1748,14 @@ ccsCompareLists (CCSSettingValueList l1, CCSSettingValueList l2, return FALSE; break; case TypeBool: - if (l1->data->value.asBool != l2->data->value.asBool) - return FALSE; + { + Bool bothTrue = (l1->data->value.asBool && l2->data->value.asBool); + Bool bothFalse = (!l1->data->value.asBool && !l2->data->value.asBool); + + /* Use the boolean operators as TRUE/FALSE can be redefined */ + if (!bothTrue && !bothFalse) + return FALSE; + } break; case TypeFloat: if (l1->data->value.asFloat != l2->data->value.asFloat) @@ -1365,7 +1987,7 @@ copyFromDefault (CCSSetting * setting) { CCSSettingValue *value; - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->value != &sPrivate->defaultValue) ccsFreeSettingValue (sPrivate->value); @@ -1388,7 +2010,7 @@ copyFromDefault (CCSSetting * setting) void ccsSettingResetToDefaultDefault (CCSSetting * setting, Bool processChanged) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->value != &sPrivate->defaultValue) { @@ -1463,7 +2085,7 @@ ccsCheckValueEq (CCSSettingValue *rhs, CCSSettingValue *lhs) Bool ccsSettingSetIntDefault (CCSSetting * setting, int data, Bool processChanged) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeInt) return FALSE; @@ -1498,7 +2120,7 @@ ccsSettingSetIntDefault (CCSSetting * setting, int data, Bool processChanged) Bool ccsSettingSetFloatDefault (CCSSetting * setting, float data, Bool processChanged) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->type != TypeFloat) return FALSE; @@ -1535,7 +2157,7 @@ ccsSettingSetFloatDefault (CCSSetting * setting, float data, Bool processChanged Bool ccsSettingSetBoolDefault (CCSSetting * setting, Bool data, Bool processChanged) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeBool) return FALSE; @@ -1571,7 +2193,7 @@ ccsSettingSetBoolDefault (CCSSetting * setting, Bool data, Bool processChanged) Bool ccsSettingSetStringDefault (CCSSetting * setting, const char *data, Bool processChanged) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->type != TypeString) return FALSE; @@ -1609,7 +2231,7 @@ ccsSettingSetStringDefault (CCSSetting * setting, const char *data, Bool process Bool ccsSettingSetColorDefault (CCSSetting * setting, CCSSettingColorValue data, Bool processChanged) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeColor) return FALSE; @@ -1644,7 +2266,7 @@ ccsSettingSetColorDefault (CCSSetting * setting, CCSSettingColorValue data, Bool Bool ccsSettingSetMatchDefault (CCSSetting * setting, const char *data, Bool processChanged) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->type != TypeMatch) return FALSE; @@ -1682,7 +2304,7 @@ ccsSettingSetMatchDefault (CCSSetting * setting, const char *data, Bool processC Bool ccsSettingSetKeyDefault (CCSSetting * setting, CCSSettingKeyValue data, Bool processChanged) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->type != TypeKey) return FALSE; @@ -1718,7 +2340,7 @@ ccsSettingSetKeyDefault (CCSSetting * setting, CCSSettingKeyValue data, Bool pro Bool ccsSettingSetButtonDefault (CCSSetting * setting, CCSSettingButtonValue data, Bool processChanged) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->type != TypeButton) return FALSE; @@ -1755,7 +2377,7 @@ ccsSettingSetButtonDefault (CCSSetting * setting, CCSSettingButtonValue data, Bo Bool ccsSettingSetEdgeDefault (CCSSetting * setting, unsigned int data, Bool processChanged) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeEdge) return FALSE; @@ -1788,7 +2410,7 @@ ccsSettingSetEdgeDefault (CCSSetting * setting, unsigned int data, Bool processC Bool ccsSettingSetBellDefault (CCSSetting * setting, Bool data, Bool processChanged) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->type != TypeBell) return FALSE; @@ -1818,13 +2440,11 @@ ccsSettingSetBellDefault (CCSSetting * setting, Bool data, Bool processChanged) return TRUE; } -static CCSSettingValueList +CCSSettingValueList ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) { CCSSettingValueList l2 = NULL; - SETTING_PRIV (setting) - while (l1) { CCSSettingValue *value = calloc (1, sizeof (CCSSettingValue)); @@ -1835,7 +2455,7 @@ ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) value->parent = setting; value->isListChild = TRUE; - switch (sPrivate->info.forList.listType) + switch (ccsSettingGetInfo (setting)->forList.listType) { case TypeInt: value->value.asInt = l1->data->value.asInt; @@ -1887,7 +2507,7 @@ ccsCopyList (CCSSettingValueList l1, CCSSetting * setting) Bool ccsSettingSetListDefault (CCSSetting * setting, CCSSettingValueList data, Bool processChanged) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeList) return FALSE; @@ -1945,7 +2565,7 @@ ccsSettingSetListDefault (CCSSetting * setting, CCSSettingValueList data, Bool p Bool ccsSettingSetValueDefault (CCSSetting * setting, CCSSettingValue * data, Bool processChanged) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); switch (sPrivate->type) { @@ -1991,7 +2611,7 @@ ccsSettingSetValueDefault (CCSSetting * setting, CCSSettingValue * data, Bool pr Bool ccsSettingGetIntDefault (CCSSetting * setting, int *data) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); if (sPrivate->type != TypeInt) return FALSE; @@ -2003,7 +2623,7 @@ ccsSettingGetIntDefault (CCSSetting * setting, int *data) Bool ccsSettingGetFloatDefault (CCSSetting * setting, float *data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeFloat) return FALSE; @@ -2015,7 +2635,7 @@ ccsSettingGetFloatDefault (CCSSetting * setting, float *data) Bool ccsSettingGetBoolDefault (CCSSetting * setting, Bool * data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeBool) return FALSE; @@ -2027,7 +2647,7 @@ ccsSettingGetBoolDefault (CCSSetting * setting, Bool * data) Bool ccsSettingGetStringDefault (CCSSetting * setting, char **data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeString) return FALSE; @@ -2039,7 +2659,7 @@ ccsSettingGetStringDefault (CCSSetting * setting, char **data) Bool ccsSettingGetColorDefault (CCSSetting * setting, CCSSettingColorValue * data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeColor) return TRUE; @@ -2051,7 +2671,7 @@ ccsSettingGetColorDefault (CCSSetting * setting, CCSSettingColorValue * data) Bool ccsSettingGetMatchDefault (CCSSetting * setting, char **data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeMatch) return FALSE; @@ -2063,7 +2683,7 @@ ccsSettingGetMatchDefault (CCSSetting * setting, char **data) Bool ccsSettingGetKeyDefault (CCSSetting * setting, CCSSettingKeyValue * data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeKey) return FALSE; @@ -2075,7 +2695,7 @@ ccsSettingGetKeyDefault (CCSSetting * setting, CCSSettingKeyValue * data) Bool ccsSettingGetButtonDefault (CCSSetting * setting, CCSSettingButtonValue * data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeButton) return FALSE; @@ -2087,7 +2707,7 @@ ccsSettingGetButtonDefault (CCSSetting * setting, CCSSettingButtonValue * data) Bool ccsSettingGetEdgeDefault (CCSSetting * setting, unsigned int * data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeEdge) return FALSE; @@ -2099,7 +2719,7 @@ ccsSettingGetEdgeDefault (CCSSetting * setting, unsigned int * data) Bool ccsSettingGetBellDefault (CCSSetting * setting, Bool * data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeBell) return FALSE; @@ -2111,7 +2731,7 @@ ccsSettingGetBellDefault (CCSSetting * setting, Bool * data) Bool ccsSettingGetListDefault (CCSSetting * setting, CCSSettingValueList * data) { - SETTING_PRIV (setting) + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting) if (sPrivate->type != TypeList) return FALSE; @@ -2285,21 +2905,22 @@ Bool ccsSettingIsReadOnly (CCSSetting *setting) return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingIsReadOnly) (setting); } +Bool ccsSettingIsReadableByBackend (CCSSetting *setting) +{ + return (*(GET_INTERFACE (CCSSettingInterface, setting))->settingIsReadableByBackend) (setting); +} + void ccsContextDestroy (CCSContext * context) { if (!context) return; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (cPrivate->backend) { - if (cPrivate->backend->vTable->backendFini) - cPrivate->backend->vTable->backendFini (context); - - dlclose (cPrivate->backend->dlhand); - free (cPrivate->backend); + ccsDynamicBackendUnref (cPrivate->backend); cPrivate->backend = NULL; } @@ -2309,14 +2930,14 @@ ccsContextDestroy (CCSContext * context) CCSPluginList ccsGetActivePluginListDefault (CCSContext * context) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); CCSPluginList rv = NULL; CCSPluginList l = cPrivate->plugins; while (l) { - PLUGIN_PRIV (l->data); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, l->data); if (pPrivate->active && strcmp (ccsPluginGetName (l->data), "ccp")) { rv = ccsPluginListAppend (rv, l->data); @@ -2523,21 +3144,21 @@ ccsGetSortedPluginStringList (CCSContext *context) return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetSortedPluginStringList) (context); } -char * +const char * ccsGetBackendDefault (CCSContext * context) { if (!context) return NULL; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return NULL; - return cPrivate->backend->vTable->name; + return ccsDynamicBackendGetBackendName (cPrivate->backend); } -char * +const char * ccsGetBackend (CCSContext *context) { return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetBackend) (context); @@ -2549,7 +3170,7 @@ ccsGetIntegrationEnabledDefault (CCSContext * context) if (!context) return FALSE; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->deIntegration; } @@ -2563,18 +3184,18 @@ ccsGetIntegrationEnabled (CCSContext *context) return (*(GET_INTERFACE (CCSContextInterface, context))->contextGetIntegrationEnabled) (context); } -char * +const char * ccsGetProfileDefault (CCSContext * context) { if (!context) return NULL; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->profile; } -char * +const char * ccsGetProfile (CCSContext *context) { if (!context) @@ -2589,7 +3210,7 @@ ccsGetPluginListAutoSortDefault (CCSContext * context) if (!context) return FALSE; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); return cPrivate->pluginListAutoSort; } @@ -2606,7 +3227,7 @@ ccsGetPluginListAutoSort (CCSContext *context) void ccsSetIntegrationEnabledDefault (CCSContext * context, Bool value) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); /* no action required if nothing changed */ if ((!cPrivate->deIntegration && !value) || @@ -2655,7 +3276,7 @@ ccsWriteAutoSortedPluginList (CCSContext *context) void ccsSetPluginListAutoSortDefault (CCSContext * context, Bool value) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); /* no action required if nothing changed */ if ((!cPrivate->pluginListAutoSort && !value) || @@ -2684,7 +3305,7 @@ ccsSetProfileDefault (CCSContext * context, char *name) if (!name) name = ""; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); /* no action required if profile stays the same */ if (cPrivate->profile && (strcmp (cPrivate->profile, name) == 0)) @@ -2712,12 +3333,12 @@ ccsProcessEventsDefault (CCSContext * context, unsigned int flags) if (!context) return; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); ccsCheckFileWatches (); - if (cPrivate->backend && cPrivate->backend->vTable->executeEvents) - (*cPrivate->backend->vTable->executeEvents) (flags); + if (cPrivate->backend) + ccsBackendExecuteEvents ((CCSBackend *) cPrivate->backend, flags); } void @@ -2735,35 +3356,33 @@ ccsReadSettingsDefault (CCSContext * context) if (!context) return; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->readSetting) + if (!ccsDynamicBackendSupportsRead (cPrivate->backend)) return; - if (cPrivate->backend->vTable->readInit) - if (!(*cPrivate->backend->vTable->readInit) (context)) - return; + if (!ccsBackendReadInit ((CCSBackend *) cPrivate->backend, context)) + return; CCSPluginList pl = cPrivate->plugins; while (pl) { - PLUGIN_PRIV (pl->data); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, pl->data); CCSSettingList sl = pPrivate->settings; while (sl) { - (*cPrivate->backend->vTable->readSetting) (context, sl->data); + ccsBackendReadSetting ((CCSBackend *) cPrivate->backend, context, sl->data); sl = sl->next; } pl = pl->next; } - if (cPrivate->backend->vTable->readDone) - (*cPrivate->backend->vTable->readDone) (context); + ccsBackendReadDone ((CCSBackend *) cPrivate->backend, context); } void @@ -2781,29 +3400,28 @@ ccsReadPluginSettingsDefault (CCSPlugin * plugin) if (!plugin || !ccsPluginGetContext (plugin)) return; - CONTEXT_PRIV (ccsPluginGetContext (plugin)); + CCSContext *context = ccsPluginGetContext (plugin); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->readSetting) + if (!ccsDynamicBackendSupportsRead (cPrivate->backend)) return; - if (cPrivate->backend->vTable->readInit) - if (!(*cPrivate->backend->vTable->readInit) (ccsPluginGetContext (plugin))) - return; + if (!ccsBackendReadInit ((CCSBackend *) cPrivate->backend, ccsPluginGetContext (plugin))) + return; - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); CCSSettingList sl = pPrivate->settings; while (sl) { - (*cPrivate->backend->vTable->readSetting) (ccsPluginGetContext (plugin), sl->data); + ccsBackendReadSetting ((CCSBackend *) cPrivate->backend, ccsPluginGetContext (plugin), sl->data); sl = sl->next; } - if (cPrivate->backend->vTable->readDone) - (*cPrivate->backend->vTable->readDone) (ccsPluginGetContext (plugin)); + ccsBackendReadDone ((CCSBackend *) cPrivate->backend, ccsPluginGetContext (plugin)); } void @@ -2818,35 +3436,33 @@ ccsWriteSettingsDefault (CCSContext * context) if (!context) return; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->writeSetting) + if (!ccsDynamicBackendSupportsWrite (cPrivate->backend)) return; - if (cPrivate->backend->vTable->writeInit) - if (!(*cPrivate->backend->vTable->writeInit) (context)) - return; + if (!ccsBackendWriteInit ((CCSBackend *) cPrivate->backend, context)) + return; CCSPluginList pl = cPrivate->plugins; while (pl) { - PLUGIN_PRIV (pl->data); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, pl->data); CCSSettingList sl = pPrivate->settings; while (sl) { - (*cPrivate->backend->vTable->writeSetting) (context, sl->data); + ccsBackendWriteSetting ((CCSBackend *) cPrivate->backend, context, sl->data); sl = sl->next; } pl = pl->next; } - if (cPrivate->backend->vTable->writeDone) - (*cPrivate->backend->vTable->writeDone) (context); + ccsBackendWriteDone ((CCSBackend *) cPrivate->backend, context); cPrivate->changedSettings = ccsSettingListFree (cPrivate->changedSettings, FALSE); @@ -2867,34 +3483,35 @@ ccsWriteChangedSettingsDefault (CCSContext * context) if (!context) return; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return; - if (!cPrivate->backend->vTable->writeSetting) + if (!ccsDynamicBackendSupportsWrite (cPrivate->backend)) return; - if (cPrivate->backend->vTable->writeInit) - if (!(*cPrivate->backend->vTable->writeInit) (context)) - return; + if (!ccsBackendWriteInit ((CCSBackend *) cPrivate->backend, context)) + return; - if (ccsSettingListLength (cPrivate->changedSettings)) + /* We must immediately steal the changed settings list + * if we recurse into this function */ + CCSSettingList changedSettings = ccsContextStealChangedSettings (context); + + if (ccsSettingListLength (changedSettings)) { - CCSSettingList l = cPrivate->changedSettings; + CCSSettingList l = changedSettings; while (l) { - (*cPrivate->backend->vTable->writeSetting) (context, l->data); + ccsBackendWriteSetting ((CCSBackend *) cPrivate->backend, context, l->data); l = l->next; } } - if (cPrivate->backend->vTable->writeDone) - (*cPrivate->backend->vTable->writeDone) (context); + ccsBackendWriteDone ((CCSBackend *) cPrivate->backend,context); - cPrivate->changedSettings = - ccsSettingListFree (cPrivate->changedSettings, FALSE); + ccsSettingListFree (changedSettings, FALSE); } void @@ -2946,8 +3563,10 @@ ccsPluginSetActive (CCSPlugin * plugin, Bool value) if (!plugin) return FALSE; - PLUGIN_PRIV (plugin); - CONTEXT_PRIV (ccsPluginGetContext (plugin)); + CCSContext *context = ccsPluginGetContext (plugin); + + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); pPrivate->active = value; @@ -2967,7 +3586,7 @@ ccsCanEnablePluginDefault (CCSContext * context, CCSPlugin * plugin) /* look if the plugin to be loaded requires a plugin not present */ sl = ccsPluginGetRequiresPlugins (plugin); - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); while (sl) { @@ -3189,7 +3808,7 @@ ccsCanDisablePluginDefault (CCSContext * context, CCSPlugin * plugin) CCSPluginList pl; CCSStringList sl; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); /* look if the plugin to be unloaded is required by another plugin */ pl = cPrivate->plugins; @@ -3297,13 +3916,13 @@ ccsGetExistingProfilesDefault (CCSContext * context) if (!context) return NULL; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return NULL; - if (cPrivate->backend->vTable->getExistingProfiles) - return (*cPrivate->backend->vTable->getExistingProfiles) (context); + if (ccsDynamicBackendSupportsProfiles (cPrivate->backend)) + return ccsBackendGetExistingProfiles ((CCSBackend *) cPrivate->backend, context); return NULL; } @@ -3323,11 +3942,14 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (!context) return; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return; + if (!ccsDynamicBackendSupportsProfiles (cPrivate->backend)) + return; + /* never ever delete default profile */ if (!name || !strlen (name)) return; @@ -3337,8 +3959,7 @@ ccsDeleteProfileDefault (CCSContext * context, char *name) if (strcmp (cPrivate->profile, name) == 0) ccsSetProfile (context, ""); - if (cPrivate->backend->vTable->deleteProfile) - (*cPrivate->backend->vTable->deleteProfile) (context, name); + ccsBackendDeleteProfile ((CCSBackend *) cPrivate->backend, context, name); } void @@ -3356,7 +3977,6 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) void *dlhand = NULL; char *err = NULL; Bool found = FALSE; - CCSBackendInfo *info; dlerror (); @@ -3372,17 +3992,25 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) return; } - CCSBackendVTable *vt = getInfo (); + CCSBackendInterface *vt = getInfo (); if (!vt) { dlclose (dlhand); return; } + CCSBackendInfo *info = ccsCopyBackendInfoFromBackend (NULL, vt); + + if (!info) + { + dlclose (dlhand); + return; + } + CCSBackendInfoList l = *bl; while (l) { - if (!strcmp (l->data->name, vt->name)) + if (!strcmp (l->data->name, info->name)) { found = TRUE; break; @@ -3397,20 +4025,6 @@ addBackendInfo (CCSBackendInfoList * bl, char *file) return; } - info = calloc (1, sizeof (CCSBackendInfo)); - if (!info) - { - dlclose (dlhand); - return; - } - - info->refCount = 1; - info->name = strdup (vt->name); - info->shortDesc = (vt->shortDesc) ? strdup (vt->shortDesc) : strdup (""); - info->longDesc = (vt->longDesc) ? strdup (vt->longDesc) : strdup (""); - info->integrationSupport = vt->integrationSupport; - info->profileSupport = vt->profileSupport; - *bl = ccsBackendInfoListAppend (*bl, info); dlclose (dlhand); } @@ -3431,7 +4045,9 @@ backendNameFilter (const struct dirent *name) } static void -getBackendInfoFromDir (CCSBackendInfoList * bl, char *path) +getBackendInfoFromDir (CCSBackendInfoList * bl, + char *path, + const char *currentBackend) { struct dirent **nameList; @@ -3446,6 +4062,9 @@ getBackendInfoFromDir (CCSBackendInfoList * bl, char *path) for (i = 0; i < nFile; i++) { + if (strncmp (currentBackend, &(nameList[i]->d_name[3]), strlen (currentBackend)) == 0) + continue; + char file[1024]; sprintf (file, "%s/%s", path, nameList[i]->d_name); addBackendInfo (bl, file); @@ -3457,46 +4076,58 @@ getBackendInfoFromDir (CCSBackendInfoList * bl, char *path) } CCSBackendInfoList -ccsGetExistingBackends () +ccsGetExistingBackends (CCSContext *context) { CCSBackendInfoList rv = NULL; char *home = getenv ("HOME"); - char *override_backend = getenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); + char *overrideBackend = getenv ("LIBCOMPIZCONFIG_BACKEND_PATH"); char *backenddir; + const char *currentBackend = ccsGetBackend (context); - if (override_backend && strlen (override_backend)) + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); + + const CCSBackendInterface *currentBackendInterface = + GET_INTERFACE (CCSBackendInterface, cPrivate->backend); + + rv = ccsBackendInfoListAppend (rv, ccsCopyBackendInfoFromBackend ((CCSBackend *) cPrivate->backend, + currentBackendInterface)); + + if (overrideBackend && strlen (overrideBackend)) { if (asprintf (&backenddir, "%s", - override_backend) == -1) + overrideBackend) == -1) backenddir = NULL; if (backenddir) { - getBackendInfoFromDir (&rv, backenddir); + getBackendInfoFromDir (&rv, backenddir, currentBackend); free (backenddir); } } - - if (home && strlen (home)) + else { - if (asprintf (&backenddir, "%s/.compizconfig/backends", home) == -1) + if (home && strlen (home)) + { + if (asprintf (&backenddir, "%s/.compizconfig/backends", home) == -1) + backenddir = NULL; + + if (backenddir) + { + getBackendInfoFromDir (&rv, backenddir, currentBackend); + free (backenddir); + } + } + + if (asprintf (&backenddir, "%s/compizconfig/backends", LIBDIR) == -1) backenddir = NULL; if (backenddir) { - getBackendInfoFromDir (&rv, backenddir); + getBackendInfoFromDir (&rv, backenddir, currentBackend); free (backenddir); } } - if (asprintf (&backenddir, "%s/compizconfig/backends", LIBDIR) == -1) - backenddir = NULL; - - if (backenddir) - { - getBackendInfoFromDir (&rv, backenddir); - free (backenddir); - } return rv; } @@ -3516,12 +4147,12 @@ ccsExportToFileDefault (CCSContext *context, if (!exportFile) return FALSE; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); for (p = cPrivate->plugins; p; p = p->next) { plugin = p->data; - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (!pPrivate->loaded) ccsLoadPluginSettings (plugin); @@ -3623,7 +4254,7 @@ ccsProcessSettingPlus (IniDictionary *dict, char *sectionName = strdup (ccsPluginGetName (ccsSettingGetParent (setting))); char *iniValue = NULL; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (asprintf (&keyName, "+s%d_%s", cPrivate->screenNum, ccsSettingGetName (setting)) == -1) return FALSE; @@ -3781,7 +4412,7 @@ ccsProcessSettingMinus (IniDictionary *dict, char *sectionName = strdup (ccsPluginGetName (ccsSettingGetParent (setting))); char *iniValue = NULL; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (asprintf (&keyName, "-s%d_%s", cPrivate->screenNum, ccsSettingGetName (setting)) == -1) return FALSE; @@ -3933,7 +4564,7 @@ Bool ccsProcessUpgrade (CCSContext *context, CCSSettingsUpgrade *upgrade) { - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); IniDictionary *dict = ccsIniOpen (upgrade->file); CCSPluginList pl = cPrivate->plugins; @@ -4355,12 +4986,12 @@ ccsImportFromFileDefault (CCSContext *context, if (!importFile) return FALSE; - CONTEXT_PRIV (context); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); for (p = cPrivate->plugins; p; p = p->next) { plugin = p->data; - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (!pPrivate->loaded) ccsLoadPluginSettings (plugin); @@ -4516,70 +5147,70 @@ ccsImportFromFile (CCSContext *context, const char *fileName, Bool overwriteNonD char * ccsPluginGetNameDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->name; } char * ccsPluginGetShortDescDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->shortDesc; } char * ccsPluginGetLongDescDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->longDesc; } char * ccsPluginGetHintsDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->hints; } char * ccsPluginGetCategoryDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->category; } CCSStringList ccsPluginGetLoadAfterDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->loadAfter; } CCSStringList ccsPluginGetLoadBeforeDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->loadBefore; } CCSStringList ccsPluginGetRequiresPluginsDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->requiresPlugin; } CCSStringList ccsPluginGetConflictPluginsDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->conflictPlugin; } CCSStringList ccsPluginGetProvidesFeaturesDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->providesFeature; } @@ -4591,28 +5222,28 @@ void * ccsPluginGetProvidesFeaturesBindable (CCSPlugin *plugin) CCSStringList ccsPluginGetRequiresFeaturesDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->requiresFeature; } void * ccsPluginGetPrivatePtrDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->privatePtr; } void ccsPluginSetPrivatePtrDefault (CCSPlugin *plugin, void *ptr) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); pPrivate->privatePtr = ptr; } CCSContext * ccsPluginGetContextDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); return pPrivate->context; } @@ -4690,7 +5321,7 @@ CCSContext * ccsPluginGetContext (CCSPlugin *plugin) CCSSettingList ccsGetPluginSettingsDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (!pPrivate->loaded) ccsLoadPluginSettings (plugin); @@ -4705,7 +5336,7 @@ CCSSettingList ccsGetPluginSettings (CCSPlugin *plugin) CCSGroupList ccsGetPluginGroupsDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (!pPrivate->loaded) ccsLoadPluginSettings (plugin); @@ -4794,13 +5425,15 @@ Bool ccsSettingGetIsIntegratedDefault (CCSSetting *setting) if (!setting) return FALSE; - CONTEXT_PRIV (ccsPluginGetContext (ccsSettingGetParent (setting))); + CCSPlugin *plugin = ccsSettingGetParent (setting); + CCSContext *context = ccsPluginGetContext (plugin); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return FALSE; - if (cPrivate->backend->vTable->getSettingIsIntegrated) - return (*cPrivate->backend->vTable->getSettingIsIntegrated) (setting); + if (ccsDynamicBackendSupportsIntegration (cPrivate->backend)) + return ccsBackendGetSettingIsIntegrated ((CCSBackend *) cPrivate->backend, setting); return FALSE; } @@ -4810,13 +5443,64 @@ Bool ccsSettingGetIsReadOnlyDefault (CCSSetting *setting) if (!setting) return FALSE; - CONTEXT_PRIV (ccsPluginGetContext (ccsSettingGetParent (setting))); + CCSPlugin *plugin = ccsSettingGetParent (setting); + CCSContext *context = ccsPluginGetContext (plugin); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); + + if (!cPrivate->backend) + return FALSE; + + return ccsBackendGetSettingIsReadOnly ((CCSBackend *) cPrivate->backend, setting); +} + +Bool ccsSettingGetIsReadableByBackendDefault (CCSSetting *setting) +{ + static const CCSSettingType readableSettingTypes[] = + { + TypeBool, + TypeInt, + TypeFloat, + TypeString, + TypeColor, + TypeKey, + TypeButton, + TypeEdge, + TypeBell, + TypeMatch, + TypeList + }; + static const unsigned int readableSettingTypesNum = sizeof (readableSettingTypes) / sizeof (readableSettingTypes[0]); + int i = 0; + Bool isReadableType = FALSE; + CCSSettingType type; + + CCSPlugin *plugin = ccsSettingGetParent (setting); + CCSContext *context = ccsPluginGetContext (plugin); + CCSContextPrivate *cPrivate = GET_PRIVATE (CCSContextPrivate, context); if (!cPrivate->backend) return FALSE; - if (cPrivate->backend->vTable->getSettingIsReadOnly) - return (*cPrivate->backend->vTable->getSettingIsReadOnly) (setting); + type = ccsSettingGetType (setting); + + /* It is impossible for certain settings to have a schema, + * such as actions and read only settings, so in that case + * just return FALSE since compizconfig doesn't expect us + * to read them anyways */ + for (i = 0; i < readableSettingTypesNum; ++i) + { + if (readableSettingTypes[i] == type) + { + isReadableType = TRUE; + break; + } + } + + if (isReadableType && + !ccsSettingIsReadOnly (setting)) + { + return TRUE; + } return FALSE; } @@ -4825,105 +5509,105 @@ Bool ccsSettingGetIsReadOnlyDefault (CCSSetting *setting) char * ccsSettingGetNameDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->name; } char * ccsSettingGetShortDescDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->shortDesc; } char * ccsSettingGetLongDescDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->longDesc; } CCSSettingType ccsSettingGetTypeDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->type; } CCSSettingInfo * ccsSettingGetInfoDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return &sPrivate->info; } char * ccsSettingGetGroupDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->group; } char * ccsSettingGetSubGroupDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->subGroup; } char * ccsSettingGetHintsDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->hints; } CCSSettingValue * ccsSettingGetDefaultValueDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return &sPrivate->defaultValue; } CCSSettingValue * ccsSettingGetValueDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->value; } Bool ccsSettingGetIsDefaultDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->isDefault; } CCSPlugin * ccsSettingGetParentDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->parent; } void * ccsSettingGetPrivatePtrDefault (CCSSetting *setting) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); return sPrivate->privatePtr; } void ccsSettingSetPrivatePtrDefault (CCSSetting *setting, void *ptr) { - SETTING_PRIV (setting); + CCSSettingPrivate *sPrivate = GET_PRIVATE (CCSSettingPrivate, setting); sPrivate->privatePtr = ptr; } CCSStrExtensionList ccsGetPluginStrExtensionsDefault (CCSPlugin *plugin) { - PLUGIN_PRIV (plugin); + CCSPluginPrivate *pPrivate = GET_PRIVATE (CCSPluginPrivate, plugin); if (!pPrivate->loaded) ccsLoadPluginSettings (plugin); @@ -4936,6 +5620,300 @@ CCSStrExtensionList ccsGetPluginStrExtensions (CCSPlugin *plugin) return (*(GET_INTERFACE (CCSPluginInterface, plugin))->pluginGetPluginStrExtensions) (plugin); } +CCSSettingValue * ccsIntegratedSettingReadValue (CCSIntegratedSetting *setting, CCSSettingType type) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingInterface, setting))->readValue) (setting, type); +} + +void ccsIntegratedSettingWriteValue (CCSIntegratedSetting *setting, CCSSettingValue *value, CCSSettingType type) +{ + (*(GET_INTERFACE (CCSIntegratedSettingInterface, setting))->writeValue) (setting, value, type); +} + +const char * ccsIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *info) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingInfoInterface, info))->pluginName) (info); +} + +const char * ccsIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *info) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingInfoInterface, info))->settingName) (info); +} + +CCSSettingType ccsIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *info) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingInfoInterface, info))->getType) (info); +} + +void ccsFreeIntegratedSettingInfo (CCSIntegratedSettingInfo *info) +{ + (*(GET_INTERFACE (CCSIntegratedSettingInfoInterface, info))->free) (info); +} + +void ccsFreeIntegratedSetting (CCSIntegratedSetting *setting) +{ + (*(GET_INTERFACE (CCSIntegratedSettingInterface, setting))->free) (setting); +} + +/* CCSSharedIntegratedSettingInfo implementation */ + +typedef struct _CCSSharedIntegratedSettingInfoPrivate CCSSharedIntegratedSettingInfoPrivate; + +struct _CCSSharedIntegratedSettingInfoPrivate +{ + const char *pluginName; + const char *settingName; + CCSSettingType type; +}; + +static const char * +ccsSharedIntegratedSettingInfoSettingName (CCSIntegratedSettingInfo *setting) +{ + CCSSharedIntegratedSettingInfoPrivate *priv = (CCSSharedIntegratedSettingInfoPrivate *) ccsObjectGetPrivate (setting); + + return priv->settingName; +} + +static const char * +ccsSharedIntegratedSettingInfoPluginName (CCSIntegratedSettingInfo *setting) +{ + CCSSharedIntegratedSettingInfoPrivate *priv = (CCSSharedIntegratedSettingInfoPrivate *) ccsObjectGetPrivate (setting); + + return priv->pluginName; +} + +static CCSSettingType +ccsSharedIntegratedSettingInfoGetType (CCSIntegratedSettingInfo *setting) +{ + CCSSharedIntegratedSettingInfoPrivate *priv = (CCSSharedIntegratedSettingInfoPrivate *) ccsObjectGetPrivate (setting); + + return priv->type; +} + +static void +ccsSharedIntegratedSettingInfoFree (CCSIntegratedSettingInfo *setting) +{ + ccsObjectFinalize (setting); + (*setting->object.object_allocation->free_) (setting->object.object_allocation->allocator, setting); +} + +const CCSIntegratedSettingInfoInterface ccsSharedIntegratedSettingInfoInterface = +{ + ccsSharedIntegratedSettingInfoPluginName, + ccsSharedIntegratedSettingInfoSettingName, + ccsSharedIntegratedSettingInfoGetType, + ccsSharedIntegratedSettingInfoFree +}; + +CCSIntegratedSettingInfo * +ccsSharedIntegratedSettingInfoNew (const char *pluginName, + const char *settingName, + CCSSettingType type, + CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSettingInfo *info = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSetting)); + + if (!info) + return NULL; + + CCSSharedIntegratedSettingInfoPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSSharedIntegratedSettingInfoPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, info); + return NULL; + } + + priv->pluginName = pluginName; + priv->settingName = settingName; + priv->type = type; + + ccsObjectInit (info, ai); + ccsObjectSetPrivate (info, (CCSPrivate *) priv); + ccsObjectAddInterface (info, (const CCSInterface *) &ccsSharedIntegratedSettingInfoInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingInfoInterface)); + ccsIntegratedSettingInfoRef (info); + + return info; +} + +CCSIntegratedSettingList +ccsIntegratedSettingsStorageFindMatchingSettingsByPredicate (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSettingsStorageFindPredicate pred, + void *data) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingsStorageInterface, storage))->findMatchingSettingsByPredicate) (storage, pred, data); +} + +CCSIntegratedSettingList +ccsIntegratedSettingsStorageFindMatchingSettingsByPluginAndSettingName (CCSIntegratedSettingsStorage *storage, + const char *pluginName, + const char *settingName) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingsStorageInterface, storage))->findMatchingSettingsByPluginAndSettingName) (storage, pluginName, settingName); +} + +void +ccsIntegratedSettingsStorageAddSetting (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSetting *setting) +{ + (*(GET_INTERFACE (CCSIntegratedSettingsStorageInterface, storage))->addSetting) (storage, setting); +} + +Bool +ccsIntegratedSettingsStorageEmpty (CCSIntegratedSettingsStorage *storage) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingsStorageInterface, storage))->empty) (storage); +} + +void +ccsFreeIntegratedSettingsStorage (CCSIntegratedSettingsStorage *storage) +{ + (*(GET_INTERFACE (CCSIntegratedSettingsStorageInterface, storage))->empty) (storage); +} + +/* CCSIntegratedSettingsStorageDefault implementation */ +typedef struct _CCSIntegratedSettingsStorageDefaultPrivate CCSIntegratedSettingsStorageDefaultPrivate; + +struct _CCSIntegratedSettingsStorageDefaultPrivate +{ + CCSIntegratedSettingList settingList; +}; + +typedef struct _CCSIntegratedSettingsStorageFindByNamesData +{ + const char *pluginName; + const char *settingName; +} CCSIntegratedSettingsStorageFindByNamesData; + +static Bool +ccsIntegratedSettingsStorageFindByNamesPredicate (CCSIntegratedSetting *setting, + void *data) +{ + CCSIntegratedSettingsStorageFindByNamesData *findNamesData = (CCSIntegratedSettingsStorageFindByNamesData *) data; + + const char *sPluginName = ccsIntegratedSettingInfoPluginName ((CCSIntegratedSettingInfo *) setting); + const char *sSettingName = ccsIntegratedSettingInfoSettingName ((CCSIntegratedSettingInfo *) setting); + + if (strcmp (sPluginName, findNamesData->pluginName) == 0 && + strcmp (sSettingName, findNamesData->settingName) == 0) + { + return TRUE; + } + + return FALSE; +} + +CCSIntegratedSettingList +ccsIntegratedSettingsStorageDefaultFindMatchingSettingsByPredicate (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSettingsStorageFindPredicate pred, + void *data) +{ + CCSIntegratedSettingsStorageDefaultPrivate *priv = (CCSIntegratedSettingsStorageDefaultPrivate *) ccsObjectGetPrivate (storage); + CCSIntegratedSettingList returnList = NULL; + CCSIntegratedSettingList iter = priv->settingList; + + while (iter) + { + if ((*pred) (iter->data, data)) + returnList = ccsIntegratedSettingListAppend (returnList, iter->data); + + iter = iter->next; + } + + return returnList; +} + +CCSIntegratedSettingList +ccsIntegratedSettingsStorageDefaultFindMatchingSettingsByPluginAndSettingName (CCSIntegratedSettingsStorage *storage, + const char *pluginName, + const char *settingName) +{ + CCSIntegratedSettingsStorageFindByNamesData data = + { + pluginName, + settingName + }; + + return ccsIntegratedSettingsStorageFindMatchingSettingsByPredicate (storage, ccsIntegratedSettingsStorageFindByNamesPredicate, (void *) &data); +} + +void +ccsIntegratedSettingsStorageDefaultAddSetting (CCSIntegratedSettingsStorage *storage, + CCSIntegratedSetting *setting) +{ + CCSIntegratedSettingsStorageDefaultPrivate *priv = (CCSIntegratedSettingsStorageDefaultPrivate *) ccsObjectGetPrivate (storage); + priv->settingList = ccsIntegratedSettingListAppend (priv->settingList, setting); +} + +Bool +ccsIntegratedSettingsStorageDefaultEmpty (CCSIntegratedSettingsStorage *storage) +{ + CCSIntegratedSettingsStorageDefaultPrivate *priv = (CCSIntegratedSettingsStorageDefaultPrivate *) ccsObjectGetPrivate (storage); + return priv->settingList == NULL; +} + +void +ccsIntegratedSettingsStorageDefaultImplFree (CCSIntegratedSettingsStorage *storage) +{ + CCSIntegratedSettingsStorageDefaultPrivate *priv = (CCSIntegratedSettingsStorageDefaultPrivate *) ccsObjectGetPrivate (storage); + + if (priv->settingList) + ccsIntegratedSettingListFree (priv->settingList, TRUE); + + ccsObjectFinalize (storage); + (*storage->object.object_allocation->free_) (storage->object.object_allocation->allocator, storage); +} + +const CCSIntegratedSettingsStorageInterface ccsIntegratedSettingsStorageDefaultImplInterface = +{ + ccsIntegratedSettingsStorageDefaultFindMatchingSettingsByPredicate, + ccsIntegratedSettingsStorageDefaultFindMatchingSettingsByPluginAndSettingName, + ccsIntegratedSettingsStorageDefaultAddSetting, + ccsIntegratedSettingsStorageDefaultEmpty, + ccsIntegratedSettingsStorageDefaultImplFree +}; + +CCSIntegratedSettingsStorage * +ccsIntegratedSettingsStorageDefaultImplNew (CCSObjectAllocationInterface *ai) +{ + CCSIntegratedSettingsStorage *storage = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSettingsStorage)); + + if (!storage) + return NULL; + + CCSIntegratedSettingsStorageDefaultPrivate *priv = (*ai->calloc_) (ai->allocator, 1, sizeof (CCSIntegratedSettingsStorageDefaultPrivate)); + + if (!priv) + { + (*ai->free_) (ai->allocator, storage); + return NULL; + } + + ccsObjectInit (storage, ai); + ccsObjectSetPrivate (storage, (CCSPrivate *) priv); + ccsObjectAddInterface (storage, (const CCSInterface *) &ccsIntegratedSettingsStorageDefaultImplInterface, GET_INTERFACE_TYPE (CCSIntegratedSettingsStorageInterface)); + + ccsIntegratedSettingsStorageRef (storage); + + return storage; +} + +CCSIntegratedSetting * +ccsIntegratedSettingFactoryCreateIntegratedSettingForCCSSettingNameAndType (CCSIntegratedSettingFactory *factory, + CCSIntegration *integration, + const char *pluginName, + const char *settingName, + CCSSettingType type) +{ + return (*(GET_INTERFACE (CCSIntegratedSettingFactoryInterface, factory))->createIntegratedSettingForCCSSettingNameAndType) (factory, integration, pluginName, settingName, type); +} + +void +ccsFreeIntegratedSettingFactory (CCSIntegratedSettingFactory *factory) +{ + (*(GET_INTERFACE (CCSIntegratedSettingFactoryInterface, factory))->free) (factory); +} + static const CCSPluginInterface ccsDefaultPluginInterface = { ccsPluginGetNameDefault, @@ -4956,7 +5934,8 @@ static const CCSPluginInterface ccsDefaultPluginInterface = ccsGetPluginSettingsDefault, ccsGetPluginGroupsDefault, ccsReadPluginSettingsDefault, - ccsGetPluginStrExtensionsDefault + ccsGetPluginStrExtensionsDefault, + ccsFreePluginDefault }; static const CCSContextInterface ccsDefaultContextInterface = @@ -4994,7 +5973,8 @@ static const CCSContextInterface ccsDefaultContextInterface = ccsGetExistingProfilesDefault, ccsDeleteProfileDefault, ccsCheckForSettingsUpgradeDefault, - ccsLoadPluginsDefault + ccsLoadPluginsDefault, + ccsFreeContextDefault }; static const CCSSettingInterface ccsDefaultSettingInterface = @@ -5039,12 +6019,45 @@ static const CCSSettingInterface ccsDefaultSettingInterface = ccsSettingResetToDefaultDefault, ccsSettingGetIsIntegratedDefault, ccsSettingGetIsReadOnlyDefault, + ccsSettingGetIsReadableByBackendDefault, ccsFreeSettingDefault }; +const CCSBackendInterface ccsDynamicBackendInterfaceWrapper = +{ + ccsDynamicBackendGetInfoWrapper, + ccsDynamicBackendExecuteEventsWrapper, + ccsDynamicBackendInitWrapper, + ccsDynamicBackendFiniWrapper, + ccsDynamicBackendReadInitWrapper, + ccsDynamicBackendReadSettingWrapper, + ccsDynamicBackendReadDoneWrapper, + ccsDynamicBackendWriteInitWrapper, + ccsDynamicBackendWriteSettingWrapper, + ccsDynamicBackendWriteDoneWrapper, + ccsDynamicBackendUpdateSettingWrapper, + ccsDynamicBackendGetSettingIsIntegratedWrapper, + ccsDynamicBackendGetSettingIsReadOnlyWrapper, + ccsDynamicBackendGetExistingProfilesWrapper, + ccsDynamicBackendDeleteProfileWrapper, + ccsDynamicBackendSetIntegrationWrapper +}; + +const CCSDynamicBackendInterface ccsDefaultDynamicBackendInterface = +{ + ccsDynamicBackendGetBackendNameDefault, + ccsDynamicBackendSupportsReadDefault, + ccsDynamicBackendSupportsWriteDefault, + ccsDynamicBackendSupportsIntegrationDefault, + ccsDynamicBackendSupportsProfilesDefault, + ccsDynamicBackendGetRawBackendDefault +}; + const CCSInterfaceTable ccsDefaultInterfaceTable = { &ccsDefaultContextInterface, &ccsDefaultPluginInterface, - &ccsDefaultSettingInterface + &ccsDefaultSettingInterface, + &ccsDynamicBackendInterfaceWrapper, + &ccsDefaultDynamicBackendInterface }; diff --git a/compizconfig/libcompizconfig/tests/CMakeLists.txt b/compizconfig/libcompizconfig/tests/CMakeLists.txt index a37de9091925c80d9d75dbca678a3cd71701a652..cb4d332881a15ee18235406695b0144c7e900dbb 100644 --- a/compizconfig/libcompizconfig/tests/CMakeLists.txt +++ b/compizconfig/libcompizconfig/tests/CMakeLists.txt @@ -1,27 +1,31 @@ include_directories (${GTEST_INCLUDE_DIRS}) include_directories (${CMAKE_SOURCE_DIR}/include) +include_directories (${CMAKE_SOURCE_DIR}/tests/shared) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../mocks/libcompizconfig) +include_directories (${CMAKE_SOURCE_DIR}/compizconfig/tests) link_directories (${CMAKE_INSTALL_PREFIX}/lib) +link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../mocks/libcompizconfig) +link_directories (${CMAKE_CURRENT_BINARY_DIR}/../../tests/) -add_library (context-mock - ${CMAKE_CURRENT_SOURCE_DIR}/context-mock.cpp) +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") -add_library (plugin-mock - ${CMAKE_CURRENT_SOURCE_DIR}/plugin-mock.cpp) +add_executable (compizconfig_test_ccs_object + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_object.cpp) -add_library (setting-mock - ${CMAKE_CURRENT_SOURCE_DIR}/setting-mock.cpp) +add_executable (compizconfig_test_ccs_context + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_context.cpp) -add_executable (test-ccs-object - ${CMAKE_CURRENT_SOURCE_DIR}/test-ccs-object.cpp) +add_executable (compizconfig_test_ccs_plugin + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_plugin.cpp) -add_executable (test-context - ${CMAKE_CURRENT_SOURCE_DIR}/test-context.cpp) +add_executable (compizconfig_test_ccs_setting + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_setting.cpp) -add_executable (test-plugin - ${CMAKE_CURRENT_SOURCE_DIR}/test-plugin.cpp) +add_executable (compizconfig_test_ccs_backend + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_backend.cpp) -add_executable (test-setting - ${CMAKE_CURRENT_SOURCE_DIR}/test-setting.cpp) +add_executable (compizconfig_test_ccs_mock_backend_conformance + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_test_ccs_mock_backend_conformance.cpp) if (HAVE_PROTOBUF) set (LIBCOMPIZCONFIG_LIBRARIES @@ -29,7 +33,7 @@ if (HAVE_PROTOBUF) protobuf) endif (HAVE_PROTOBUF) -target_link_libraries (context-mock +target_link_libraries (compizconfig_test_ccs_object ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} @@ -37,64 +41,65 @@ target_link_libraries (context-mock ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig) -target_link_libraries (plugin-mock +target_link_libraries (compizconfig_test_ccs_context ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig) - -target_link_libraries (setting-mock - ${GTEST_BOTH_LIBRARIES} - ${GMOCK_LIBRARY} - ${GMOCK_MAIN_LIBRARY} - ${CMAKE_THREAD_LIBS_INIT} - ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig) + compizconfig + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock) -target_link_libraries (test-ccs-object +target_link_libraries (compizconfig_test_ccs_plugin ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} - compizconfig) + compizconfig + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock) -target_link_libraries (test-context +target_link_libraries (compizconfig_test_ccs_backend ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig - context-mock - plugin-mock - setting-mock) + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock + compizconfig_ccs_backend_mock) -target_link_libraries (test-plugin +target_link_libraries (compizconfig_test_ccs_mock_backend_conformance ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig - context-mock - plugin-mock - setting-mock) + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock + compizconfig_ccs_backend_mock) -target_link_libraries (test-setting +target_link_libraries (compizconfig_test_ccs_setting ${GTEST_BOTH_LIBRARIES} ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${LIBCOMPIZCONFIG_LIBRARIES} compizconfig - context-mock - plugin-mock - setting-mock) - -compiz_discover_tests (test-ccs-object COVERAGE compizconfig) -compiz_discover_tests (test-context COVERAGE context-mock) -compiz_discover_tests (test-plugin COVERAGE plugin-mock) -compiz_discover_tests (test-setting COVERAGE setting-mock) + compizconfig_ccs_context_mock + compizconfig_ccs_plugin_mock + compizconfig_ccs_setting_mock) + +compiz_discover_tests (compizconfig_test_ccs_object COVERAGE compizconfig) +compiz_discover_tests (compizconfig_test_ccs_context COVERAGE compizconfig_ccs_context_mock) +compiz_discover_tests (compizconfig_test_ccs_plugin COVERAGE compizconfig_ccs_plugin_mock) +compiz_discover_tests (compizconfig_test_ccs_setting COVERAGE compizconfig_ccs_setting_mock) +compiz_discover_tests (compizconfig_test_ccs_mock_backend_conformance COVERAGE compizconfig_ccs_backend_mock) diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e4099beb9b3304e4a5901d51004f4df49dd11b8 --- /dev/null +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_backend.cpp @@ -0,0 +1,52 @@ +#include +#include + +#include + +#include "compizconfig_ccs_backend_mock.h" + +using ::testing::_; +using ::testing::ReturnNull; + +class CCSBackendTest : + public ::testing::Test +{ +}; + +TEST(CCSBackendTest, TestMock) +{ + CCSBackend *backend = ccsMockBackendNew (); + CCSBackendGMock *mock = (CCSBackendGMock *) ccsObjectGetPrivate (backend); + + EXPECT_CALL (*mock, getInfo ()); + EXPECT_CALL (*mock, executeEvents (_)); + EXPECT_CALL (*mock, init (_)); + EXPECT_CALL (*mock, fini ()); + EXPECT_CALL (*mock, readInit (_)); + EXPECT_CALL (*mock, readSetting (_,_)); + EXPECT_CALL (*mock, readDone (_)); + EXPECT_CALL (*mock, writeInit (_)); + EXPECT_CALL (*mock, writeSetting (_, _)); + EXPECT_CALL (*mock, writeDone (_)); + EXPECT_CALL (*mock, getSettingIsIntegrated (_)); + EXPECT_CALL (*mock, getSettingIsReadOnly (_)); + EXPECT_CALL (*mock, getExistingProfiles (_)).WillRepeatedly (ReturnNull ()); + EXPECT_CALL (*mock, deleteProfile (_, _)); + + ccsBackendGetInfo (backend); + ccsBackendExecuteEvents (backend, 0); + ccsBackendInit (backend, NULL); + ccsBackendFini (backend); + ccsBackendReadInit (backend, NULL); + ccsBackendReadSetting (backend, NULL, NULL); + ccsBackendReadDone (backend, NULL); + ccsBackendWriteInit (backend, NULL); + ccsBackendWriteSetting (backend, NULL, NULL); + ccsBackendWriteDone (backend, NULL); + ccsBackendGetSettingIsIntegrated (backend, NULL); + ccsBackendGetSettingIsReadOnly (backend, NULL); + ccsBackendGetExistingProfiles (backend, NULL); + ccsBackendDeleteProfile (backend, NULL, NULL); + + ccsFreeMockBackend (backend); +} diff --git a/compizconfig/libcompizconfig/tests/test-context.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_context.cpp similarity index 97% rename from compizconfig/libcompizconfig/tests/test-context.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_context.cpp index 197411aa62a2d74484e2a11a2f9569acc5ff8be8..22d576806ae14d6be1eaf2760dac9bd88cde4231 100644 --- a/compizconfig/libcompizconfig/tests/test-context.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_context.cpp @@ -3,7 +3,7 @@ #include -#include "mock-context.h" +#include "compizconfig_ccs_context_mock.h" using ::testing::_; using ::testing::Return; @@ -90,5 +90,5 @@ TEST(CCSContextTest, TestMock) free (foo); free (bar); - ccsFreeMockContext (context); + ccsFreeContext (context); } diff --git a/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e8a088b342db8076c7dbc82b76759afcaf889e45 --- /dev/null +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_mock_backend_conformance.cpp @@ -0,0 +1,819 @@ +#include +#include + +#include + +#include +#include + +#include "compizconfig_ccs_backend_mock.h" + +using ::testing::_; +using ::testing::Return; +using ::testing::Invoke; +using ::testing::WithArgs; +using ::testing::Combine; +using ::testing::ValuesIn; +using ::testing::Values; +using ::testing::AtLeast; + +namespace +{ +std::string keynameFromPluginKey (const std::string &plugin, + const std::string &key) +{ + return plugin + "/" + key; +} +} + +template +class ValueForKeyRetreival +{ + public: + + T GetValueForKey (const std::string &key, + const std::map &map) + { + std::map ::const_iterator it = map.find (key); + + if (it != map.end ()) + return boost::get (it->second); + else + throw std::exception (); + } +}; + +namespace +{ + void doNothingWithCCSSetting (CCSSetting *) {}; + + const CCSBackendInfo mockBackendInfo = + { + "mock", + "Mock Backend", + "Mock Backend for libccs", + TRUE, + TRUE + }; +} + +class MockCCSSettingsTestEnvironment : + public CCSSettingsConceptTestEnvironmentInterface +{ + public: + + virtual void SetUp () + { + } + + virtual void TearDown () + { + } + + void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + void WriteListAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mValues[keynameFromPluginKey (plugin, key)] = value; + } + + virtual Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) + { + return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + } + + virtual int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual float ReadFloatAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) + { + return ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues); + } + + virtual Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) + { + return boolToBool (ValueForKeyRetreival ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + } + + virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key, + CCSSetting *setting) + { + CCSListWrapper::Ptr lw (ValueForKeyRetreival > ().GetValueForKey (keynameFromPluginKey (plugin, key), mValues)); + + return ccsCopyList (*lw, lw->setting ().get ()); + } + + private: + + std::map mValues; +}; + +class MockCCSBackendConceptTestEnvironment : + public CCSBackendConceptTestEnvironmentInterface +{ + private: + + virtual void SetUp () + { + mMockCCSSettingTestEnvironment.SetUp (); + } + + virtual void TearDown () + { + mMockCCSSettingTestEnvironment.SetUp (); + } + + public: + + CCSBackend * SetUp (CCSContext *context, CCSContextGMock *gmockContext) + { + mContext = context; + mBackend = ccsMockBackendNew (); + mBackendGMock = (CCSBackendGMock *) ccsObjectGetPrivate (mBackend); + + ON_CALL (*mBackendGMock, readSetting (_, _)) + .WillByDefault ( + WithArgs<1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + + ON_CALL (*mBackendGMock, updateSetting (_, _, _)) + .WillByDefault ( + WithArgs<2> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::ReadValueIntoSetting))); + + ON_CALL (*mBackendGMock, writeSetting (_, _)) + .WillByDefault ( + WithArgs<1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::WriteValueToMap))); + + ON_CALL (*mBackendGMock, deleteProfile (_, _)) + .WillByDefault ( + WithArgs <1> ( + Invoke ( + this, + &MockCCSBackendConceptTestEnvironment::DeleteProfile))); + + return mBackend; + } + + const CCSBackendInfo * GetInfo () + { + EXPECT_CALL (*mBackendGMock, getInfo ()).WillOnce (Return (&mockBackendInfo)); + + return &mockBackendInfo; + } + + void TearDown (CCSBackend *backend) + { + ccsFreeMockBackend (backend); + } + + void AddProfile (const std::string &profile) + { + mProfiles.push_back (profile); + } + + void SetGetExistingProfilesExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + CCSStringList stringList = NULL; + + CCSString *defaultProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + CCSString *currentProfile = reinterpret_cast (calloc (1, sizeof (CCSString))); + + EXPECT_CALL (*gmockContext, getProfile ()); + + defaultProfile->value = strdup ("Default"); + currentProfile->value = strdup (ccsGetProfile (context)); + + ccsStringRef (defaultProfile); + ccsStringRef (currentProfile); + + stringList = ccsStringListAppend (stringList, defaultProfile); + stringList = ccsStringListAppend (stringList, currentProfile); + + for (std::vector ::iterator it = mProfiles.begin (); + it != mProfiles.end (); + ++it) + { + if (*it == defaultProfile->value || + *it == currentProfile->value) + continue; + + CCSString *string = reinterpret_cast (calloc (1, sizeof (CCSString))); + + string->value = strdup ((*it).c_str ()); + ccsStringRef (string); + + stringList = ccsStringListAppend (stringList, string); + } + + EXPECT_CALL (*mBackendGMock, getExistingProfiles (context)).WillOnce (Return (stringList)); + } + + void SetDeleteProfileExpectation (const std::string &profileForDeletion, + CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, deleteProfile (context, + Eq (profileForDeletion))); + } + + void SetReadInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, readInit (context)).WillOnce (Return (TRUE)); + } + + void SetReadDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, readDone (context)); + } + + void SetWriteInitExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, writeInit (context)).WillOnce (Return (TRUE)); + } + + void SetWriteDoneExpectation (CCSContext *context, + CCSContextGMock *gmockContext) + { + EXPECT_CALL (*mBackendGMock, writeDone (context)); + } + + void PreWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, writeSetting (_, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getDefaultValue ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } + } + + void PostWrite (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + + void PreRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, readSetting (_, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } + } + + void PostRead (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + + void PreUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + EXPECT_CALL (*mBackendGMock, updateSetting (_, _, _)); + EXPECT_CALL (*gmockPlugin, getName ()); + EXPECT_CALL (*gmockSetting, getName ()); + EXPECT_CALL (*gmockSetting, getParent ()); + + if (type == TypeList) + { + EXPECT_CALL (*gmockSetting, getType ()).Times (AtLeast (1)); + EXPECT_CALL (*gmockSetting, getInfo ()).Times (AtLeast (1)); + } + else + { + EXPECT_CALL (*gmockSetting, getType ()); + } + } + + void PostUpdate (CCSContextGMock *gmockContext, + CCSPluginGMock *gmockPlugin, + CCSSettingGMock *gmockSetting, + CCSSettingType type) + { + } + + bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) + { + CCSPlugin *cplugin = ccsFindPlugin (mContext, plugin.c_str ()); + + if (!cplugin) + return false; + + CCSSetting *csetting = ccsFindSetting (cplugin, setting.c_str ()); + + if (!csetting) + return false; + + ccsBackendUpdateSetting (mBackend, mContext, cplugin, csetting); + return true; + } + + void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteBoolAtKey (plugin, key, value); + } + + void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + + { + mMockCCSSettingTestEnvironment.WriteIntegerAtKey (plugin, key, value); + } + + void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteFloatAtKey (plugin, key, value); + } + + void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteMatchAtKey (plugin, key, value);; + } + + void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteStringAtKey (plugin, key, value); + } + + void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteColorAtKey (plugin, key, value); + } + + void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteKeyAtKey (plugin, key, value); + } + + void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteButtonAtKey (plugin, key, value); + } + + void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteEdgeAtKey (plugin, key, value); + } + + void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteBellAtKey (plugin, key, value); + } + + void WriteListAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) + { + mMockCCSSettingTestEnvironment.WriteListAtKey (plugin, key, value); + } + + virtual Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadBoolAtKey (plugin, key); + } + + virtual int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadIntegerAtKey (plugin, key); + } + + virtual float ReadFloatAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadFloatAtKey (plugin, key);; + } + + virtual const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadStringAtKey (plugin, key); + } + + virtual CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadColorAtKey (plugin, key); + } + + virtual CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadKeyAtKey (plugin, key); + } + + virtual CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadButtonAtKey (plugin, key); + } + + virtual unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadEdgeAtKey (plugin, key); + } + + virtual const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadMatchAtKey (plugin, key); + } + + virtual Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) + { + return mMockCCSSettingTestEnvironment.ReadBellAtKey (plugin, key); + } + + virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key, + CCSSetting *setting) + { + return mMockCCSSettingTestEnvironment.ReadListAtKey (plugin, key, setting); + } + + protected: + + bool DeleteProfile (const std::string &profileToDelete) + { + std::vector ::iterator it = std::find (mProfiles.begin (), + mProfiles.end (), + profileToDelete); + + if (it != mProfiles.end ()) + { + mProfiles.erase (it); + return true; + } + else + { + return false; + } + } + + private: + + void ReadValueIntoSetting (CCSSetting *setting) + { + std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); + std::string key (ccsSettingGetName (setting)); + + switch (ccsSettingGetType (setting)) + { + case TypeBool: + + ccsSetBool (setting, ReadBoolAtKey (plugin, key), FALSE); + break; + + case TypeInt: + + ccsSetInt (setting, ReadIntegerAtKey (plugin, key), FALSE); + break; + + case TypeFloat: + + ccsSetFloat (setting, ReadFloatAtKey (plugin, key), FALSE); + break; + + case TypeString: + + ccsSetString (setting, ReadStringAtKey (plugin, key), FALSE); + break; + + case TypeMatch: + + ccsSetMatch (setting, ReadMatchAtKey (plugin, key), FALSE); + break; + + case TypeColor: + + ccsSetColor (setting, ReadColorAtKey (plugin, key), FALSE); + break; + + case TypeKey: + + ccsSetKey (setting, ReadKeyAtKey (plugin, key), FALSE); + break; + + case TypeButton: + + ccsSetButton (setting, ReadButtonAtKey (plugin, key), FALSE); + break; + + case TypeEdge: + + ccsSetEdge (setting, ReadEdgeAtKey (plugin, key), FALSE); + break; + + case TypeBell: + + ccsSetBell (setting, ReadBellAtKey (plugin, key), FALSE); + break; + + case TypeList: + ccsSetList (setting, CCSListWrapper (ReadListAtKey (plugin, key, setting), + true, + ccsSettingGetInfo (setting)->forList.listType, + boost::shared_ptr (), + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))), FALSE); + break; + + default: + + throw std::exception (); + } + } + + void WriteValueToMap (CCSSetting *setting) + { + std::string plugin (ccsPluginGetName (ccsSettingGetParent (setting))); + std::string key (ccsSettingGetName (setting)); + + Bool vBool; + int vInt; + float vFloat; + char *vString; + CCSSettingColorValue vColor; + CCSSettingKeyValue vKey; + CCSSettingButtonValue vButton; + unsigned int vEdge; + CCSSettingValueList vList; + + switch (ccsSettingGetType (setting)) + { + case TypeBool: + + ccsGetBool (setting, &vBool); + WriteBoolAtKey (plugin, key, VariantTypes (vBool ? true : false)); + break; + + case TypeInt: + + ccsGetInt (setting, &vInt); + WriteIntegerAtKey (plugin, key, VariantTypes (vInt)); + break; + + case TypeFloat: + + ccsGetFloat (setting, &vFloat); + WriteFloatAtKey (plugin, key, VariantTypes (vFloat)); + break; + + case TypeString: + + ccsGetString (setting, &vString); + WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); + break; + + case TypeMatch: + + ccsGetMatch (setting, &vString); + WriteStringAtKey (plugin, key, VariantTypes (static_cast (vString))); + break; + + case TypeColor: + + ccsGetColor (setting, &vColor); + WriteColorAtKey (plugin, key, VariantTypes (vColor)); + break; + + case TypeKey: + + ccsGetKey (setting, &vKey); + WriteKeyAtKey (plugin, key, VariantTypes (vKey)); + break; + + case TypeButton: + + ccsGetButton (setting, &vButton); + WriteButtonAtKey (plugin, key, VariantTypes (vButton)); + break; + + case TypeEdge: + + ccsGetEdge (setting, &vEdge); + WriteEdgeAtKey (plugin, key, VariantTypes (vEdge)); + break; + + case TypeBell: + + ccsGetBell (setting, &vBool); + WriteBellAtKey (plugin, key, VariantTypes (vBool ? true : false)); + break; + + case TypeList: + { + CCSSettingValueList listCopy = NULL; + + ccsGetList (setting, &vList); + listCopy = ccsCopyList (vList, setting); + + WriteListAtKey (plugin, key, VariantTypes (boost::make_shared (listCopy, true, + ccsSettingGetInfo (setting)->forList.listType, + boost::shared_ptr (), + boost::shared_ptr (setting, boost::bind (doNothingWithCCSSetting, _1))))); + break; + } + default: + + throw std::exception (); + } + } + + private: + + MockCCSSettingsTestEnvironment mMockCCSSettingTestEnvironment; + CCSBackend *mBackend; + CCSBackendGMock *mBackendGMock; + CCSContext *mContext; + std::vector mProfiles; +}; + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestReadWrite, + compizconfig::test::GenerateTestingParametersForBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInfo, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestInitFiniFuncs, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); + +INSTANTIATE_TEST_CASE_P (MockCCSBackendConcept, CCSBackendConformanceTestProfileHandling, + compizconfig::test::GenerateTestingEnvFactoryBackendInterface ()); diff --git a/compizconfig/libcompizconfig/tests/test-ccs-object.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp similarity index 82% rename from compizconfig/libcompizconfig/tests/test-ccs-object.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp index 28881df31f78e9b6b6762b3220d2dc8e974afca4..6c957756c1887c46c15b883551b1dc992976cb4f 100644 --- a/compizconfig/libcompizconfig/tests/test-ccs-object.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_object.cpp @@ -6,6 +6,7 @@ #include #include +#include using ::testing::_; using ::testing::Return; @@ -225,83 +226,6 @@ TEST(CCSObjectTest, TestFinalizeFreesEverything) free (to); } -class AllocationInterface -{ - public: - - virtual void * realloc_ (void *, size_t) = 0; - virtual void * malloc_ (size_t) = 0; - virtual void * calloc_ (size_t, size_t) = 0; - virtual void free_ (void *) = 0; - - public: - - static void * wrapRealloc (void *o, void *a , size_t b) - { - AllocationInterface *ao = static_cast (o); - return ao->realloc_ (a, b); - } - - static void * wrapMalloc (void *o, size_t a) - { - AllocationInterface *ao = static_cast (o); - return ao->malloc_ (a); - } - - static void * wrapCalloc (void *o, size_t a, size_t b) - { - AllocationInterface *ao = static_cast (o); - return ao->calloc_ (a, b); - } - - static void wrapFree (void *o, void *a) - { - AllocationInterface *ao = static_cast (o); - ao->free_ (a); - } -}; - -class ObjectAllocationGMock : - public AllocationInterface -{ - public: - - MOCK_METHOD2 (realloc_, void * (void *, size_t)); - MOCK_METHOD1 (malloc_, void * (size_t)); - MOCK_METHOD2 (calloc_, void * (size_t, size_t)); - MOCK_METHOD1 (free_, void (void *)); - -}; - -class FailingObjectReallocation : - public AllocationInterface -{ - public: - - FailingObjectReallocation (unsigned int sc) : - successCount (sc) - { - } - - void * realloc_ (void *a, size_t b) { unsigned int c = successCount--; if (c) return realloc (a, b); else return NULL; } - void * malloc_ (size_t a) { return malloc (a); } - void * calloc_ (size_t n, size_t a) { return calloc (n, a); } - void free_ (void *a) { free (a); } - - private: - - unsigned int successCount; -}; - -CCSObjectAllocationInterface failingAllocator = -{ - AllocationInterface::wrapRealloc, - AllocationInterface::wrapMalloc, - AllocationInterface::wrapCalloc, - AllocationInterface::wrapFree, - NULL -}; - TEST(CCSObjectTest, TestReallocFailures) { TestingObjectWrapper *to = (TestingObjectWrapper *) calloc (1, sizeof (TestingObjectWrapper)); diff --git a/compizconfig/libcompizconfig/tests/test-plugin.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_plugin.cpp similarity index 96% rename from compizconfig/libcompizconfig/tests/test-plugin.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_plugin.cpp index 52b816fb09f4b4195e02d1427e1560c22010367a..faead208d51636e6ca05a45795eeb25c1d4170ef 100644 --- a/compizconfig/libcompizconfig/tests/test-plugin.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_plugin.cpp @@ -3,7 +3,7 @@ #include -#include "mock-plugin.h" +#include "compizconfig_ccs_plugin_mock.h" using ::testing::_; using ::testing::Return; @@ -56,5 +56,5 @@ TEST(CCSPluginTest, TestMock) ccsReadPluginSettings (plugin); ccsGetPluginStrExtensions (plugin); - ccsFreeMockPlugin (plugin); + ccsPluginUnref (plugin); } diff --git a/compizconfig/libcompizconfig/tests/test-setting.cpp b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp similarity index 95% rename from compizconfig/libcompizconfig/tests/test-setting.cpp rename to compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp index 12017e5a0d61245e2ce48d096a4309e0e6647c50..4ded6ed9aa0cac1bf9dba0f21b311afa6597fb2c 100644 --- a/compizconfig/libcompizconfig/tests/test-setting.cpp +++ b/compizconfig/libcompizconfig/tests/compizconfig_test_ccs_setting.cpp @@ -3,7 +3,7 @@ #include -#include "mock-setting.h" +#include "compizconfig_ccs_setting_mock.h" using ::testing::_; using ::testing::Return; @@ -58,6 +58,7 @@ TEST(CCSSettingTest, TestMock) EXPECT_CALL (*mock, resetToDefault (_)); EXPECT_CALL (*mock, isIntegrated ()); EXPECT_CALL (*mock, isReadOnly ()); + EXPECT_CALL (*mock, isReadableByBackend ()); CCSSettingColorValue cv; CCSSettingKeyValue kv; @@ -104,6 +105,7 @@ TEST(CCSSettingTest, TestMock) ccsResetToDefault (setting, FALSE); ccsSettingIsIntegrated (setting); ccsSettingIsReadOnly (setting); + ccsSettingIsReadableByBackend (setting); - ccsFreeMockSetting (setting); + ccsSettingUnref (setting); } diff --git a/compizconfig/mocks/CMakeLists.txt b/compizconfig/mocks/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b288ae8e1e60bac6cf5469d719dc832527755c08 --- /dev/null +++ b/compizconfig/mocks/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (libcompizconfig) diff --git a/compizconfig/mocks/libcompizconfig/CMakeLists.txt b/compizconfig/mocks/libcompizconfig/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1e87fc7099c433c03588cde6e6a81a8df0fa8e00 --- /dev/null +++ b/compizconfig/mocks/libcompizconfig/CMakeLists.txt @@ -0,0 +1,53 @@ +include_directories (${GTEST_INCLUDE_DIRS}) +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../libcompizconfig/include) +link_directories (${CMAKE_INSTALL_PREFIX}/lib) + +if (HAVE_PROTOBUF) + set (LIBCOMPIZCONFIG_LIBRARIES + ${LIBCOMPIZCONFIG_LIBRARIES} + protobuf) +endif (HAVE_PROTOBUF) + +add_library (compizconfig_ccs_context_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_context_mock.cpp) + +add_library (compizconfig_ccs_plugin_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_plugin_mock.cpp) + +add_library (compizconfig_ccs_setting_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_setting_mock.cpp) + +add_library (compizconfig_ccs_backend_mock + ${CMAKE_CURRENT_SOURCE_DIR}/compizconfig_ccs_backend_mock.cpp) + +target_link_libraries (compizconfig_ccs_context_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) + +target_link_libraries (compizconfig_ccs_plugin_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) + +target_link_libraries (compizconfig_ccs_setting_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) + +target_link_libraries (compizconfig_ccs_backend_mock + ${GTEST_BOTH_LIBRARIES} + ${GMOCK_LIBRARY} + ${GMOCK_MAIN_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${LIBCOMPIZCONFIG_LIBRARIES} + compizconfig) diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a65ab6c775e13527089cf70ca7b8936b34bc750 --- /dev/null +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.cpp @@ -0,0 +1,59 @@ +#include +#include + +#include + +#include "compizconfig_ccs_backend_mock.h" + +CCSBackendInterface CCSBackendGMockInterface = +{ + CCSBackendGMock::ccsBackendGetInfo, + CCSBackendGMock::ccsBackendExecuteEvents, + CCSBackendGMock::ccsBackendInit, + CCSBackendGMock::ccsBackendFini, + CCSBackendGMock::ccsBackendReadInit, + CCSBackendGMock::ccsBackendReadSetting, + CCSBackendGMock::ccsBackendReadDone, + CCSBackendGMock::ccsBackendWriteInit, + CCSBackendGMock::ccsBackendWriteSetting, + CCSBackendGMock::ccsBackendWriteDone, + CCSBackendGMock::ccsBackendUpdateSetting, + CCSBackendGMock::ccsBackendGetSettingIsIntegrated, + CCSBackendGMock::ccsBackendGetSettingIsReadOnly, + CCSBackendGMock::ccsBackendGetExistingProfiles, + CCSBackendGMock::ccsBackendDeleteProfile +}; + +CCSBackend * +ccsMockBackendNew () +{ + CCSBackend *backend = (CCSBackend *) calloc (1, sizeof (CCSBackend)); + + if (!backend) + return NULL; + + ccsObjectInit (backend, &ccsDefaultObjectAllocator); + + CCSBackendGMock *mock = new CCSBackendGMock (backend); + ccsObjectSetPrivate (backend, (CCSPrivate *) mock); + ccsObjectAddInterface (backend, (CCSInterface *) &CCSBackendGMockInterface, GET_INTERFACE_TYPE (CCSBackendInterface)); + + ccsBackendRef (backend); + + return backend; +} + +void +ccsFreeMockBackend (CCSBackend *backend) +{ + /* Need to delete the mock correctly */ + + CCSBackendGMock *mock = (CCSBackendGMock *) ccsObjectGetPrivate (backend); + + delete mock; + + ccsObjectSetPrivate (backend, NULL); + ccsObjectFinalize (backend); + + free (backend); +} diff --git a/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..c36627b2ab5d69a8dbd26e47ff42d323a67e83d2 --- /dev/null +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_backend_mock.h @@ -0,0 +1,150 @@ +#ifndef _COMPIZCONFIG_CCS_BACKEND_MOCK_H +#define _COMPIZCONFIG_CCS_BACKEND_MOCK_H + +#include +#include + +#include + +CCSBackend * ccsMockBackendNew (); +void ccsFreeMockBackend (CCSBackend *); + +class CCSBackendGMockInterface +{ + public: + + virtual ~CCSBackendGMockInterface () {}; + + virtual const CCSBackendInfo * getInfo () = 0; + virtual void executeEvents (unsigned int) = 0; + virtual Bool init (CCSContext *context) = 0; + virtual Bool fini () = 0; + virtual Bool readInit (CCSContext *context) = 0; + virtual void readSetting (CCSContext *context, CCSSetting *setting) = 0; + virtual void readDone (CCSContext *context) = 0; + virtual Bool writeInit (CCSContext *conxtext) = 0; + virtual void writeSetting (CCSContext *context, CCSSetting *setting) = 0; + virtual void writeDone (CCSContext *context) = 0; + virtual void updateSetting (CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) = 0; + virtual Bool getSettingIsIntegrated (CCSSetting *setting) = 0; + virtual Bool getSettingIsReadOnly (CCSSetting *setting) = 0; + virtual CCSStringList getExistingProfiles (CCSContext *context) = 0; + virtual Bool deleteProfile (CCSContext *context, char *name) = 0; +}; + +class CCSBackendGMock : + public CCSBackendGMockInterface +{ + public: + + CCSBackendGMock (CCSBackend *b) : + mBackend (b) + { + } + + CCSBackend * backend () { return mBackend; } + + /* Mock implementations */ + MOCK_METHOD0 (getInfo, const CCSBackendInfo * ()); + MOCK_METHOD1 (executeEvents, void (unsigned int)); + MOCK_METHOD1 (init, Bool (CCSContext *)); + MOCK_METHOD0 (fini, Bool ()); + MOCK_METHOD1 (readInit, Bool (CCSContext *)); + MOCK_METHOD2 (readSetting, void (CCSContext *, CCSSetting *)); + MOCK_METHOD1 (readDone, void (CCSContext *)); + MOCK_METHOD1 (writeInit, Bool (CCSContext *)); + MOCK_METHOD2 (writeSetting, void (CCSContext *, CCSSetting *)); + MOCK_METHOD1 (writeDone, void (CCSContext *)); + MOCK_METHOD3 (updateSetting, void (CCSContext *, CCSPlugin *, CCSSetting *)); + MOCK_METHOD1 (getSettingIsIntegrated, Bool (CCSSetting *)); + MOCK_METHOD1 (getSettingIsReadOnly, Bool (CCSSetting *)); + MOCK_METHOD1 (getExistingProfiles, CCSStringList (CCSContext *)); + MOCK_METHOD2 (deleteProfile, Bool (CCSContext *, char *name)); + + private: + + CCSBackend *mBackend; + + public: + + /* Thunking C to C++ */ + static const CCSBackendInfo * ccsBackendGetInfo (CCSBackend *backend) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getInfo (); + } + + static void ccsBackendExecuteEvents (CCSBackend *backend, unsigned int flags) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->executeEvents (flags); + } + + static Bool ccsBackendInit (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->init (context); + } + + static Bool ccsBackendFini (CCSBackend *backend) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->fini (); + } + + static Bool ccsBackendReadInit (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->readInit (context); + } + + static void ccsBackendReadSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->readSetting (context, setting); + } + + static void ccsBackendReadDone (CCSBackend *backend, CCSContext *context) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->readDone (context); + } + + static Bool ccsBackendWriteInit (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeInit (context); + } + + static void ccsBackendWriteSetting (CCSBackend *backend, CCSContext *context, CCSSetting *setting) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeSetting (context, setting); + } + + static void ccsBackendWriteDone (CCSBackend *backend, CCSContext *context) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->writeDone (context); + } + + static void ccsBackendUpdateSetting (CCSBackend *backend, CCSContext *context, CCSPlugin *plugin, CCSSetting *setting) + { + ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->updateSetting (context, plugin, setting); + } + + static Bool ccsBackendGetSettingIsIntegrated (CCSBackend *backend, CCSSetting *setting) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getSettingIsIntegrated (setting); + } + + static Bool ccsBackendGetSettingIsReadOnly (CCSBackend *backend, CCSSetting *setting) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getSettingIsReadOnly (setting); + } + + static CCSStringList ccsBackendGetExistingProfiles (CCSBackend *backend, CCSContext *context) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->getExistingProfiles (context); + } + + static Bool ccsBackendDeleteProfile (CCSBackend *backend, CCSContext *context, char *name) + { + return ((CCSBackendGMock *) ccsObjectGetPrivate (backend))->deleteProfile (context, name); + } + +}; + +extern CCSBackendInterface CCSBackendGMockInterface; + +#endif diff --git a/compizconfig/libcompizconfig/tests/context-mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp similarity index 92% rename from compizconfig/libcompizconfig/tests/context-mock.cpp rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp index 4d70bb4eac270401b5fe135b12867d52936fdba3..2c483dc78ec31dafc836e33256c3c07dd8f2289e 100644 --- a/compizconfig/libcompizconfig/tests/context-mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.cpp @@ -3,7 +3,7 @@ #include -#include "mock-context.h" +#include "compizconfig_ccs_context_mock.h" CCSContextInterface CCSContextGMockInterface = { @@ -40,7 +40,8 @@ CCSContextInterface CCSContextGMockInterface = CCSContextGMock::ccsGetExistingProfiles, CCSContextGMock::ccsDeleteProfile, CCSContextGMock::ccsCheckForSettingsUpgrade, - CCSContextGMock::ccsLoadPlugins + CCSContextGMock::ccsLoadPlugins, + CCSContextGMock::ccsFreeContext }; CCSContext * @@ -53,7 +54,7 @@ ccsMockContextNew () ccsObjectInit (context, &ccsDefaultObjectAllocator); - CCSContextGMock *mock = new CCSContextGMock (); + CCSContextGMock *mock = new CCSContextGMock (context); ccsObjectSetPrivate (context, (CCSPrivate *) mock); ccsObjectAddInterface (context, (CCSInterface *) &CCSContextGMockInterface, GET_INTERFACE_TYPE (CCSContextInterface)); diff --git a/compizconfig/libcompizconfig/tests/mock-context.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h similarity index 95% rename from compizconfig/libcompizconfig/tests/mock-context.h rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h index c3ea63c8706fe6bab38e43db4f235fe6f30ada43..3f5246b9b58c27e66176d46e89ac308b92f13da2 100644 --- a/compizconfig/libcompizconfig/tests/mock-context.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_context_mock.h @@ -3,6 +3,9 @@ #include +CCSContext * ccsMockContextNew (); +void ccsFreeMockContext (CCSContext *); + class CCSContextGMockInterface { public: @@ -23,12 +26,12 @@ class CCSContextGMockInterface virtual Bool pluginIsActive (char *name) = 0; virtual CCSPluginList getActivePluginList () = 0; virtual CCSStringList getSortedPluginStringList () = 0; - virtual char * getBackend () = 0; + virtual const char * getBackend () = 0; virtual Bool setBackend (char *name) = 0; virtual void setIntegrationEnabled (Bool value) = 0; virtual void setProfile (char *name) = 0; virtual void setPluginListAutoSort (Bool value) = 0; - virtual char * getProfile () = 0; + virtual const char * getProfile () = 0; virtual Bool getIntegrationEnabled () = 0; virtual Bool getPluginListAutoSort () = 0; virtual void processEvents (unsigned int flags) = 0; @@ -50,6 +53,13 @@ class CCSContextGMock : { public: + CCSContextGMock (CCSContext *c) : + mContext (c) + { + } + + CCSContext * context () { return mContext; } + MOCK_METHOD0 (getPlugins, CCSPluginList ()); MOCK_METHOD0 (getCategories, CCSPluginCategory * ()); MOCK_METHOD0 (getChangedSettings, CCSSettingList ()); @@ -64,12 +74,12 @@ class CCSContextGMock : MOCK_METHOD1 (pluginIsActive, Bool (char *)); MOCK_METHOD0 (getActivePluginList, CCSPluginList ()); MOCK_METHOD0 (getSortedPluginStringList, CCSStringList ()); - MOCK_METHOD0 (getBackend, char * ()); + MOCK_METHOD0 (getBackend, const char * ()); MOCK_METHOD1 (setBackend, Bool (char *)); MOCK_METHOD1 (setIntegrationEnabled, void (Bool)); MOCK_METHOD1 (setProfile, void (char *)); MOCK_METHOD1 (setPluginListAutoSort, void (Bool)); - MOCK_METHOD0 (getProfile, char * ()); + MOCK_METHOD0 (getProfile, const char * ()); MOCK_METHOD0 (getIntegrationEnabled, Bool ()); MOCK_METHOD0 (getPluginListAutoSort, Bool ()); MOCK_METHOD1 (processEvents, void (unsigned int)); @@ -85,6 +95,10 @@ class CCSContextGMock : MOCK_METHOD0 (checkForSettingsUpgrade, Bool ()); MOCK_METHOD0 (loadPlugins, void ()); + private: + + CCSContext *mContext; + public: /* Thunking from C interface callbacks to the virtual functions ... */ @@ -172,7 +186,7 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getSortedPluginStringList (); } - static char * + static const char * ccsGetBackend (CCSContext *context) { return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getBackend (); @@ -187,7 +201,7 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->getIntegrationEnabled (); } - static char * + static const char * ccsGetProfile (CCSContext *context) { if (!context) @@ -330,9 +344,15 @@ class CCSContextGMock : return ((CCSContextGMock *) ccsObjectGetPrivate (context))->loadPlugins (); } + + static void + ccsFreeContext (CCSContext *context) + { + if (!context) + return; + + ccsFreeMockContext (context); + } }; extern CCSContextInterface CCSContextGMockInterface; - -CCSContext * ccsMockContextNew (); -void ccsFreeMockContext (CCSContext *); diff --git a/compizconfig/libcompizconfig/tests/plugin-mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp similarity index 89% rename from compizconfig/libcompizconfig/tests/plugin-mock.cpp rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp index aa559877402b6b545ed1feedd347287c26474085..c4abc268fedddce61e5445e811b1be18da1aef15 100644 --- a/compizconfig/libcompizconfig/tests/plugin-mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.cpp @@ -3,7 +3,7 @@ #include -#include "mock-plugin.h" +#include "compizconfig_ccs_plugin_mock.h" CCSPluginInterface CCSPluginGMockInterface = { @@ -25,7 +25,8 @@ CCSPluginInterface CCSPluginGMockInterface = CCSPluginGMock::ccsGetPluginSettings, CCSPluginGMock::ccsGetPluginGroups, CCSPluginGMock::ccsReadPluginSettings, - CCSPluginGMock::ccsGetPluginStrExtensions + CCSPluginGMock::ccsGetPluginStrExtensions, + CCSPluginGMock::ccsFreePlugin }; CCSPlugin * @@ -38,7 +39,7 @@ ccsMockPluginNew () ccsObjectInit (plugin, &ccsDefaultObjectAllocator); - CCSPluginGMock *mock = new CCSPluginGMock (); + CCSPluginGMock *mock = new CCSPluginGMock (plugin); ccsObjectSetPrivate (plugin, (CCSPrivate *) mock); ccsObjectAddInterface (plugin, (CCSInterface *) &CCSPluginGMockInterface, GET_INTERFACE_TYPE (CCSPluginInterface)); diff --git a/compizconfig/libcompizconfig/tests/mock-plugin.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h similarity index 95% rename from compizconfig/libcompizconfig/tests/mock-plugin.h rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h index a741bf6f5ee5f0424998c6ca4e5aeeb8629eb5b4..36c9d6c0b7dae20d1db5647581031be51f0ef1bb 100644 --- a/compizconfig/libcompizconfig/tests/mock-plugin.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_plugin_mock.h @@ -3,6 +3,9 @@ #include +CCSPlugin * ccsMockPluginNew (); +void ccsFreeMockPlugin (CCSPlugin *); + class CCSPluginGMockInterface { public: @@ -35,6 +38,14 @@ class CCSPluginGMock : { public: + CCSPluginGMock (CCSPlugin *p) : + mPlugin (p) + { + } + + CCSPlugin * + plugin () { return mPlugin; } + /* Mock implementations */ MOCK_METHOD0 (getName, char * ()); MOCK_METHOD0 (getShortDesc, char * ()); @@ -56,6 +67,10 @@ class CCSPluginGMock : MOCK_METHOD0 (readPluginSettings, void ()); MOCK_METHOD0 (getPluginStrExtensions, CCSStrExtensionList ()); + private: + + CCSPlugin *mPlugin; + public: /* Thunking C to C++ */ @@ -158,9 +173,12 @@ class CCSPluginGMock : { return ((CCSPluginGMock *) ccsObjectGetPrivate (plugin))->getPluginStrExtensions (); } + + static void ccsFreePlugin (CCSPlugin *plugin) + + { + ccsFreeMockPlugin (plugin); + } }; extern CCSPluginInterface CCSPluginGMockInterface; - -CCSPlugin * ccsMockPluginNew (); -void ccsFreeMockPlugin (CCSPlugin *); diff --git a/compizconfig/libcompizconfig/tests/setting-mock.cpp b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp similarity index 77% rename from compizconfig/libcompizconfig/tests/setting-mock.cpp rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp index c4bd7efdf3f19c9fed0bc4b0afffd6070db44909..4da7812aa545b1357e85a828ee772b55412c8812 100644 --- a/compizconfig/libcompizconfig/tests/setting-mock.cpp +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.cpp @@ -3,7 +3,9 @@ #include -#include "mock-setting.h" +#include "compizconfig_ccs_setting_mock.h" + +using ::testing::NiceMock; CCSSettingInterface CCSSettingGMockInterface = { @@ -47,11 +49,12 @@ CCSSettingInterface CCSSettingGMockInterface = CCSSettingGMock::ccsResetToDefault, CCSSettingGMock::ccsSettingIsIntegrated, CCSSettingGMock::ccsSettingIsReadOnly, + CCSSettingGMock::ccsSettingIsReadableByBackend, CCSSettingGMock::ccsSettingFree }; -CCSSetting * -ccsMockSettingNew () +static CCSSetting * +allocateSettingObjectWithMockInterface () { CCSSetting *setting = (CCSSetting *) calloc (1, sizeof (CCSSetting)); @@ -60,8 +63,6 @@ ccsMockSettingNew () ccsObjectInit (setting, &ccsDefaultObjectAllocator); - CCSSettingGMock *mock = new CCSSettingGMock (); - ccsObjectSetPrivate (setting, (CCSPrivate *) mock); ccsObjectAddInterface (setting, (CCSInterface *) &CCSSettingGMockInterface, GET_INTERFACE_TYPE (CCSSettingInterface)); ccsSettingRef (setting); @@ -69,6 +70,34 @@ ccsMockSettingNew () return setting; } +CCSSetting * +ccsMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + CCSSettingGMock *mock = new CCSSettingGMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + +CCSSetting * +ccsNiceMockSettingNew () +{ + CCSSetting *setting = allocateSettingObjectWithMockInterface (); + + if (!setting) + return NULL; + + NiceMock *mock = new NiceMock (setting); + ccsObjectSetPrivate (setting, (CCSPrivate *) mock); + + return setting; +} + void ccsFreeMockSetting (CCSSetting *setting) { diff --git a/compizconfig/libcompizconfig/tests/mock-setting.h b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h similarity index 95% rename from compizconfig/libcompizconfig/tests/mock-setting.h rename to compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h index e27dc03c353dabf69967bfca0529632b92aa3168..22588610b8b83bf72aa3732ad6ef67ae49652f08 100644 --- a/compizconfig/libcompizconfig/tests/mock-setting.h +++ b/compizconfig/mocks/libcompizconfig/compizconfig_ccs_setting_mock.h @@ -1,3 +1,6 @@ +#ifndef _COMPIZCONFIG_CCS_SETTING_MOCK +#define _COMPIZCONFIG_CCS_SETTING_MOCK + #include #include @@ -7,6 +10,7 @@ using ::testing::_; using ::testing::Return; CCSSetting * ccsMockSettingNew (); +CCSSetting * ccsNiceMockSettingNew (); void ccsFreeMockSetting (CCSSetting *); class CCSSettingGMockInterface @@ -55,6 +59,7 @@ class CCSSettingGMockInterface virtual void resetToDefault (Bool) = 0; virtual Bool isIntegrated () = 0; virtual Bool isReadOnly () = 0; + virtual Bool isReadableByBackend () = 0; }; class CCSSettingGMock : @@ -64,6 +69,15 @@ class CCSSettingGMock : /* Mock implementations */ + CCSSettingGMock (CCSSetting *s) : + mSetting (s) + { + /* Teach GMock how to handle it */ + ON_CALL (*this, getType ()).WillByDefault (Return (TypeNum)); + } + + CCSSetting * setting () { return mSetting; } + MOCK_METHOD0 (getName, char * ()); MOCK_METHOD0 (getShortDesc, char * ()); MOCK_METHOD0 (getLongDesc, char * ()); @@ -104,12 +118,11 @@ class CCSSettingGMock : MOCK_METHOD1 (resetToDefault, void (Bool)); MOCK_METHOD0 (isIntegrated, Bool ()); MOCK_METHOD0 (isReadOnly, Bool ()); + MOCK_METHOD0 (isReadableByBackend, Bool ()); - CCSSettingGMock () - { - /* Teach GMock how to handle it */ - ON_CALL (*this, getType ()).WillByDefault (Return (TypeNum)); - } + private: + + CCSSetting *mSetting; public: @@ -349,6 +362,11 @@ class CCSSettingGMock : return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->setPrivatePtr (ptr); } + static Bool ccsSettingIsReadableByBackend (CCSSetting *setting) + { + return ((CCSSettingGMock *) ccsObjectGetPrivate (setting))->isReadableByBackend (); + } + static void ccsSettingFree (CCSSetting *setting) { ccsFreeMockSetting (setting); @@ -356,3 +374,5 @@ class CCSSettingGMock : }; extern CCSSettingInterface CCSSettingGMockInterface; + +#endif diff --git a/compizconfig/tests/compizconfig_backend_concept_test.h b/compizconfig/tests/compizconfig_backend_concept_test.h new file mode 100644 index 0000000000000000000000000000000000000000..5e70539012ba7268e3f0c05723e976d53ac34cce --- /dev/null +++ b/compizconfig/tests/compizconfig_backend_concept_test.h @@ -0,0 +1,1490 @@ +#ifndef _COMPIZCONFIG_CCS_BACKEND_CONCEPT_TEST +#define _COMPIZCONFIG_CCS_BACKEND_CONCEPT_TEST + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include "gtest_shared_characterwrapper.h" +#include "compizconfig_test_value_combiners.h" + +using ::testing::Eq; +using ::testing::IsNull; +using ::testing::SetArgPointee; +using ::testing::DoAll; +using ::testing::Return; +using ::testing::ReturnNull; +using ::testing::MakeMatcher; +using ::testing::Matcher; +using ::testing::MatcherInterface; +using ::testing::MatchResultListener; +using ::testing::AtLeast; +using ::testing::NiceMock; + +MATCHER(IsTrue, "Is True") { if (arg) return true; else return false; } +MATCHER(IsFalse, "Is False") { if (!arg) return true; else return false; } + +class ListEqualityMatcher : + public MatcherInterface +{ + public: + + ListEqualityMatcher (CCSSettingListInfo info, + CCSSettingValueList cmp) : + mInfo (info), + mCmp (cmp) + { + } + + virtual bool MatchAndExplain (CCSSettingValueList x, MatchResultListener *listener) const + { + return ccsCompareLists (x, mCmp, mInfo); + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "lists are equal"; + } + + virtual void DescribeNegationTo (std::ostream *os) const + { + *os << "lists are not equal"; + } + + private: + + CCSSettingListInfo mInfo; + CCSSettingValueList mCmp; +}; + +Matcher ListEqual (CCSSettingListInfo info, + CCSSettingValueList cmp) +{ + return MakeMatcher (new ListEqualityMatcher (info, cmp)); +} + +bool +operator== (const CCSSettingColorValue &lhs, + const CCSSettingColorValue &rhs) +{ + if (ccsIsEqualColor (lhs, rhs)) + return true; + return false; +} + +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingColorValue &v) +{ + return os << "Red: " << std::hex << v.color.red << "Blue: " << std::hex << v.color.blue << "Green: " << v.color.green << "Alpha: " << v.color.alpha + << std::dec << std::endl; +} + +bool +operator== (const CCSSettingKeyValue &lhs, + const CCSSettingKeyValue &rhs) +{ + if (ccsIsEqualKey (lhs, rhs)) + return true; + return false; +} + +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingKeyValue &v) +{ + return os << "Keysym: " << v.keysym << " KeyModMask " << std::hex << v.keyModMask << std::dec << std::endl; +} + +bool +operator== (const CCSSettingButtonValue &lhs, + const CCSSettingButtonValue &rhs) +{ + if (ccsIsEqualButton (lhs, rhs)) + return true; + return false; +} + +::std::ostream & +operator<< (::std::ostream &os, const CCSSettingButtonValue &v) +{ + return os << "Button " << v.button << "Button Key Mask: " << std::hex << v.buttonModMask << "Edge Mask: " << v.edgeMask << std::dec << std::endl; +} + +bool +operator== (const CCSString &lhs, + const std::string &rhs) +{ + if (rhs == lhs.value) + return true; + + return false; +} + +bool +operator== (const std::string &lhs, + const CCSString &rhs) +{ + if (lhs == rhs.value) + return true; + + return false; +} + +::std::ostream & +operator<< (::std::ostream &os, CCSString &string) +{ + os << string.value << std::endl; + return os; +} + +class CCSListWrapper : + boost::noncopyable +{ + public: + + typedef boost::shared_ptr Ptr; + + CCSListWrapper (CCSSettingValueList list, + bool freeItems, + CCSSettingType type, + const boost::shared_ptr &listInfo, + const boost::shared_ptr &settingReference) : + mList (list), + mFreeItems (freeItems), + mType (type), + mListInfo (listInfo), + mSettingReference (settingReference) + { + } + + CCSSettingType type () { return mType; } + + operator CCSSettingValueList () + { + return mList; + } + + operator CCSSettingValueList () const + { + return mList; + } + + ~CCSListWrapper () + { + ccsSettingValueListFree (mList, mFreeItems ? TRUE : FALSE); + } + + const boost::shared_ptr & + setting () + { + return mSettingReference; + } + + private: + + CCSSettingValueList mList; + bool mFreeItems; + CCSSettingType mType; + boost::shared_ptr mListInfo; + boost::shared_ptr mSettingReference; +}; + +template +class ItemInCCSListMatcher : + public ::testing::MatcherInterface +{ + public: + + ItemInCCSListMatcher (const Matcher &matcher) : + mMatcher (matcher) + { + } + + virtual bool MatchAndExplain (L list, MatchResultListener *listener) const + { + L iter = list; + + while (iter) + { + if (mMatcher.MatchAndExplain ((*(reinterpret_cast (iter->data))), listener)) + return true; + + iter = iter->next; + } + + return false; + } + + virtual void DescribeTo (std::ostream *os) const + { + *os << "found in list ("; + mMatcher.DescribeTo (os); + *os << ")"; + } + + virtual void DescribeNegationTo (std::ostream *os) const + { + *os << "not found in list ("; + mMatcher.DescribeNegationTo (os); + *os << ")"; + } + + private: + + const Matcher & mMatcher; +}; + +template +Matcher IsItemInCCSList (const Matcher &matcher) +{ + return MakeMatcher (new ItemInCCSListMatcher (matcher)); +} + +namespace +{ + bool ccsStringCmp (const CCSString &a, const CCSString &b) + { + return std::string (a.value) == b.value; + } +} + +typedef boost::variant VariantTypes; + +class CCSSettingsConceptTestEnvironmentInterface +{ + public: + + virtual void SetUp () = 0; + virtual void TearDown () = 0; + + virtual void WriteBoolAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteIntegerAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteFloatAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteStringAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteColorAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteKeyAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteButtonAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteEdgeAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteMatchAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteBellAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + virtual void WriteListAtKey (const std::string &plugin, + const std::string &key, + const VariantTypes &value) = 0; + + virtual Bool ReadBoolAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual int ReadIntegerAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual float ReadFloatAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual const char * ReadStringAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingColorValue ReadColorAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingKeyValue ReadKeyAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingButtonValue ReadButtonAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual unsigned int ReadEdgeAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual const char * ReadMatchAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual Bool ReadBellAtKey (const std::string &plugin, + const std::string &key) = 0; + virtual CCSSettingValueList ReadListAtKey (const std::string &plugin, + const std::string &key, + CCSSetting *setting) = 0; +}; + +class CCSBackendConceptTestEnvironmentInterface : + public CCSSettingsConceptTestEnvironmentInterface +{ + public: + + typedef boost::shared_ptr Ptr; + + virtual ~CCSBackendConceptTestEnvironmentInterface () {}; + virtual CCSBackend * SetUp (CCSContext *context, + CCSContextGMock *gmockContext) = 0; + virtual void TearDown (CCSBackend *) = 0; + + virtual void AddProfile (const std::string &profile) = 0; + virtual void SetGetExistingProfilesExpectation (CCSContext *, + CCSContextGMock *) = 0; + virtual void SetDeleteProfileExpectation (const std::string &, + CCSContext *, + CCSContextGMock *) = 0; + + virtual void SetReadInitExpectation (CCSContext *, + CCSContextGMock *) = 0; + + virtual void SetReadDoneExpectation (CCSContext *, + CCSContextGMock *) = 0; + + virtual void SetWriteInitExpectation (CCSContext *, + CCSContextGMock *) = 0; + + virtual void SetWriteDoneExpectation (CCSContext *, + CCSContextGMock *) = 0; + + virtual const CCSBackendInfo * GetInfo () = 0; + + virtual void PreWrite (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + virtual void PostWrite (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + + virtual void PreRead (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + virtual void PostRead (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + + virtual void PreUpdate (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + virtual void PostUpdate (CCSContextGMock *, + CCSPluginGMock *, + CCSSettingGMock *, + CCSSettingType) = 0; + + virtual bool UpdateSettingAtKey (const std::string &plugin, + const std::string &setting) = 0; +}; + +class CCSBackendConceptTestEnvironmentFactoryInterface +{ + public: + + typedef boost::shared_ptr Ptr; + + virtual ~CCSBackendConceptTestEnvironmentFactoryInterface () {} + + virtual CCSBackendConceptTestEnvironmentInterface::Ptr ConstructTestEnv () = 0; +}; + +template +class CCSBackendConceptTestEnvironmentFactory : + public CCSBackendConceptTestEnvironmentFactoryInterface +{ + public: + + CCSBackendConceptTestEnvironmentInterface::Ptr + ConstructTestEnv () + { + return boost::shared_static_cast (boost::make_shared ()); + } +}; + +namespace +{ + +typedef boost::function WriteFunc; + +Bool boolToBool (bool v) { return v ? TRUE : FALSE; } + +CCSSettingGMock * getSettingGMockFromSetting (const boost::shared_ptr &setting) { return (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); } + +void SetIntWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getInt (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadIntegerAtKey (plugin, key), boost::get (value)); +} + +void SetBoolWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getBool (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boolToBool (boost::get (value))), + Return (TRUE))); + write (); + + bool v (boost::get (value)); + + if (v) + EXPECT_THAT (env->ReadBoolAtKey (plugin, key), IsTrue ()); + else + EXPECT_THAT (env->ReadBoolAtKey (plugin, key), IsFalse ()); +} + +void SetFloatWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getFloat (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadFloatAtKey (plugin, key), boost::get (value)); +} + +void SetStringWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getString (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + const_cast (boost::get (value))), + Return (TRUE))); + write (); + EXPECT_EQ (std::string (env->ReadStringAtKey (plugin, key)), std::string (boost::get (value))); +} + +void SetColorWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getColor (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + + EXPECT_EQ (env->ReadColorAtKey (plugin, key), boost::get (value)); +} + +void SetKeyWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getKey (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadKeyAtKey (plugin, key), boost::get (value)); +} + +void SetButtonWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getButton (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadButtonAtKey (plugin, key), boost::get (value)); +} + +void SetEdgeWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getEdge (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boost::get (value)), + Return (TRUE))); + write (); + EXPECT_EQ (env->ReadEdgeAtKey (plugin, key), boost::get (value)); +} + +void SetBellWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getBell (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + boolToBool (boost::get (value))), + Return (TRUE))); + write (); + bool v (boost::get (value)); + + if (v) + EXPECT_THAT (env->ReadBellAtKey (plugin, key), IsTrue ()); + else + EXPECT_THAT (env->ReadBellAtKey (plugin, key), IsFalse ()); +} + +void SetMatchWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + EXPECT_CALL (*gmock, getMatch (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + const_cast (boost::get (value))), + Return (TRUE))); + write (); + EXPECT_EQ (std::string (env->ReadMatchAtKey (plugin, key)), std::string (boost::get (value))); +} + +void SetListWriteExpectation (const std::string &plugin, + const std::string &key, + const VariantTypes &value, + const boost::shared_ptr &setting, + const WriteFunc &write, + const CCSBackendConceptTestEnvironmentInterface::Ptr &env) +{ + CCSSettingGMock *gmock (getSettingGMockFromSetting (setting)); + CCSSettingValueList list = *(boost::get > (value)); + + EXPECT_CALL (*gmock, getInfo ()); + + CCSSettingInfo *info = ccsSettingGetInfo (setting.get ()); + + info->forList.listType = (boost::get > (value))->type (); + + EXPECT_CALL (*gmock, getInfo ()).Times (AtLeast (1)); + EXPECT_CALL (*gmock, getList (_)).WillRepeatedly (DoAll ( + SetArgPointee <0> ( + list), + Return (TRUE))); + write (); + + EXPECT_THAT (CCSListWrapper (env->ReadListAtKey (plugin, key, setting.get ()), + true, + info->forList.listType, + boost::shared_ptr (), + setting), + ListEqual (info->forList, list)); +} + +void SetIntReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setInt (boost::get (value), _)); +} + +void SetBoolReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + bool v (boost::get (value)); + + if (v) + EXPECT_CALL (*gmock, setBool (IsTrue (), _)); + else + EXPECT_CALL (*gmock, setBool (IsFalse (), _)); +} + +void SetBellReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + bool v (boost::get (value)); + + if (v) + EXPECT_CALL (*gmock, setBell (IsTrue (), _)); + else + EXPECT_CALL (*gmock, setBell (IsFalse (), _)); +} + +void SetFloatReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setFloat (boost::get (value), _)); +} + +void SetStringReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setString (Eq (std::string (boost::get (value))), _)); +} + +void SetMatchReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setMatch (Eq (std::string (boost::get (value))), _)); +} + +void SetColorReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setColor (boost::get (value), _)); +} + +void SetKeyReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setKey (boost::get (value), _)); +} + +void SetButtonReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setButton (boost::get (value), _)); +} + +void SetEdgeReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + EXPECT_CALL (*gmock, setEdge (boost::get (value), _)); +} + +CCSSettingInfo globalListInfo; + +void SetListReadExpectation (CCSSettingGMock *gmock, const VariantTypes &value) +{ + globalListInfo.forList.listType = (boost::get > (value))->type (); + globalListInfo.forList.listInfo = NULL; + + ON_CALL (*gmock, getInfo ()).WillByDefault (Return (&globalListInfo)); + EXPECT_CALL (*gmock, setList (ListEqual (globalListInfo.forList, *(boost::get > (value))), _)); +} + +} + +class CCSBackendConceptTestParamInterface +{ + public: + + typedef boost::shared_ptr Ptr; + + typedef void (CCSBackendConceptTestEnvironmentInterface::*NativeWriteMethod) (const std::string &plugin, + const std::string &keyname, + const VariantTypes &value); + + typedef boost::function SetReadExpectation; + typedef boost::function &, + const WriteFunc &, + const CCSBackendConceptTestEnvironmentInterface::Ptr & )> SetWriteExpectation; + + virtual void TearDown (CCSBackend *) = 0; + + virtual CCSBackendConceptTestEnvironmentInterface::Ptr testEnv () = 0; + virtual VariantTypes & value () = 0; + virtual void nativeWrite (const CCSBackendConceptTestEnvironmentInterface::Ptr & iface, + const std::string &plugin, + const std::string &keyname, + const VariantTypes &value) = 0; + virtual CCSSettingType & type () = 0; + virtual std::string & keyname () = 0; + virtual SetWriteExpectation & setWriteExpectationAndWrite () = 0; + virtual SetReadExpectation & setReadExpectation () = 0; + virtual std::string & what () = 0; +}; + +template +class CCSBackendConceptTestParam : + public CCSBackendConceptTestParamInterface +{ + public: + + typedef boost::shared_ptr > Ptr; + + CCSBackendConceptTestParam (CCSBackendConceptTestEnvironmentFactoryInterface *testEnvFactory, + const VariantTypes &value, + const NativeWriteMethod &write, + const CCSSettingType &type, + const std::string &keyname, + const SetReadExpectation &setReadExpectation, + const SetWriteExpectation &setWriteExpectation, + const std::string &what) : + mTestEnvFactory (testEnvFactory), + mTestEnv (), + mValue (value), + mNativeWrite (write), + mType (type), + mKeyname (keyname), + mSetReadExpectation (setReadExpectation), + mSetWriteExpectation (setWriteExpectation), + mWhat (what) + { + } + + void TearDown (CCSBackend *b) + { + if (mTestEnv) + mTestEnv->TearDown (b); + + mTestEnv.reset (); + } + + CCSBackendConceptTestEnvironmentInterface::Ptr testEnv () + { + if (!mTestEnv) + mTestEnv = mTestEnvFactory->ConstructTestEnv (); + + return mTestEnv; + } + + VariantTypes & value () { return mValue; } + void nativeWrite (const CCSBackendConceptTestEnvironmentInterface::Ptr & iface, + const std::string &plugin, + const std::string &keyname, + const VariantTypes &value) + { + return ((iface.get ())->*mNativeWrite) (plugin, keyname, value); + } + CCSSettingType & type () { return mType; } + std::string & keyname () { return mKeyname; } + CCSBackendConceptTestParamInterface::SetReadExpectation & setReadExpectation () { return mSetReadExpectation; } + CCSBackendConceptTestParamInterface::SetWriteExpectation & setWriteExpectationAndWrite () { return mSetWriteExpectation; } + std::string & what () { return mWhat; } + + private: + + CCSBackendConceptTestEnvironmentFactoryInterface *mTestEnvFactory; + CCSBackendConceptTestEnvironmentInterface::Ptr mTestEnv; + VariantTypes mValue; + NativeWriteMethod mNativeWrite; + CCSSettingType mType; + std::string mKeyname; + SetReadExpectation mSetReadExpectation; + SetWriteExpectation mSetWriteExpectation; + std::string mWhat; + +}; + +class CCSBackendConformanceSpawnObjectsTestFixtureBase +{ + protected: + + CCSBackendConformanceSpawnObjectsTestFixtureBase () : + profileName ("mock") + { + } + + virtual ~CCSBackendConformanceSpawnObjectsTestFixtureBase () + { + } + + /* Having the returned context, setting and plugin + * as out params is awkward, but GTest doesn't let + * you use ASSERT_* unless the function returns void + */ + void + SpawnContext (boost::shared_ptr &context) + { + context.reset (ccsMockContextNew (), boost::bind (ccsFreeMockContext, _1)); + } + + void + SpawnPlugin (const std::string &name, const boost::shared_ptr &context, boost::shared_ptr &plugin) + { + plugin.reset (ccsMockPluginNew (), boost::bind (ccsFreeMockPlugin, _1)); + + CCSPluginGMock *gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin.get ()); + + ASSERT_FALSE (name.empty ()); + ASSERT_TRUE (context.get ()); + + ON_CALL (*gmockPlugin, getName ()).WillByDefault (Return ((char *) name.c_str ())); + ON_CALL (*gmockPlugin, getContext ()).WillByDefault (Return (context.get ())); + } + + void + SpawnSetting (const std::string &name, + CCSSettingType type, + const boost::shared_ptr &plugin, + boost::shared_ptr &setting) + { + setting.reset (ccsMockSettingNew (), boost::bind (ccsFreeMockSetting, _1)); + mSpawnedSettingInfo.push_back (CCSSettingInfo ()); + + CCSSettingGMock *gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); + + ASSERT_FALSE (name.empty ()); + ASSERT_NE (type, TypeNum); + ASSERT_TRUE (plugin); + + ON_CALL (*gmockSetting, getName ()).WillByDefault (Return ((char *) name.c_str ())); + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (type)); + ON_CALL (*gmockSetting, getParent ()).WillByDefault (Return (plugin.get ())); + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (&(mSpawnedSettingInfo.back ()))); + } + + void + SetupContext () + { + SpawnContext (context); + gmockContext = (CCSContextGMock *) ccsObjectGetPrivate (context.get ()); + + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (profileName.c_str ())); + } + + CCSBackend * GetBackend () + { + return mBackend; + } + + boost::shared_ptr context; + CCSContextGMock *gmockContext; + CCSBackend *mBackend; + + private: + + std::vector mSpawnedSettingInfo; + std::string profileName; +}; + +class CCSBackendConformanceTestParameterizedByBackendFixture : + public CCSBackendConformanceSpawnObjectsTestFixtureBase, + public ::testing::TestWithParam +{ + public: + + CCSBackendConformanceTestParameterizedByBackendFixture () : + mTestEnv (GetParam ()->ConstructTestEnv ()) + { + } + + virtual void SetUp () + { + SetupContext (); + mBackend = mTestEnv->SetUp (context.get (), gmockContext); + } + + virtual void TearDown () + { + if (mTestEnv) + mTestEnv->TearDown (mBackend); + + mTestEnv.reset (); + } + + protected: + + CCSBackendConceptTestEnvironmentInterface::Ptr mTestEnv; +}; + +class CCSBackendConformanceTestParameterized : + public CCSBackendConformanceSpawnObjectsTestFixtureBase, + public ::testing::TestWithParam +{ + public: + + virtual ~CCSBackendConformanceTestParameterized () {} + + virtual void SetUp () + { + SetupContext (); + mBackend = GetParam ()->testEnv ()->SetUp (context.get (), gmockContext); + } + + virtual void TearDown () + { + CCSBackendConformanceTestParameterized::GetParam ()->TearDown (mBackend); + } +}; + +namespace compizconfig +{ +namespace test +{ + +namespace list_populators = impl::populators::list; + +typedef boost::function ConstructorFunc; + +CCSListWrapper::Ptr +CCSListConstructionExpectationsSetter (const ConstructorFunc &c, + CCSSettingType type, + bool freeItems) +{ + boost::function f (boost::bind (ccsFreeMockSetting, _1)); + boost::shared_ptr mockSetting (ccsNiceMockSettingNew (), f); + NiceMock *gmockSetting = reinterpret_cast *> (ccsObjectGetPrivate (mockSetting.get ())); + + ON_CALL (*gmockSetting, getType ()).WillByDefault (Return (TypeList)); + + boost::shared_ptr listInfo (new CCSSettingInfo); + + listInfo->forList.listType = type; + + ON_CALL (*gmockSetting, getInfo ()).WillByDefault (Return (listInfo.get ())); + ON_CALL (*gmockSetting, getDefaultValue ()).WillByDefault (ReturnNull ()); + return boost::make_shared (c (mockSetting.get ()), freeItems, type, listInfo, mockSetting); +} + +template +::testing::internal::ParamGenerator +GenerateTestingParametersForBackendInterface () +{ + static CCSBackendConceptTestEnvironmentFactory interfaceFactory; + static CCSBackendConceptTestEnvironmentFactoryInterface *backendEnvFactory = &interfaceFactory; + + typedef CCSBackendConceptTestParam ConceptParam; + + static typename CCSBackendConceptTestParamInterface::Ptr testParam[] = + { + boost::make_shared (backendEnvFactory, + VariantTypes (1), + &CCSBackendConceptTestEnvironmentInterface::WriteIntegerAtKey, + TypeInt, + "integer_setting", + boost::bind (SetIntReadExpectation, _1, _2), + boost::bind (SetIntWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestInt"), + boost::make_shared (backendEnvFactory, + VariantTypes (true), + &CCSBackendConceptTestEnvironmentInterface::WriteBoolAtKey, + TypeBool, + "boolean_setting", + boost::bind (SetBoolReadExpectation, _1, _2), + boost::bind (SetBoolWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestBool"), + boost::make_shared (backendEnvFactory, + VariantTypes (static_cast (3.0)), + &CCSBackendConceptTestEnvironmentInterface::WriteFloatAtKey, + TypeFloat, + "float_setting", + boost::bind (SetFloatReadExpectation, _1, _2), + boost::bind (SetFloatWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestFloat"), + boost::make_shared (backendEnvFactory, + VariantTypes (static_cast ("foo")), + &CCSBackendConceptTestEnvironmentInterface::WriteStringAtKey, + TypeString, + "string_setting", + boost::bind (SetStringReadExpectation, _1, _2), + boost::bind (SetStringWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestString"), + boost::make_shared (backendEnvFactory, + VariantTypes (static_cast ("foo=bar")), + &CCSBackendConceptTestEnvironmentInterface::WriteMatchAtKey, + TypeMatch, + "match_setting", + boost::bind (SetMatchReadExpectation, _1, _2), + boost::bind (SetMatchWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestMatch"), + boost::make_shared (backendEnvFactory, + VariantTypes (true), + &CCSBackendConceptTestEnvironmentInterface::WriteBellAtKey, + TypeBell, + "bell_setting", + boost::bind (SetBellReadExpectation, _1, _2), + boost::bind (SetBellWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestBell"), + boost::make_shared (backendEnvFactory, + VariantTypes (impl::getColorValueList ()[0]), + &CCSBackendConceptTestEnvironmentInterface::WriteColorAtKey, + TypeColor, + "color_setting", + boost::bind (SetColorReadExpectation, _1, _2), + boost::bind (SetColorWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestColor"), + boost::make_shared (backendEnvFactory, + VariantTypes (impl::keyValue), + &CCSBackendConceptTestEnvironmentInterface::WriteKeyAtKey, + TypeKey, + "key_setting", + boost::bind (SetKeyReadExpectation, _1, _2), + boost::bind (SetKeyWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestKey"), + boost::make_shared (backendEnvFactory, + VariantTypes (impl::buttonValue), + &CCSBackendConceptTestEnvironmentInterface::WriteButtonAtKey, + TypeButton, + "button_setting", + boost::bind (SetButtonReadExpectation, _1, _2), + boost::bind (SetButtonWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestButton"), + boost::make_shared (backendEnvFactory, + VariantTypes (static_cast (1)), + &CCSBackendConceptTestEnvironmentInterface::WriteEdgeAtKey, + TypeEdge, + "edge_setting", + boost::bind (SetEdgeReadExpectation, _1, _2), + boost::bind (SetEdgeWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestEdge"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::integer, _1), + TypeInt, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, + TypeList, + "int_list_setting", + boost::bind (SetListReadExpectation, _1, _2), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListInt"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::doubleprecision, _1), + TypeFloat, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, + TypeList, + "float_list_setting", + boost::bind (SetListReadExpectation, _1, _2), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListFloat"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::boolean, _1), + TypeBool, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, + TypeList, + "bool_list_setting", + boost::bind (SetListReadExpectation, _1, _2), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListBool"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::string, _1), + TypeString, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, + TypeList, + "string_list_setting", + boost::bind (SetListReadExpectation, _1, _2), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListString"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::match, _1), + TypeMatch, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, + TypeList, + "match_list_setting", + boost::bind (SetListReadExpectation, _1, _2), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListMatch"), + boost::make_shared (backendEnvFactory, + VariantTypes (CCSListConstructionExpectationsSetter (boost::bind (list_populators::color, _1), + TypeColor, true)), + &CCSBackendConceptTestEnvironmentInterface::WriteListAtKey, + TypeList, + "color_list_setting", + boost::bind (SetListReadExpectation, _1, _2), + boost::bind (SetListWriteExpectation, _1, _2, _3, _4, _5, _6), + "TestListColor") + }; + + return ::testing::ValuesIn (testParam); +} + +template +::testing::internal::ParamGenerator +GenerateTestingEnvFactoryBackendInterface () +{ + boost::shared_ptr f (boost::make_shared > ()); + return ::testing::Values (f); +} + +} +} + +class CCSBackendConformanceTestReadWrite : + public CCSBackendConformanceTestParameterized +{ + public: + + virtual ~CCSBackendConformanceTestReadWrite () {} + + virtual void SetUp () + { + CCSBackendConformanceTestParameterized::SetUp (); + + pluginName = "mock"; + settingName = GetParam ()->keyname (); + VALUE = GetParam ()->value (); + + CCSBackendConformanceTestParameterized::SpawnPlugin (pluginName, context, plugin); + CCSBackendConformanceTestParameterized::SpawnSetting (settingName, GetParam ()->type (), plugin, setting); + + gmockPlugin = (CCSPluginGMock *) ccsObjectGetPrivate (plugin.get ()); + gmockSetting = (CCSSettingGMock *) ccsObjectGetPrivate (setting.get ()); + } + + virtual void TearDown () + { + CCSBackendConformanceTestParameterized::TearDown (); + } + + protected: + + std::string pluginName; + std::string settingName; + VariantTypes VALUE; + boost::shared_ptr plugin; + boost::shared_ptr setting; + CCSPluginGMock *gmockPlugin; + CCSSettingGMock *gmockSetting; + +}; + +TEST_P (CCSBackendConformanceTestReadWrite, TestReadValue) +{ + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "Read"); + + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->nativeWrite (CCSBackendConformanceTestParameterized::GetParam ()->testEnv (), + pluginName, settingName, VALUE); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostRead (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + + ccsBackendReadSetting (CCSBackendConformanceTestParameterized::GetBackend (), context.get (), setting.get ()); +} + +TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateMockedValue) +{ + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "UpdateMocked"); + + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->nativeWrite (CCSBackendConformanceTestParameterized::GetParam ()->testEnv (), + pluginName, settingName, VALUE); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + + ccsBackendUpdateSetting (CCSBackendConformanceTestParameterized::GetBackend (), context.get (), plugin.get (), setting.get ()); +} + +TEST_P (CCSBackendConformanceTestReadWrite, TestUpdateKeyedValue) +{ + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "UpdateKeyed"); + + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->nativeWrite (CCSBackendConformanceTestParameterized::GetParam ()->testEnv (), + pluginName, settingName, VALUE); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostUpdate (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setReadExpectation () (gmockSetting, VALUE); + + EXPECT_CALL (*gmockContext, findPlugin (_)).WillOnce (Return (plugin.get ())); + EXPECT_CALL (*gmockPlugin, findSetting (_)).WillOnce (Return (setting.get ())); + + EXPECT_TRUE (CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->UpdateSettingAtKey (pluginName, settingName)); +} + +TEST_P (CCSBackendConformanceTestReadWrite, TestWriteValue) +{ + SCOPED_TRACE (CCSBackendConformanceTestParameterized::GetParam ()->what () + "Write"); + + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PreWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + CCSBackendConformanceTestParameterized::GetParam ()->setWriteExpectationAndWrite () (pluginName, + settingName, + VALUE, + setting, + boost::bind (ccsBackendWriteSetting, + CCSBackendConformanceTestParameterized::GetBackend (), + context.get (), + setting.get ()), + GetParam ()->testEnv ()); + CCSBackendConformanceTestParameterized::GetParam ()->testEnv ()->PostWrite (gmockContext, gmockPlugin, gmockSetting, GetParam ()->type ()); + +} + +class CCSBackendConformanceTestInfo : + public CCSBackendConformanceTestParameterizedByBackendFixture +{ +}; + +TEST_P (CCSBackendConformanceTestInfo, TestGetInfo) +{ + const CCSBackendInfo *knownBackendInfo = mTestEnv->GetInfo (); + const CCSBackendInfo *retreivedBackendInfo = ccsBackendGetInfo (GetBackend ()); + + EXPECT_THAT (retreivedBackendInfo->name, Eq (knownBackendInfo->name)); + EXPECT_THAT (retreivedBackendInfo->shortDesc, Eq (knownBackendInfo->shortDesc)); + EXPECT_THAT (retreivedBackendInfo->longDesc, Eq (knownBackendInfo->longDesc)); + + if (knownBackendInfo->profileSupport) + EXPECT_TRUE (retreivedBackendInfo->profileSupport); + else + EXPECT_FALSE (retreivedBackendInfo->profileSupport); + + if (knownBackendInfo->integrationSupport) + EXPECT_TRUE (retreivedBackendInfo->integrationSupport); + else + EXPECT_FALSE (retreivedBackendInfo->integrationSupport); +} + +class CCSBackendConformanceTestInitFiniFuncs : + public CCSBackendConformanceTestParameterizedByBackendFixture +{ +}; + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestReadInit) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->readInit) + { + mTestEnv->SetReadInitExpectation (context.get (), gmockContext); + ccsBackendReadInit (backend, context.get ()); + } +} + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestReadDone) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->readDone) + { + mTestEnv->SetReadDoneExpectation (context.get (), gmockContext); + ccsBackendReadDone (backend, context.get ()); + } +} + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestWriteInit) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->writeInit) + { + mTestEnv->SetWriteInitExpectation (context.get (), gmockContext); + ccsBackendWriteInit (backend, context.get ()); + } +} + +TEST_P (CCSBackendConformanceTestInitFiniFuncs, TestWriteDone) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->writeDone) + { + mTestEnv->SetWriteDoneExpectation (context.get (), gmockContext); + ccsBackendWriteDone (backend, context.get ()); + } +} + +class CCSBackendConformanceTestProfileHandling : + public CCSBackendConformanceTestParameterizedByBackendFixture +{ + public: + + static const std::string PROFILE_MOCK; + static const std::string PROFILE_DEFAULT; + static const std::string PROFILE_FOO; + static const std::string PROFILE_BAR; + static const std::string PROFILE_BAZ; +}; + +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_MOCK ("mock"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_DEFAULT ("Default"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_FOO ("foo"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAR ("bar"); +const std::string CCSBackendConformanceTestProfileHandling::PROFILE_BAZ ("baz"); + +/* A workaround for templates inside of macros not + * expanding correctly */ +namespace +{ + Matcher + IsStringItemInStringCCSList (const Matcher &matcher) + { + return IsItemInCCSList (matcher); + } +} + +TEST_P (CCSBackendConformanceTestProfileHandling, TestGetExistingProfiles) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 4); + + /* Default profile must always be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); + + /* Current profile should also be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_MOCK))); + + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_BAR))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); + } +} + +TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonCurrentProfile) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); + + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); + EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + + /* Check to make sure that the profile is no longer there */ + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 3); + + /* Default profile must always be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); + + /* Current profile should also be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_MOCK))); + + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); + + /* PROFILE_BAR was deleted */ + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAR)))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); + } +} + +TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteNonExistantCurrentProfile) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + CharacterWrapper PROFILE_BAZ_CHAR (strdup (PROFILE_BAZ.c_str ())); + + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAZ, context.get (), gmockContext); + + EXPECT_FALSE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAZ_CHAR)); + + /* Check to make sure that the profile is no longer there */ + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 4); + + /* Default profile must always be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); + + /* Current profile should also be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_MOCK))); + + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_BAR))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); + } +} + +TEST_P (CCSBackendConformanceTestProfileHandling, TestDeleteCurrentProfile) +{ + CCSBackend *backend = GetBackend (); + CCSBackendInterface *backendInterface = GET_INTERFACE (CCSBackendInterface, backend); + + if (backendInterface->getExistingProfiles) + { + mTestEnv->AddProfile (PROFILE_FOO); + mTestEnv->AddProfile (PROFILE_BAR); + + CharacterWrapper PROFILE_BAR_CHAR (strdup (PROFILE_BAR.c_str ())); + + /* Make sure that backends know what profile is being deleted */ + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_BAR.c_str ())); + + mTestEnv->SetDeleteProfileExpectation (PROFILE_BAR, context.get (), gmockContext); + + /* Before deleting the profile, getProfile can no longer refer to it */ + ON_CALL (*gmockContext, getProfile ()).WillByDefault (Return (PROFILE_FOO.c_str ())); + + EXPECT_TRUE (ccsBackendDeleteProfile (backend, context.get (), PROFILE_BAR_CHAR)); + + /* Check to make sure that the profile is no longer there */ + mTestEnv->SetGetExistingProfilesExpectation (context.get (), gmockContext); + boost::shared_ptr <_CCSStringList> existingProfiles (ccsBackendGetExistingProfiles (backend, context.get ()), + boost::bind (ccsStringListFree, _1, TRUE)); + + ASSERT_EQ (ccsStringListLength (existingProfiles.get ()), 2); + /* Default profile must always be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_DEFAULT))); + + /* Old current profile shouldn't be there */ + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAR)))); + + /* New current profile should be there */ + EXPECT_THAT (existingProfiles.get (), IsStringItemInStringCCSList (Eq (PROFILE_FOO))); + EXPECT_THAT (existingProfiles.get (), Not (IsStringItemInStringCCSList (Eq (PROFILE_BAZ)))); + } +} + +#endif + diff --git a/compizconfig/tests/compizconfig_ccs_mocked_allocator.h b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h new file mode 100644 index 0000000000000000000000000000000000000000..9550029e0f96794128fd7f63614a092622b9cfd5 --- /dev/null +++ b/compizconfig/tests/compizconfig_ccs_mocked_allocator.h @@ -0,0 +1,95 @@ +#ifndef _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H +#define _COMPIZCONFIG_CCS_MOCKED_ALLOCATION_H + +#include +#include + +class AllocationInterface +{ + public: + + virtual void * realloc_ (void *, size_t) = 0; + virtual void * malloc_ (size_t) = 0; + virtual void * calloc_ (size_t, size_t) = 0; + virtual void free_ (void *) = 0; + + public: + + static void * wrapRealloc (void *o, void *a , size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->realloc_ (a, b); + } + + static void * wrapMalloc (void *o, size_t a) + { + AllocationInterface *ao = static_cast (o); + return ao->malloc_ (a); + } + + static void * wrapCalloc (void *o, size_t a, size_t b) + { + AllocationInterface *ao = static_cast (o); + return ao->calloc_ (a, b); + } + + static void wrapFree (void *o, void *a) + { + AllocationInterface *ao = static_cast (o); + ao->free_ (a); + } +}; + +class ObjectAllocationGMock : + public AllocationInterface +{ + public: + + MOCK_METHOD2 (realloc_, void * (void *, size_t)); + MOCK_METHOD1 (malloc_, void * (size_t)); + MOCK_METHOD2 (calloc_, void * (size_t, size_t)); + MOCK_METHOD1 (free_, void (void *)); + +}; + +class FailingObjectReallocation : + public AllocationInterface +{ + public: + + FailingObjectReallocation (unsigned int sc) : + successCount (sc) + { + } + + void * realloc_ (void *a, size_t b) { unsigned int c = successCount--; if (c) return realloc (a, b); else return NULL; } + void * malloc_ (size_t a) { return malloc (a); } + void * calloc_ (size_t n, size_t a) { return calloc (n, a); } + void free_ (void *a) { free (a); } + + private: + + unsigned int successCount; +}; + +class FailingObjectAllocation : + public AllocationInterface +{ + public: + + void * realloc_ (void *a, size_t b) { return NULL; } + void * malloc_ (size_t a) { return NULL; } + void * calloc_ (size_t n, size_t a) { return NULL; } + void free_ (void *a) { } +}; + +CCSObjectAllocationInterface failingAllocator = +{ + AllocationInterface::wrapRealloc, + AllocationInterface::wrapMalloc, + AllocationInterface::wrapCalloc, + AllocationInterface::wrapFree, + NULL +}; + +#endif diff --git a/compizconfig/tests/compizconfig_test_value_combiners.h b/compizconfig/tests/compizconfig_test_value_combiners.h new file mode 100644 index 0000000000000000000000000000000000000000..1f64ea730205370a56f72ffa8bf02bbd488a5274 --- /dev/null +++ b/compizconfig/tests/compizconfig_test_value_combiners.h @@ -0,0 +1,109 @@ +#ifndef _COMPIZCONFIG_TEST_VALUE_COMBINERS_H +#define _COMPIZCONFIG_TEST_VALUE_COMBINERS_H + +#include +#include +#include + +namespace compizconfig +{ + namespace test + { + namespace impl + { + Bool boolValues[] = { TRUE, FALSE, TRUE }; + int intValues[] = { 1, 2, 3 }; + float floatValues[] = { 1.0, 2.0, 3.0 }; + const char * stringValues[] = { "foo", "grill", "bar" }; + const char * matchValues[] = { "type=foo", "class=bar", "xid=42" }; + + const unsigned int NUM_COLOR_VALUES = 3; + + CCSSettingColorValue * + getColorValueList () + { + static const unsigned short max = std::numeric_limits ::max (); + static const unsigned short maxD2 = max / 2; + static const unsigned short maxD4 = max / 4; + static const unsigned short maxD8 = max / 8; + + static bool colorValueListInitialized = false; + + static CCSSettingColorValue colorValues[NUM_COLOR_VALUES]; + + if (!colorValueListInitialized) + { + colorValues[0].color.red = maxD2; + colorValues[0].color.blue = maxD4; + colorValues[0].color.green = maxD8; + colorValues[0].color.alpha = max; + + colorValues[1].color.red = maxD8; + colorValues[1].color.blue = maxD4; + colorValues[1].color.green = maxD2; + colorValues[1].color.alpha = max; + + colorValues[1].color.red = max; + colorValues[1].color.blue = maxD4; + colorValues[1].color.green = maxD2; + colorValues[1].color.alpha = maxD8; + + for (unsigned int i = 0; i < NUM_COLOR_VALUES; i++) + { + CharacterWrapper s (ccsColorToString (&colorValues[i])); + + ccsStringToColor (s, &colorValues[i]); + } + + colorValueListInitialized = true; + } + + return colorValues; + } + CCSSettingKeyValue keyValue = { XK_A, + (1 << 0)}; + + CCSSettingButtonValue buttonValue = { 1, + (1 << 0), + (1 << 1) }; + + namespace populators + { + namespace list + { + CCSSettingValueList boolean (CCSSetting *setting) + { + return ccsGetValueListFromBoolArray (boolValues, sizeof (boolValues) / sizeof (boolValues[0]), setting); + } + + CCSSettingValueList integer (CCSSetting *setting) + { + return ccsGetValueListFromIntArray (intValues, sizeof (intValues) / sizeof (intValues[0]), setting); + } + + CCSSettingValueList doubleprecision (CCSSetting *setting) + { + return ccsGetValueListFromFloatArray (floatValues, sizeof (floatValues) / sizeof (floatValues[0]), setting); + } + + CCSSettingValueList string (CCSSetting *setting) + { + return ccsGetValueListFromStringArray (stringValues, sizeof (stringValues) / sizeof (stringValues[0]), setting); + } + + CCSSettingValueList match (CCSSetting *setting) + { + return ccsGetValueListFromMatchArray (matchValues, sizeof (matchValues) / sizeof (matchValues[0]), setting); + } + + CCSSettingValueList color (CCSSetting *setting) + { + return ccsGetValueListFromColorArray (getColorValueList (), 3, setting); + } + } + } + } + } +} + +#endif diff --git a/gtk/gnome/50-compiz-launchers.xml.in b/gtk/gnome/50-compiz-launchers.xml.in new file mode 100644 index 0000000000000000000000000000000000000000..217caf39f3db0fc6e4ede69c2b2e073330edb33c --- /dev/null +++ b/gtk/gnome/50-compiz-launchers.xml.in @@ -0,0 +1,6 @@ + + + + + + diff --git a/gtk/gnome/50-compiz-navigation.xml.in b/gtk/gnome/50-compiz-navigation.xml.in new file mode 100644 index 0000000000000000000000000000000000000000..030b36bd261b4759b2a9e8917e1fe77151294034 --- /dev/null +++ b/gtk/gnome/50-compiz-navigation.xml.in @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gtk/gnome/50-compiz-screenshot.xml.in b/gtk/gnome/50-compiz-screenshot.xml.in new file mode 100644 index 0000000000000000000000000000000000000000..f2c97fa7e05a5750024c507754c07e81d02cb8e0 --- /dev/null +++ b/gtk/gnome/50-compiz-screenshot.xml.in @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/gtk/gnome/50-compiz-system.xml.in b/gtk/gnome/50-compiz-system.xml.in new file mode 100644 index 0000000000000000000000000000000000000000..926feb94f6af018d020f91e7a433a5a05c582a64 --- /dev/null +++ b/gtk/gnome/50-compiz-system.xml.in @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/gtk/gnome/50-compiz-windows.xml.in b/gtk/gnome/50-compiz-windows.xml.in new file mode 100644 index 0000000000000000000000000000000000000000..e947db654f466be95effbf5727180a0260772ac5 --- /dev/null +++ b/gtk/gnome/50-compiz-windows.xml.in @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gtk/gnome/CMakeLists.txt b/gtk/gnome/CMakeLists.txt index 893ee7676b7a4be006931a0ced75915e81189265..aa0ea74499ef6d8d7b6b349ebb66973d9e2ba672 100644 --- a/gtk/gnome/CMakeLists.txt +++ b/gtk/gnome/CMakeLists.txt @@ -9,5 +9,33 @@ if (BUILD_GNOME) DESTINATION ${datadir}/applications ) + set (_keybindings_files + 50-compiz-launchers.xml.in + 50-compiz-navigation.xml.in + 50-compiz-screenshot.xml.in + 50-compiz-system.xml.in + 50-compiz-windows.xml.in) + + set (_keybindings_files_translated "") + + foreach (_keybinding_file ${_keybindings_files}) + string (LENGTH ${_keybinding_file} _str_len) + math (EXPR _str_len_no_in "${_str_len} - 3") + string (SUBSTRING ${_keybinding_file} 0 ${_str_len_no_in} _keybinding_file_no_in) + + compiz_translate_xml (${CMAKE_CURRENT_SOURCE_DIR}/${_keybinding_file} + ${CMAKE_CURRENT_BINARY_DIR}/${_keybinding_file_no_in} NOTRANSLATIONS) + + list (APPEND _keybindings_files_translated ${CMAKE_CURRENT_BINARY_DIR}/${_keybinding_file_no_in}) + endforeach (_keybinding_file ${keybinding_files}) + + add_custom_target (compiz-gnome-keybindings ALL DEPENDS + ${_keybindings_files_translated}) + + install ( + FILES ${_keybinding_files_translated} + DESTINATION ${datadir}/gnome-control-center/keybindings + ) + add_custom_target (compiz.desktop ALL SOURCES ${desktop_file}) endif (BUILD_GNOME) diff --git a/gtk/window-decorator/settings.c b/gtk/window-decorator/settings.c index dec51ce2b83300b0519f85a33b1bcd109f9ea2f0..3ec3f7242e06b4b4dd4dcada98079430449adcfb 100644 --- a/gtk/window-decorator/settings.c +++ b/gtk/window-decorator/settings.c @@ -124,6 +124,42 @@ shadow_property_changed (WnckScreen *s) return changed; } +void +set_frame_scale (decor_frame_t *frame, + gchar *font_str) +{ + gfloat scale = 1.0f; + + gwd_decor_frame_ref (frame); + + if (frame->titlebar_font) + pango_font_description_free (frame->titlebar_font); + + frame->titlebar_font = pango_font_description_from_string (font_str); + + scale = (*theme_get_title_scale) (frame); + + pango_font_description_set_size (frame->titlebar_font, + MAX (pango_font_description_get_size (frame->titlebar_font) * scale, 1)); + + gwd_decor_frame_unref (frame); +} + +void +set_frames_scales (gpointer key, + gpointer value, + gpointer user_data) +{ + decor_frame_t *frame = (decor_frame_t *) value; + gchar *font_str = (gchar *) user_data; + + gwd_decor_frame_ref (frame); + + set_frame_scale (frame, font_str); + + gwd_decor_frame_unref (frame); +} + #ifdef USE_GCONF static gboolean use_tooltips_changed (GConfClient *client) @@ -400,42 +436,6 @@ button_layout_changed (GConfClient *client) return FALSE; } -void -set_frame_scale (decor_frame_t *frame, - gchar *font_str) -{ - gfloat scale = 1.0f; - - gwd_decor_frame_ref (frame); - - if (frame->titlebar_font) - pango_font_description_free (frame->titlebar_font); - - frame->titlebar_font = pango_font_description_from_string (font_str); - - scale = (*theme_get_title_scale) (frame); - - pango_font_description_set_size (frame->titlebar_font, - MAX (pango_font_description_get_size (frame->titlebar_font) * scale, 1)); - - gwd_decor_frame_unref (frame); -} - -void -set_frames_scales (gpointer key, - gpointer value, - gpointer user_data) -{ - decor_frame_t *frame = (decor_frame_t *) value; - gchar *font_str = (gchar *) user_data; - - gwd_decor_frame_ref (frame); - - set_frame_scale (frame, font_str); - - gwd_decor_frame_unref (frame); -} - static void titlebar_font_changed (GConfClient *client) { diff --git a/plugins/animation/animation.xml.in b/plugins/animation/animation.xml.in index f9b60ec8c654b7de0de4c20a36438f86e638a2e9..8f37edd9eec19c562c7c6255e677e4a1ca05e5fa 100644 --- a/plugins/animation/animation.xml.in +++ b/plugins/animation/animation.xml.in @@ -212,6 +212,64 @@ + + + <_short>UnMinimize Animation + + + <_short>Animation Selection + + + + + + + + <_short>Random Effects + + + + <_short>Shade Animation @@ -641,6 +699,7 @@ open_effects close_effects minimize_effects + unminimize_effects shade_effects animation:None @@ -659,6 +718,8 @@ close_random_effects minimize_effects minimize_random_effects + unminimize_effects + unminimize_random_effects shade_effects shade_random_effects @@ -687,6 +748,8 @@ close_random_effects minimize_effects minimize_random_effects + unminimize_effects + unminimize_random_effects animation:Dream <_name>Dream diff --git a/plugins/animation/include/animation/animation.h b/plugins/animation/include/animation/animation.h index 6f88d8c5db0ec22c95c352a84c56ab2a66e9d7dc..ad9f24a40035f9fa23a5428d899209620e3d86c3 100644 --- a/plugins/animation/include/animation/animation.h +++ b/plugins/animation/include/animation/animation.h @@ -11,9 +11,9 @@ typedef enum WindowEventOpen = 0, WindowEventClose, WindowEventMinimize, - WindowEventUnminimize, WindowEventShade, WindowEventUnshade, + WindowEventUnminimize, WindowEventFocus, WindowEventNum, WindowEventNone @@ -25,6 +25,7 @@ typedef enum AnimEventClose, AnimEventMinimize, AnimEventShade, + AnimEventUnMinimize, AnimEventFocus, AnimEventNum } AnimEvent; diff --git a/plugins/animation/include/animation/animeffect.h b/plugins/animation/include/animation/animeffect.h index 1b56172accf77b0b0d8156623574789e99d629dd..debc303d3715b07e1b5c5638b88fb82997e03085 100644 --- a/plugins/animation/include/animation/animeffect.h +++ b/plugins/animation/include/animation/animeffect.h @@ -8,6 +8,22 @@ typedef Animation *(*CreateAnimFunc) (CompWindow *w, const AnimEffect info, const CompRect &icon); +class AnimEffectUsedFor +{ +public: + static AnimEffectUsedFor all(); + static AnimEffectUsedFor none(); + AnimEffectUsedFor& exclude(AnimEvent event); + AnimEffectUsedFor& include(AnimEvent event); + + bool open; + bool close; + bool minimize; + bool shade; + bool unMinimize; + bool focus; +}; + /// Animation info class that holds the name, the list of supported events, and /// the creator function for a subclass of Animation. /// A pointer to this class is used as an identifier for each implemented @@ -16,7 +32,7 @@ class AnimEffectInfo { public: AnimEffectInfo (const char *name, - bool usedO, bool usedC, bool usedM, bool usedS, bool usedF, + AnimEffectUsedFor usedFor, CreateAnimFunc create, bool isRestackAnim = false); ~AnimEffectInfo () {} @@ -28,7 +44,7 @@ public: /// To be set to true for the window event animation list(s) that /// the new animation (value) should be added to - /// (0: open, 1: close, 2: minimize, 3: shade, 4: focus) + /// (0: open, 1: close, 2: minimize, 3: shade, 4: unminimize, 5: focus) bool usedForEvents[AnimEventNum]; /// Creates an instance of the Animation subclass and returns it as an diff --git a/plugins/animation/src/animation.cpp b/plugins/animation/src/animation.cpp index 4dea0ea5890327689291ae8ff3bacf79f8f7d6b0..2aa20fd48abdb2a3bf0361d51e75d9393d8b8258 100644 --- a/plugins/animation/src/animation.cpp +++ b/plugins/animation/src/animation.cpp @@ -101,7 +101,7 @@ COMPIZ_PLUGIN_20090315 (animation, AnimPluginVTable); #define FAKE_ICON_SIZE 4 const char *eventNames[AnimEventNum] = -{"Open", "Close", "Minimize", "Shade", "Focus"}; +{"Open", "Close", "Minimize", "Shade", "UnMinimize", "Focus"}; int chosenEffectOptionIds[AnimEventNum] = { @@ -109,7 +109,8 @@ int chosenEffectOptionIds[AnimEventNum] = AnimationOptions::CloseEffects, AnimationOptions::MinimizeEffects, AnimationOptions::ShadeEffects, - AnimationOptions::FocusEffects + AnimationOptions::UnminimizeEffects, + AnimationOptions::FocusEffects, }; int randomEffectOptionIds[AnimEventNum] = @@ -118,6 +119,7 @@ int randomEffectOptionIds[AnimEventNum] = AnimationOptions::CloseRandomEffects, AnimationOptions::MinimizeRandomEffects, AnimationOptions::ShadeRandomEffects, + AnimationOptions::UnminimizeRandomEffects, -1 }; @@ -127,6 +129,7 @@ int customOptionOptionIds[AnimEventNum] = AnimationOptions::CloseOptions, AnimationOptions::MinimizeOptions, AnimationOptions::ShadeOptions, + AnimationOptions::UnminimizeOptions, AnimationOptions::FocusOptions }; @@ -136,6 +139,7 @@ int matchOptionIds[AnimEventNum] = AnimationOptions::CloseMatches, AnimationOptions::MinimizeMatches, AnimationOptions::ShadeMatches, + AnimationOptions::UnminimizeMatches, AnimationOptions::FocusMatches }; @@ -145,6 +149,7 @@ int durationOptionIds[AnimEventNum] = AnimationOptions::CloseDurations, AnimationOptions::MinimizeDurations, AnimationOptions::ShadeDurations, + AnimationOptions::UnminimizeDurations, AnimationOptions::FocusDurations }; @@ -541,7 +546,7 @@ PrivateAnimWindow::updateSelectionRow (unsigned int r) } // Assumes events in the metadata are in -// [Open, Close, Minimize, Focus, Shade] order +// [Open, Close, Minimize, Shade, UnMinimize, Focus] order // and effects among those are in alphabetical order // but with "(Event) None" first and "(Event) Random" last. AnimEffect @@ -2168,7 +2173,7 @@ PrivateAnimScreen::initiateUnminimizeAnim (PrivateAnimWindow *aw) int duration = 200; AnimEffect chosenEffect = - getMatchingAnimSelection (w, AnimEventMinimize, &duration); + getMatchingAnimSelection (w, AnimEventUnMinimize, &duration); aw->mNewState = NormalState; @@ -2202,7 +2207,7 @@ PrivateAnimScreen::initiateUnminimizeAnim (PrivateAnimWindow *aw) if (startingNew) { AnimEffect effectToBePlayed = - getActualEffect (chosenEffect, AnimEventMinimize); + getActualEffect (chosenEffect, AnimEventUnMinimize); // handle empty random effect list if (effectToBePlayed == AnimEffectNone) @@ -2444,20 +2449,64 @@ PrivateAnimScreen::glPaintOutput (const GLScreenPaintAttrib &attrib, return gScreen->glPaintOutput (attrib, matrix, region, output, mask); } +AnimEffectUsedFor AnimEffectUsedFor::all () +{ + AnimEffectUsedFor usedFor; + usedFor.open = usedFor.close = usedFor.minimize = + usedFor.shade = usedFor.unMinimize = usedFor.focus = true; + return usedFor; +} + +AnimEffectUsedFor AnimEffectUsedFor::none () +{ + AnimEffectUsedFor usedFor; + usedFor.open = usedFor.close = usedFor.minimize = + usedFor.shade = usedFor.unMinimize = usedFor.focus = true; + return usedFor; +} + +AnimEffectUsedFor& AnimEffectUsedFor::exclude (AnimEvent event) +{ + switch (event) { + case AnimEventOpen: open = false; break; + case AnimEventClose: close = false; break; + case AnimEventMinimize: minimize = false; break; + case AnimEventShade: shade = false; break; + case AnimEventUnMinimize: unMinimize = false; break; + case AnimEventFocus: focus = false; break; + default: break; + } + return *this; +} + +AnimEffectUsedFor& AnimEffectUsedFor::include (AnimEvent event) +{ + switch (event) { + case AnimEventOpen: open = true; break; + case AnimEventClose: close = true; break; + case AnimEventMinimize: minimize = true; break; + case AnimEventShade: shade = true; break; + case AnimEventUnMinimize: unMinimize = true; break; + case AnimEventFocus: focus = true; break; + default: break; + } + return *this; +} + AnimEffectInfo::AnimEffectInfo (const char *name, - bool usedO, bool usedC, bool usedM, - bool usedS, bool usedF, + AnimEffectUsedFor usedFor, CreateAnimFunc create, bool isRestackAnim) : name (name), create (create), isRestackAnim (isRestackAnim) { - usedForEvents[AnimEventOpen] = usedO; - usedForEvents[AnimEventClose] = usedC; - usedForEvents[AnimEventMinimize] = usedM; - usedForEvents[AnimEventShade] = usedS; - usedForEvents[AnimEventFocus] = usedF; + usedForEvents[AnimEventOpen] = usedFor.open; + usedForEvents[AnimEventClose] = usedFor.close; + usedForEvents[AnimEventMinimize] = usedFor.minimize; + usedForEvents[AnimEventShade] = usedFor.shade; + usedForEvents[AnimEventUnMinimize] = usedFor.unMinimize; + usedForEvents[AnimEventFocus] = usedFor.focus; } bool @@ -2577,69 +2626,87 @@ void PrivateAnimScreen::initAnimationList () { int i = 0; + animEffects[i++] = AnimEffectNone = new AnimEffectInfo ("animation:None", - true, true, true, true, true, 0); + AnimEffectUsedFor::all(), + 0); + animEffects[i++] = AnimEffectRandom = new AnimEffectInfo ("animation:Random", - true, true, true, true, false, 0); + AnimEffectUsedFor::all().exclude(AnimEventFocus), + 0); + animEffects[i++] = AnimEffectCurvedFold = new AnimEffectInfo ("animation:Curved Fold", - true, true, true, true, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus), &createAnimation); + animEffects[i++] = AnimEffectDodge = - new AnimEffectInfo ("animation:Dodge", - false, false, false, false, true, + new AnimEffectInfo ("animation:Dodge", + AnimEffectUsedFor::none().include(AnimEventFocus), &createAnimation, true); + animEffects[i++] = AnimEffectDream = - new AnimEffectInfo ("animation:Dream", - true, true, true, false, false, + new AnimEffectInfo ("animation:Dream", + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectFade = new AnimEffectInfo ("animation:Fade", - true, true, true, false, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectFocusFade = - new AnimEffectInfo ("animation:Focus Fade", - false, false, false, false, true, + new AnimEffectInfo ("animation:Focus Fade", + AnimEffectUsedFor::none().include(AnimEventFocus), &createAnimation, true); + animEffects[i++] = AnimEffectGlide1 = new AnimEffectInfo ("animation:Glide 1", - true, true, true, false, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectGlide2 = new AnimEffectInfo ("animation:Glide 2", - true, true, true, false, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectHorizontalFolds = new AnimEffectInfo ("animation:Horizontal Folds", - true, true, true, true, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus), &createAnimation); + animEffects[i++] = AnimEffectMagicLamp = new AnimEffectInfo ("animation:Magic Lamp", - true, true, true, false, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectMagicLampWavy = new AnimEffectInfo ("animation:Magic Lamp Wavy", - true, true, true, false, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectRollUp = new AnimEffectInfo ("animation:Roll Up", - false, false, false, true, false, + AnimEffectUsedFor::none().include(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectSidekick = new AnimEffectInfo ("animation:Sidekick", - true, true, true, false, false, + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectWave = new AnimEffectInfo ("animation:Wave", - true, true, true, false, true, + AnimEffectUsedFor::all().exclude(AnimEventShade), &createAnimation); + animEffects[i++] = AnimEffectZoom = - new AnimEffectInfo ("animation:Zoom", - true, true, true, false, false, + new AnimEffectInfo ("animation:Zoom", + AnimEffectUsedFor::all().exclude(AnimEventFocus).exclude(AnimEventShade), &createAnimation); animExtensionPluginInfo.effectOptions = &getOptions (); diff --git a/plugins/animationaddon/src/animationaddon.cpp b/plugins/animationaddon/src/animationaddon.cpp index fd00b09fe0cb3b79953283db29baac61ce109a06..a806dbe9f7167f1e671b6c4d4ea5edc79103b429 100644 --- a/plugins/animationaddon/src/animationaddon.cpp +++ b/plugins/animationaddon/src/animationaddon.cpp @@ -136,54 +136,42 @@ void PrivateAnimAddonScreen::initAnimationList () { int i = 0; + AnimEffectUsedFor usedFor = AnimEffectUsedFor::all() + .exclude(AnimEventFocus) + .exclude(AnimEventShade); animEffects[i++] = AnimEffectAirplane = - new AnimEffectInfo ("animationaddon:Airplane", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Airplane", usedFor, &createAnimation); - animEffects[i++] = AnimEffectBeamUp = - new AnimEffectInfo ("animationaddon:Beam Up", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Beam Up", usedFor, &createAnimation); animEffects[i++] = AnimEffectBurn = - new AnimEffectInfo ("animationaddon:Burn", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Burn", usedFor, &createAnimation); animEffects[i++] = AnimEffectDissolve = - new AnimEffectInfo ("animationaddon:Dissolve", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Dissolve", usedFor, &createAnimation); animEffects[i++] = AnimEffectDomino = - new AnimEffectInfo ("animationaddon:Domino", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Domino", usedFor, &createAnimation); animEffects[i++] = AnimEffectExplode = - new AnimEffectInfo ("animationaddon:Explode", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Explode", usedFor, &createAnimation); - animEffects[i++] = AnimEffectFold = - new AnimEffectInfo ("animationaddon:Fold", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Fold", usedFor, &createAnimation); - animEffects[i++] = AnimEffectGlide3 = - new AnimEffectInfo ("animationaddon:Glide 3", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Glide 3", usedFor, &createAnimation); - animEffects[i++] = AnimEffectLeafSpread = - new AnimEffectInfo ("animationaddon:Leaf Spread", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Leaf Spread", usedFor, &createAnimation); animEffects[i++] = AnimEffectRazr = - new AnimEffectInfo ("animationaddon:Razr", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Razr", usedFor, &createAnimation); animEffects[i++] = AnimEffectSkewer = - new AnimEffectInfo ("animationaddon:Skewer", - true, true, true, false, false, + new AnimEffectInfo ("animationaddon:Skewer", usedFor, &createAnimation); animAddonExtPluginInfo.effectOptions = &getOptions (); diff --git a/plugins/expo/src/expo.cpp b/plugins/expo/src/expo.cpp index b98b80e6caac5b7519e0f6a3097693d4e76f6da5..758e006d95b5f0afb0c8f090ce9d9b1236241b4c 100644 --- a/plugins/expo/src/expo.cpp +++ b/plugins/expo/src/expo.cpp @@ -339,6 +339,10 @@ ExpoScreen::handleEvent (XEvent *event) if (expoMode && event->xbutton.button == Button1 && event->xbutton.root == screen->root ()) { + CompPoint pointer (event->xbutton.x_root, event->xbutton.y_root); + if (!screen->workArea().contains (pointer)) + break; + anyClick = true; if (clickTime == 0) { @@ -363,6 +367,10 @@ ExpoScreen::handleEvent (XEvent *event) if (expoMode && event->xbutton.button == Button1 && event->xbutton.root == screen->root ()) { + CompPoint pointer (event->xbutton.x_root, event->xbutton.y_root); + if (!screen->workArea().contains (pointer)) + break; + if (event->xbutton.time - clickTime > (unsigned int) optionGetDoubleClickTime ()) { diff --git a/plugins/imgsvg/CMakeLists.txt b/plugins/imgsvg/CMakeLists.txt index 000198a55f96093765e7e5b99b2306ae95287871..74989db25e1151f0f5b6206cdf77e457da38ae9f 100644 --- a/plugins/imgsvg/CMakeLists.txt +++ b/plugins/imgsvg/CMakeLists.txt @@ -2,4 +2,15 @@ find_package (Compiz REQUIRED) include (CompizPlugin) -compiz_plugin(imgsvg PLUGINDEPS composite opengl PKGDEPS cairo>=1.0 cairo-xlib librsvg-2.0>=2.14.0) \ No newline at end of file +pkg_check_modules (RSVG librsvg-2.0>=2.36.2) + +if (RSVG_FOUND) + compiz_set (HAVE_RSVG_2_36_2 1) +endif (RSVG_FOUND) + +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/imgsvg-config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/src/imgsvg-config.h) + +include_directories (${CMAKE_CURRENT_BINARY_DIR}/src) + +compiz_plugin(imgsvg PLUGINDEPS composite opengl PKGDEPS cairo>=1.0 cairo-xlib librsvg-2.0>=2.14.0) diff --git a/plugins/imgsvg/src/imgsvg-config.h.in b/plugins/imgsvg/src/imgsvg-config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..d94654a55b9989b45f680e3b1bc902ae7bf20f94 --- /dev/null +++ b/plugins/imgsvg/src/imgsvg-config.h.in @@ -0,0 +1 @@ +#cmakedefine HAVE_RSVG_2_36_2 diff --git a/plugins/imgsvg/src/imgsvg.h b/plugins/imgsvg/src/imgsvg.h index d8a0680816da33645b3c25373f082a672f14785e..95b36767532852133ee26d618bf5af103c6042f7 100644 --- a/plugins/imgsvg/src/imgsvg.h +++ b/plugins/imgsvg/src/imgsvg.h @@ -33,9 +33,14 @@ #include #include +#include + #include #include + +#ifndef HAVE_RSVG_2_36_2 #include +#endif #include #include diff --git a/plugins/resize/CMakeLists.txt b/plugins/resize/CMakeLists.txt index 4c21ab9ce065e139e898a9ef16cf3a52402b3d5b..f1d5cedb0949875f1ebf2f8cf455034fdea863c2 100644 --- a/plugins/resize/CMakeLists.txt +++ b/plugins/resize/CMakeLists.txt @@ -2,4 +2,7 @@ find_package (Compiz REQUIRED) include (CompizPlugin) -compiz_plugin(resize PLUGINDEPS composite opengl) +add_subdirectory (src/logic) +include_directories (src/logic/include) + +compiz_plugin(resize PLUGINDEPS composite opengl LIBRARIES resize_logic) diff --git a/plugins/resize/resize.xml.in b/plugins/resize/resize.xml.in index 2605c59f1047b883dc64a1ccce306eff89ac1434..53067d5dbeaefb7187f60cdc790844eeada22d56 100644 --- a/plugins/resize/resize.xml.in +++ b/plugins/resize/resize.xml.in @@ -53,6 +53,11 @@ Same as setting 'any' for resize_from_center_match false +