diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,6 +177,7 @@ add_subdirectory(layout-templates) +add_subdirectory(gtkconfig) add_subdirectory(doc) add_subdirectory(runners) add_subdirectory(containments) diff --git a/cmake/modules/FindGSettingSchemas.cmake b/cmake/modules/FindGSettingSchemas.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/FindGSettingSchemas.cmake @@ -0,0 +1,23 @@ +find_package(PkgConfig) + +pkg_check_modules(PC_GLIB2 REQUIRED glib-2.0) + +find_path(GLIB_SCHEMAS_DIR org.gnome.desktop.interface.gschema.xml + HINTS ${PC_GLIB2_PREFIX}/share + PATH_SUFFIXES glib-2.0/schemas) + +if (GLIB_SCHEMAS_DIR) + set(GSettingSchemas_FOUND true) +else() + set(GSettingSchemas_FOUND false) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(GSettingSchemas + FOUND_VAR + GSettingSchemas_FOUND + REQUIRED_VARS + GSettingSchemas_FOUND +) + +mark_as_advanced(GSettingSchemas_FOUND) diff --git a/cmake/modules/FindGTK2.cmake b/cmake/modules/FindGTK2.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/FindGTK2.cmake @@ -0,0 +1,597 @@ +# - FindGTK2.cmake +# This module can find the GTK2 widget libraries and several of its other +# optional components like gtkmm, glade, and glademm. +# +# NOTE: If you intend to use version checking, CMake 2.6.2 or later is +# required. +# +# Specify one or more of the following components +# as you call this find module. See example below. +# +# gtk +# gtkmm +# glade +# glademm +# +# The following variables will be defined for your use +# +# GTK2_FOUND - Were all of your specified components found? +# GTK2_INCLUDE_DIRS - All include directories +# GTK2_LIBRARIES - All libraries +# +# GTK2_VERSION - The version of GTK2 found (x.y.z) +# GTK2_MAJOR_VERSION - The major version of GTK2 +# GTK2_MINOR_VERSION - The minor version of GTK2 +# GTK2_PATCH_VERSION - The patch version of GTK2 +# +# Optional variables you can define prior to calling this module: +# +# GTK2_DEBUG - Enables verbose debugging of the module +# GTK2_SKIP_MARK_AS_ADVANCED - Disable marking cache variables as advanced +# GTK2_ADDITIONAL_SUFFIXES - Allows defining additional directories to +# search for include files +# +#================= +# Example Usage: +# +# Call find_package() once, here are some examples to pick from: +# +# Require GTK 2.6 or later +# find_package(GTK2 2.6 REQUIRED gtk) +# +# Require GTK 2.10 or later and Glade +# find_package(GTK2 2.10 REQUIRED gtk glade) +# +# Search for GTK/GTKMM 2.8 or later +# find_package(GTK2 2.8 COMPONENTS gtk gtkmm) +# +# if(GTK2_FOUND) +# include_directories(${GTK2_INCLUDE_DIRS}) +# add_executable(mygui mygui.cc) +# target_link_libraries(mygui ${GTK2_LIBRARIES}) +# endif() +# + +#============================================================================= +# Copyright 2009 Kitware, Inc. +# Copyright 2008-2009 Philip Lowman +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Version 1.3 (11/9/2010) (CMake 2.8.4) +# * 11429: Add support for detecting GTK2 built with Visual Studio 10. +# Thanks to Vincent Levesque for the patch. + +# Version 1.2 (8/30/2010) (CMake 2.8.3) +# * Merge patch for detecting gdk-pixbuf library (split off +# from core GTK in 2.21). Thanks to Vincent Untz for the patch +# and Ricardo Cruz for the heads up. +# Version 1.1 (8/19/2010) (CMake 2.8.3) +# * Add support for detecting GTK2 under macports (thanks to Gary Kramlich) +# Version 1.0 (8/12/2010) (CMake 2.8.3) +# * Add support for detecting new pangommconfig.h header file +# (Thanks to Sune Vuorela & the Debian Project for the patch) +# * Add support for detecting fontconfig.h header +# * Call find_package(Freetype) since it's required +# * Add support for allowing users to add additional library directories +# via the GTK2_ADDITIONAL_SUFFIXES variable (kind of a future-kludge in +# case the GTK developers change versions on any of the directories in the +# future). +# Version 0.8 (1/4/2010) +# * Get module working under MacOSX fink by adding /sw/include, /sw/lib +# to PATHS and the gobject library +# Version 0.7 (3/22/09) +# * Checked into CMake CVS +# * Added versioning support +# * Module now defaults to searching for GTK if COMPONENTS not specified. +# * Added HKCU prior to HKLM registry key and GTKMM specific environment +# variable as per mailing list discussion. +# * Added lib64 to include search path and a few other search paths where GTK +# may be installed on Unix systems. +# * Switched to lowercase CMake commands +# * Prefaced internal variables with _GTK2 to prevent collision +# * Changed internal macros to functions +# * Enhanced documentation +# Version 0.6 (1/8/08) +# Added GTK2_SKIP_MARK_AS_ADVANCED option +# Version 0.5 (12/19/08) +# Second release to cmake mailing list + +#============================================================= +# _GTK2_GET_VERSION +# Internal function to parse the version number in gtkversion.h +# _OUT_major = Major version number +# _OUT_minor = Minor version number +# _OUT_micro = Micro version number +# _gtkversion_hdr = Header file to parse +#============================================================= +function(_GTK2_GET_VERSION _OUT_major _OUT_minor _OUT_micro _gtkversion_hdr) + file(READ ${_gtkversion_hdr} _contents) + if(_contents) + string(REGEX REPLACE ".*#define GTK_MAJOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_major} "${_contents}") + string(REGEX REPLACE ".*#define GTK_MINOR_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_minor} "${_contents}") + string(REGEX REPLACE ".*#define GTK_MICRO_VERSION[ \t]+\\(([0-9]+)\\).*" "\\1" ${_OUT_micro} "${_contents}") + + if(NOT ${_OUT_major} MATCHES "[0-9]+") + message(FATAL_ERROR "Version parsing failed for GTK2_MAJOR_VERSION!") + endif() + if(NOT ${_OUT_minor} MATCHES "[0-9]+") + message(FATAL_ERROR "Version parsing failed for GTK2_MINOR_VERSION!") + endif() + if(NOT ${_OUT_micro} MATCHES "[0-9]+") + message(FATAL_ERROR "Version parsing failed for GTK2_MICRO_VERSION!") + endif() + + set(${_OUT_major} ${${_OUT_major}} PARENT_SCOPE) + set(${_OUT_minor} ${${_OUT_minor}} PARENT_SCOPE) + set(${_OUT_micro} ${${_OUT_micro}} PARENT_SCOPE) + else() + message(FATAL_ERROR "Include file ${_gtkversion_hdr} does not exist") + endif() +endfunction() + +#============================================================= +# _GTK2_FIND_INCLUDE_DIR +# Internal function to find the GTK include directories +# _var = variable to set +# _hdr = header file to look for +#============================================================= +function(_GTK2_FIND_INCLUDE_DIR _var _hdr) + + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "_GTK2_FIND_INCLUDE_DIR( ${_var} ${_hdr} )") + endif() + + set(_relatives + # If these ever change, things will break. + ${GTK2_ADDITIONAL_SUFFIXES} + glibmm-2.4 + glib-2.0 + atk-1.0 + atkmm-1.6 + cairo + cairomm-1.0 + gdk-pixbuf-2.0 + gdkmm-2.4 + giomm-2.4 + gtk-2.0 + gtkmm-2.4 + libglade-2.0 + libglademm-2.4 + pango-1.0 + pangomm-1.4 + sigc++-2.0 + ) + + set(_suffixes) + foreach(_d ${_relatives}) + list(APPEND _suffixes ${_d}) + list(APPEND _suffixes ${_d}/include) # for /usr/lib/gtk-2.0/include + endforeach() + + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "include suffixes = ${_suffixes}") + endif() + + find_path(${_var} ${_hdr} + PATHS + /usr/local/lib64 + /usr/local/lib + /usr/lib64 + /usr/lib + /opt/gnome/include + /opt/gnome/lib + /opt/openwin/include + /usr/openwin/lib + /sw/include + /sw/lib + /opt/local/include + /opt/local/lib + /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/ + $ENV{GTKMM_BASEPATH}/include + $ENV{GTKMM_BASEPATH}/lib + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/include + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/include + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib + PATH_SUFFIXES + ${_suffixes} + ) + + if(${_var}) + set(GTK2_INCLUDE_DIRS ${GTK2_INCLUDE_DIRS} ${${_var}} PARENT_SCOPE) + if(NOT GTK2_SKIP_MARK_AS_ADVANCED) + mark_as_advanced(${_var}) + endif() + endif() + +endfunction(_GTK2_FIND_INCLUDE_DIR) + +#============================================================= +# _GTK2_FIND_LIBRARY +# Internal function to find libraries packaged with GTK2 +# _var = library variable to create +#============================================================= +function(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version) + + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "_GTK2_FIND_LIBRARY( ${_var} ${_lib} ${_expand_vc} ${_append_version} )") + endif() + + # Not GTK versions per se but the versions encoded into Windows + # import libraries (GtkMM 2.14.1 has a gtkmm-vc80-2_4.lib for example) + # Also the MSVC libraries use _ for . (this is handled below) + set(_versions 2.20 2.18 2.16 2.14 2.12 + 2.10 2.8 2.6 2.4 2.2 2.0 + 1.20 1.18 1.16 1.14 1.12 + 1.10 1.8 1.6 1.4 1.2 1.0) + + set(_library) + set(_library_d) + + set(_library ${_lib}) + + if(_expand_vc AND MSVC) + # Add vc80/vc90/vc100 midfixes + if(MSVC80) + set(_library ${_library}-vc80) + elseif(MSVC90) + set(_library ${_library}-vc90) + elseif(MSVC10) + set(_library ${_library}-vc100) + endif() + set(_library_d ${_library}-d) + endif() + + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "After midfix addition = ${_library} and ${_library_d}") + endif() + + set(_lib_list) + set(_libd_list) + if(_append_version) + foreach(_ver ${_versions}) + list(APPEND _lib_list "${_library}-${_ver}") + list(APPEND _libd_list "${_library_d}-${_ver}") + endforeach() + else() + set(_lib_list ${_library}) + set(_libd_list ${_library_d}) + endif() + + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "library list = ${_lib_list} and library debug list = ${_libd_list}") + endif() + + # For some silly reason the MSVC libraries use _ instead of . + # in the version fields + if(_expand_vc AND MSVC) + set(_no_dots_lib_list) + set(_no_dots_libd_list) + foreach(_l ${_lib_list}) + string(REPLACE "." "_" _no_dots_library ${_l}) + list(APPEND _no_dots_lib_list ${_no_dots_library}) + endforeach() + # And for debug + set(_no_dots_libsd_list) + foreach(_l ${_libd_list}) + string(REPLACE "." "_" _no_dots_libraryd ${_l}) + list(APPEND _no_dots_libd_list ${_no_dots_libraryd}) + endforeach() + + # Copy list back to original names + set(_lib_list ${_no_dots_lib_list}) + set(_libd_list ${_no_dots_libd_list}) + endif() + + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "While searching for ${_var}, our proposed library list is ${_lib_list}") + endif() + + find_library(${_var} + NAMES ${_lib_list} + PATHS + /opt/gnome/lib + /opt/gnome/lib64 + /usr/openwin/lib + /usr/openwin/lib64 + /sw/lib + $ENV{GTKMM_BASEPATH}/lib + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib + ) + + if(_expand_vc AND MSVC) + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "While searching for ${_var}_DEBUG our proposed library list is ${_libd_list}") + endif() + + find_library(${_var}_DEBUG + NAMES ${_libd_list} + PATHS + $ENV{GTKMM_BASEPATH}/lib + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path]/lib + ) + + if(${_var} AND ${_var}_DEBUG) + if(NOT GTK2_SKIP_MARK_AS_ADVANCED) + mark_as_advanced(${_var}_DEBUG) + endif() + set(GTK2_LIBRARIES ${GTK2_LIBRARIES} optimized ${${_var}} debug ${${_var}_DEBUG}) + set(GTK2_LIBRARIES ${GTK2_LIBRARIES} PARENT_SCOPE) + endif() + else() + if(NOT GTK2_SKIP_MARK_AS_ADVANCED) + mark_as_advanced(${_var}) + endif() + set(GTK2_LIBRARIES ${GTK2_LIBRARIES} ${${_var}}) + set(GTK2_LIBRARIES ${GTK2_LIBRARIES} PARENT_SCOPE) + # Set debug to release + set(${_var}_DEBUG ${${_var}}) + set(${_var}_DEBUG ${${_var}} PARENT_SCOPE) + endif() +endfunction(_GTK2_FIND_LIBRARY) + +#============================================================= + +# +# main() +# + +set(GTK2_FOUND) +set(GTK2_INCLUDE_DIRS) +set(GTK2_LIBRARIES) + +if(NOT GTK2_FIND_COMPONENTS) + # Assume they only want GTK + set(GTK2_FIND_COMPONENTS gtk) +endif() + +# +# If specified, enforce version number +# +if(GTK2_FIND_VERSION) + cmake_minimum_required(VERSION 2.6.2) + set(GTK2_FAILED_VERSION_CHECK true) + if(GTK2_DEBUG) + message(STATUS "[FindGTK2.cmake:${CMAKE_CURRENT_LIST_LINE}] " + "Searching for version ${GTK2_FIND_VERSION}") + endif() + _GTK2_FIND_INCLUDE_DIR(GTK2_GTK_INCLUDE_DIR gtk/gtk.h) + if(GTK2_GTK_INCLUDE_DIR) + _GTK2_GET_VERSION(GTK2_MAJOR_VERSION + GTK2_MINOR_VERSION + GTK2_PATCH_VERSION + ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h) + set(GTK2_VERSION + ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION}) + if(GTK2_FIND_VERSION_EXACT) + if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION) + set(GTK2_FAILED_VERSION_CHECK false) + endif() + else() + if(GTK2_VERSION VERSION_EQUAL GTK2_FIND_VERSION OR + GTK2_VERSION VERSION_GREATER GTK2_FIND_VERSION) + set(GTK2_FAILED_VERSION_CHECK false) + endif() + endif() + else() + # If we can't find the GTK include dir, we can't do version checking + if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY) + message(FATAL_ERROR "Could not find GTK2 include directory") + endif() + return() + endif() + + if(GTK2_FAILED_VERSION_CHECK) + if(GTK2_FIND_REQUIRED AND NOT GTK2_FIND_QUIETLY) + if(GTK2_FIND_VERSION_EXACT) + message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, version ${GTK2_FIND_VERSION} is needed exactly.") + else() + message(FATAL_ERROR "GTK2 version check failed. Version ${GTK2_VERSION} was found, at least version ${GTK2_FIND_VERSION} is required") + endif() + endif() + + # If the version check fails, exit out of the module here + return() + endif() +endif() + +# +# Find all components +# + +# find_package(Freetype) +# list(APPEND GTK2_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS}) +# list(APPEND GTK2_LIBRARIES ${FREETYPE_LIBRARIES}) + +foreach(_GTK2_component ${GTK2_FIND_COMPONENTS}) + if(_GTK2_component STREQUAL "gtk") + _GTK2_FIND_INCLUDE_DIR(GTK2_GLIB_INCLUDE_DIR glib.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBCONFIG_INCLUDE_DIR glibconfig.h) + _GTK2_FIND_LIBRARY (GTK2_GLIB_LIBRARY glib false true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_GOBJECT_INCLUDE_DIR gobject/gobject.h) + _GTK2_FIND_LIBRARY (GTK2_GOBJECT_LIBRARY gobject false true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_GDK_PIXBUF_INCLUDE_DIR gdk-pixbuf/gdk-pixbuf.h) + _GTK2_FIND_LIBRARY (GTK2_GDK_PIXBUF_LIBRARY gdk_pixbuf false true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_GDK_INCLUDE_DIR gdk/gdk.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GDKCONFIG_INCLUDE_DIR gdkconfig.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GTK_INCLUDE_DIR gtk/gtk.h) + + if(UNIX) + _GTK2_FIND_LIBRARY (GTK2_GDK_LIBRARY gdk-x11 false true) + _GTK2_FIND_LIBRARY (GTK2_GTK_LIBRARY gtk-x11 false true) + else() + _GTK2_FIND_LIBRARY (GTK2_GDK_LIBRARY gdk-win32 false true) + _GTK2_FIND_LIBRARY (GTK2_GTK_LIBRARY gtk-win32 false true) + endif() + + _GTK2_FIND_INCLUDE_DIR(GTK2_CAIRO_INCLUDE_DIR cairo.h) + _GTK2_FIND_LIBRARY (GTK2_CAIRO_LIBRARY cairo false false) + + _GTK2_FIND_INCLUDE_DIR(GTK2_FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h) + + _GTK2_FIND_INCLUDE_DIR(GTK2_PANGO_INCLUDE_DIR pango/pango.h) + _GTK2_FIND_LIBRARY (GTK2_PANGO_LIBRARY pango false true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_ATK_INCLUDE_DIR atk/atk.h) + _GTK2_FIND_LIBRARY (GTK2_ATK_LIBRARY atk false true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_GIO_INCLUDE_DIR gio/gio.h) + _GTK2_FIND_LIBRARY (GTK2_GIO_LIBRARY gio false true) + + + elseif(_GTK2_component STREQUAL "gtkmm") + + _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBMM_INCLUDE_DIR glibmm.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GLIBMMCONFIG_INCLUDE_DIR glibmmconfig.h) + _GTK2_FIND_LIBRARY (GTK2_GLIBMM_LIBRARY glibmm true true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_GDKMM_INCLUDE_DIR gdkmm.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GDKMMCONFIG_INCLUDE_DIR gdkmmconfig.h) + _GTK2_FIND_LIBRARY (GTK2_GDKMM_LIBRARY gdkmm true true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_GTKMM_INCLUDE_DIR gtkmm.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GTKMMCONFIG_INCLUDE_DIR gtkmmconfig.h) + _GTK2_FIND_LIBRARY (GTK2_GTKMM_LIBRARY gtkmm true true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_CAIROMM_INCLUDE_DIR cairomm/cairomm.h) + _GTK2_FIND_LIBRARY (GTK2_CAIROMM_LIBRARY cairomm true true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_PANGOMM_INCLUDE_DIR pangomm.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_PANGOMMCONFIG_INCLUDE_DIR pangommconfig.h) + _GTK2_FIND_LIBRARY (GTK2_PANGOMM_LIBRARY pangomm true true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_SIGC++_INCLUDE_DIR sigc++/sigc++.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_SIGC++CONFIG_INCLUDE_DIR sigc++config.h) + _GTK2_FIND_LIBRARY (GTK2_SIGC++_LIBRARY sigc true true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_GIOMM_INCLUDE_DIR giomm.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GIOMMCONFIG_INCLUDE_DIR giommconfig.h) + _GTK2_FIND_LIBRARY (GTK2_GIOMM_LIBRARY giomm true true) + + _GTK2_FIND_INCLUDE_DIR(GTK2_ATKMM_INCLUDE_DIR atkmm.h) + _GTK2_FIND_LIBRARY (GTK2_ATKMM_LIBRARY atkmm true true) + + elseif(_GTK2_component STREQUAL "glade") + + _GTK2_FIND_INCLUDE_DIR(GTK2_GLADE_INCLUDE_DIR glade/glade.h) + _GTK2_FIND_LIBRARY (GTK2_GLADE_LIBRARY glade false true) + + elseif(_GTK2_component STREQUAL "glademm") + + _GTK2_FIND_INCLUDE_DIR(GTK2_GLADEMM_INCLUDE_DIR libglademm.h) + _GTK2_FIND_INCLUDE_DIR(GTK2_GLADEMMCONFIG_INCLUDE_DIR libglademmconfig.h) + _GTK2_FIND_LIBRARY (GTK2_GLADEMM_LIBRARY glademm true true) + + else() + message(FATAL_ERROR "Unknown GTK2 component ${_component}") + endif() +endforeach() + +# +# Solve for the GTK2 version if we haven't already +# +if(NOT GTK2_FIND_VERSION AND GTK2_GTK_INCLUDE_DIR) + _GTK2_GET_VERSION(GTK2_MAJOR_VERSION + GTK2_MINOR_VERSION + GTK2_PATCH_VERSION + ${GTK2_GTK_INCLUDE_DIR}/gtk/gtkversion.h) + set(GTK2_VERSION ${GTK2_MAJOR_VERSION}.${GTK2_MINOR_VERSION}.${GTK2_PATCH_VERSION}) +endif() + +# +# Try to enforce components +# + +set(_GTK2_did_we_find_everything true) # This gets set to GTK2_FOUND + +include(FindPackageHandleStandardArgs) + +foreach(_GTK2_component ${GTK2_FIND_COMPONENTS}) + string(TOUPPER ${_GTK2_component} _COMPONENT_UPPER) + + if(_GTK2_component STREQUAL "gtk") + FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtk libraries were not found." + GTK2_GTK_LIBRARY + GTK2_GTK_INCLUDE_DIR + + GTK2_GLIB_INCLUDE_DIR + GTK2_GLIBCONFIG_INCLUDE_DIR + GTK2_GLIB_LIBRARY + + GTK2_GDK_INCLUDE_DIR + GTK2_GDKCONFIG_INCLUDE_DIR + GTK2_GDK_LIBRARY + + GTK2_GIO_INCLUDE_DIR + GTK2_GIO_LIBRARY + ) + elseif(_GTK2_component STREQUAL "gtkmm") + FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "Some or all of the gtkmm libraries were not found." + GTK2_GTKMM_LIBRARY + GTK2_GTKMM_INCLUDE_DIR + GTK2_GTKMMCONFIG_INCLUDE_DIR + + GTK2_GLIBMM_INCLUDE_DIR + GTK2_GLIBMMCONFIG_INCLUDE_DIR + GTK2_GLIBMM_LIBRARY + + GTK2_GDKMM_INCLUDE_DIR + GTK2_GDKMMCONFIG_INCLUDE_DIR + GTK2_GDKMM_LIBRARY + ) + elseif(_GTK2_component STREQUAL "glade") + FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glade library was not found." + GTK2_GLADE_LIBRARY + GTK2_GLADE_INCLUDE_DIR + ) + elseif(_GTK2_component STREQUAL "glademm") + FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK2_${_COMPONENT_UPPER} "The glademm library was not found." + GTK2_GLADEMM_LIBRARY + GTK2_GLADEMM_INCLUDE_DIR + GTK2_GLADEMMCONFIG_INCLUDE_DIR + ) + endif() + + if(NOT GTK2_${_COMPONENT_UPPER}_FOUND) + set(_GTK2_did_we_find_everything false) + endif() +endforeach() + +if(_GTK2_did_we_find_everything AND NOT GTK2_VERSION_CHECK_FAILED) + set(GTK2_FOUND true) +else() + # Unset our variables. + set(GTK2_FOUND false) + set(GTK2_VERSION) + set(GTK2_VERSION_MAJOR) + set(GTK2_VERSION_MINOR) + set(GTK2_VERSION_PATCH) + set(GTK2_INCLUDE_DIRS) + set(GTK2_LIBRARIES) +endif() + +if(GTK2_INCLUDE_DIRS) + list(REMOVE_DUPLICATES GTK2_INCLUDE_DIRS) +endif() + diff --git a/cmake/modules/FindGTK3.cmake b/cmake/modules/FindGTK3.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/FindGTK3.cmake @@ -0,0 +1,193 @@ +# - Find gtk3, glib +# Defines: +# GTK3_FOUND +# GTK3_INCLUDE_DIRS +# GTK3_LIBRARY_DIRS +# GTK3_DEFINITIONS +# GTK3_DEFINITIONS + +FIND_PACKAGE(PkgConfig) + +# +# gtk +# +PKG_CHECK_MODULES(PC_GTK3 REQUIRED gtk+-3.0) + +SET(GTK3_DEFINITIONS ${PC_GTK3_CXXFLAGS_OTHER}) + +FIND_PATH( + GTK3_INCLUDE_DIR gtk/gtk.h + HINTS ${PC_GTK3_INCLUDEDIR} ${PC_GTK3_INCLUDE_DIRS} + PATH_SUFFIXES gtk-3.0) + +FIND_LIBRARY( + GTK3_LIBRARY NAMES gtk-3 + HINTS ${PC_GTK3_LIBDIR} ${PC_GTK3_LIBRARY_DIRS}) + +# +# glib +# +PKG_CHECK_MODULES(PC_GLIB2 REQUIRED glib-2.0) + +SET(GLIB2_DEFINITIONS ${PC_GLIB2_CXXFLAGS_OTHER}) + +FIND_PATH( + GLIB2_INCLUDE_DIR_PART1 glib.h + HINTS ${PC_GLIB2_INCLUDEDIR} ${PC_GLIB2_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0) + +FIND_PATH( + GLIB2_INCLUDE_DIR_PART2 glibconfig.h + HINTS ${PC_GLIB2_INCLUDEDIR} ${PC_GLIB2_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0/include) + +SET(GLIB2_INCLUDE_DIR ${GLIB2_INCLUDE_DIR_PART1} ${GLIB2_INCLUDE_DIR_PART2}) + +FIND_LIBRARY( + GLIB2_LIBRARY NAMES glib-2.0 + HINTS ${PC_GLIB2_LIBDIR} ${PC_GLIB2_LIBRARY_DIRS}) + +# +# gobject +# +PKG_CHECK_MODULES(PC_GOBJECT2 REQUIRED gobject-2.0) + +SET(GLIB2_DEFINITIONS ${PC_GOBJECT2_CXXFLAGS_OTHER}) + +FIND_PATH( + GOBJECT2_INCLUDE_DIR_PART1 glib.h + HINTS ${PC_GOBJECT2_INCLUDEDIR} ${PC_GOBJECT2_INCLUDE_DIRS} + PATH_SUFFIXES gobject-2.0) + +FIND_PATH( + GOBJECT2_INCLUDE_DIR_PART2 gobject.h + HINTS ${PC_GOBJECT2_INCLUDEDIR} ${PC_GOBJECT2_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0/gobject) + +SET(GOBJECT2_INCLUDE_DIR ${GOBJECT2_INCLUDE_DIR_PART1} ${GOBJECT2_INCLUDE_DIR_PART2}) + +FIND_LIBRARY( + GOBJECT2_LIBRARY NAMES gobject-2.0 + HINTS ${PC_GOBJECT2_LIBDIR} ${PC_GOBJECT2_LIBRARY_DIRS}) + +# +# gio +# +PKG_CHECK_MODULES(PC_GIO2 REQUIRED gio-2.0) + +SET(GLIB2_DEFINITIONS ${PC_GIO2_CXXFLAGS_OTHER}) + +FIND_PATH( + GIO2_INCLUDE_DIR_PART1 glib.h + HINTS ${PC_GIO2_INCLUDEDIR} ${PC_GIO2_INCLUDE_DIRS} + PATH_SUFFIXES gio) + +FIND_PATH( + GIO2_INCLUDE_DIR_PART2 gio.h + HINTS ${PC_GIO2_INCLUDEDIR} ${PC_GIO2_INCLUDE_DIRS} + PATH_SUFFIXES glib-2.0/gio) + +SET(GIO2_INCLUDE_DIR ${GIO2_INCLUDE_DIR_PART1} ${GIO2_INCLUDE_DIR_PART2}) + +FIND_LIBRARY( + GIO2_LIBRARY NAMES gio-2.0 + HINTS ${PC_GIO2_LIBDIR} ${PC_GIO2_LIBRARY_DIRS}) + + +# +# pango +# +PKG_CHECK_MODULES(PC_PANGO REQUIRED pango) + +SET(PANGO_DEFINITIONS ${PC_PANGO_CXXFLAGS_OTHER}) + +FIND_PATH( + PANGO_INCLUDE_DIR pango/pango.h + HINTS ${PC_PANGO_INCLUDEDIR} ${PC_PANGO_INCLUDE_DIRS} + PATH_SUFFIXES pango-1.0) + +FIND_LIBRARY( + PANGO_LIBRARY NAMES pango-1.0 + HINTS ${PC_PANGO_LIBDIR} ${PC_PANGO_LIBRARY_DIRS}) + +# +# harfbuzz +# +if(PC_PANGO_VERSION VERSION_EQUAL 1.44 OR PC_PANGO_VERSION VERSION_GREATER 1.44) + PKG_CHECK_MODULES(PC_HARFBUZZ REQUIRED harfbuzz) + + SET(HARFBUZZ_DEFINITIONS ${PC_HARFBUZZ_CXXFLAGS_OTHER}) + + FIND_PATH( + HARFBUZZ_INCLUDE_DIR hb.h + HINTS ${PC_HARFBUZZ_INCLUDEDIR} ${PC_HARFBUZZ_INCLUDE_DIRS} + PATH_SUFFIXES harfbuzz) + + FIND_LIBRARY( + HARFBUZZ_LIBRARY NAMES harfbuzz + HINTS ${PC_HARFBUZZ_LIBDIR} ${PC_HARFBUZZ_LIBRARY_DIRS}) +endif() + +# +# cairo +# +PKG_CHECK_MODULES(PC_CAIRO REQUIRED cairo) + +SET(CAIRO_DEFINITIONS ${PC_CAIRO_CXXFLAGS_OTHER}) + +FIND_PATH( + CAIRO_INCLUDE_DIR cairo.h + HINTS ${PC_CAIRO_INCLUDEDIR} ${PC_CAIRO_INCLUDE_DIRS} + PATH_SUFFIXES cairo) + +FIND_LIBRARY( + CAIRO_LIBRARY NAMES cairo + HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS}) + +# +# gdk-pixbuf +# +PKG_CHECK_MODULES(PC_GDKPIXBUF REQUIRED gdk-pixbuf-2.0) + +SET(GDKPIXBUF_DEFINITIONS ${PC_GDKPIXBUF_CXXFLAGS_OTHER}) + +FIND_PATH( + GDKPIXBUF_INCLUDE_DIR gdk-pixbuf/gdk-pixbuf.h + HINTS ${PC_GDKPIXBUF_INCLUDEDIR} ${PC_GDKPIXBUF_INCLUDE_DIRS} + PATH_SUFFIXES gdk-pixbuf-2.0) + +FIND_LIBRARY( + GDKPIXBUF_LIBRARY NAMES gdk_pixbuf-2.0 + HINTS ${PC_GDKPIXBUF_LIBDIR} ${PC_GDKPIXBUF_LIBRARY_DIRS}) + +# +# atk +# +PKG_CHECK_MODULES(PC_ATK REQUIRED atk) + +SET(ATK_DEFINITIONS ${PC_ATK_CXXFLAGS_OTHER}) + +FIND_PATH( + ATK_INCLUDE_DIR atk/atk.h + HINTS ${PC_ATK_INCLUDEDIR} ${PC_ATK_INCLUDE_DIRS} + PATH_SUFFIXES atk-1.0) + +FIND_LIBRARY( + ATK_LIBRARY NAMES atk-1.0 + HINTS ${PC_ATK_LIBDIR} ${PC_ATK_LIBRARY_DIRS}) + +# +# +#result +# +# +SET(GTK3_LIBRARY_DIRS ${GTK3_LIBRARY} ${GLIB2_LIBRARY} ${PANGO_LIBRARY} ${HARFBUZZ_LIBRARY} ${CAIRO_LIBRARY} ${GDKPIXBUF_LIBRARY} ${ATK_LIBRARY}) +SET(GTK3_INCLUDE_DIRS ${GTK3_INCLUDE_DIR} ${GLIB2_INCLUDE_DIR} ${GIO2_INCLUDE_DIR} ${HARFBUZZ_INCLUDE_DIR} ${PANGO_INCLUDE_DIR} ${CAIRO_INCLUDE_DIR} ${GDKPIXBUF_INCLUDE_DIR} ${ATK_INCLUDE_DIR}) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS( + GTK3 DEFAULT_MSG + GTK3_LIBRARY GTK3_INCLUDE_DIR) + +MARK_AS_ADVANCED(GTK3_INCLUDE_DIR GTK3_LIBRARY) diff --git a/gtkconfig/CMakeLists.txt b/gtkconfig/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/gtkconfig/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(gtk2apps_reloader) +add_subdirectory(kded) diff --git a/gtkconfig/gtk2apps_reloader/CMakeLists.txt b/gtkconfig/gtk2apps_reloader/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/gtkconfig/gtk2apps_reloader/CMakeLists.txt @@ -0,0 +1,16 @@ +find_package(GTK2 REQUIRED) +find_package(GTK3 REQUIRED) + +add_executable(gtk2apps_reloader "gtk2reloader.c") + +target_include_directories(gtk2apps_reloader + PUBLIC + ${GTK2_INCLUDE_DIRS} + ${GTK3_INCLUDE_DIRS} +) + +target_link_libraries(gtk2apps_reloader + ${GTK2_LIBRARIES} +) + +install(TARGETS gtk2apps_reloader RUNTIME DESTINATION ${LIBEXEC_INSTALL_DIR}) diff --git a/gtkconfig/gtk2apps_reloader/gtk2reloader.c b/gtkconfig/gtk2apps_reloader/gtk2reloader.c new file mode 100644 --- /dev/null +++ b/gtkconfig/gtk2apps_reloader/gtk2reloader.c @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 Mikhail Zolotukhin + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +int main(int argc, char** argv) { + gtk_init(&argc, &argv); + + GdkEventClient event; + event.type = GDK_CLIENT_EVENT; + event.send_event = TRUE; + event.window = NULL; + event.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); + event.data_format = 8; + + gdk_event_send_clientmessage_toall((GdkEvent *)&event); + return 0; +} diff --git a/gtkconfig/kded/CMakeLists.txt b/gtkconfig/kded/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/gtkconfig/kded/CMakeLists.txt @@ -0,0 +1,29 @@ +find_package(GTK3 REQUIRED) +find_package(GSettingSchemas REQUIRED) + +set(kscreen_daemon_SRCS + gtkconfig.cpp + configeditor.cpp +) + +add_library(gtkconfig MODULE ${kscreen_daemon_SRCS}) + +target_include_directories(gtkconfig + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${GTK3_INCLUDE_DIRS} +) + +target_link_libraries(gtkconfig + Qt5::Gui + Qt5::DBus + KF5::CoreAddons + KF5::ConfigCore + KF5::DBusAddons + ${GIO2_LIBRARY} + ${GLIB2_LIBRARY} + ${GTK3_LIBRARY} + ${GOBJECT2_LIBRARY} +) + +install(TARGETS gtkconfig DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded) diff --git a/gtkconfig/kded/configeditor.h b/gtkconfig/kded/configeditor.h new file mode 100644 --- /dev/null +++ b/gtkconfig/kded/configeditor.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 Mikhail Zolotukhin + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include + +class QString; +class QFile; + +class ConfigEditor +{ +public: + ConfigEditor() = default; + + void setGtk2ConfigValue(const QString ¶mName, const QString ¶mValue); + void setGtk3ConfigValueWayland(const QString ¶mName, const QString ¶mValue); + void setGtk3ConfigValueX11SettingsIni(const QString ¶mName, const QString ¶mValue); + void setGtk3ConfigValueX11XSettingsd(const QString ¶mName, const QString ¶mValue); + +private: + void replaceValueInGtkrcContents(QString >krcContents, const QString ¶mName, const QString ¶mValue); + void replaceValueInXSettingsdContents(QString &xSettingsdContents, const QString ¶mName, const QString ¶mValue); + + void reloadGtk2Apps(); + void reloadXSettingsd(); + + QString readFileContents(QFile >krc); + pid_t getPidOfXSettingsd(); +}; diff --git a/gtkconfig/kded/configeditor.cpp b/gtkconfig/kded/configeditor.cpp new file mode 100644 --- /dev/null +++ b/gtkconfig/kded/configeditor.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2019 Mikhail Zolotukhin + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#undef signals +#include +#include +#define signals Q_SIGNALS + +#include "configeditor.h" + +void ConfigEditor::setGtk3ConfigValueWayland(const QString ¶mName, const QString ¶mValue) +{ + gtk_init(nullptr, nullptr); + g_autoptr(GSettings) gsettings = g_settings_new("org.gnome.desktop.interface"); + g_settings_set_string(gsettings, paramName.toUtf8().constData(), paramValue.toUtf8().constData()); +} + +void ConfigEditor::setGtk3ConfigValueX11SettingsIni(const QString ¶mName, const QString ¶mValue) +{ + using qsp = QStandardPaths; + QString configLocation(qsp::writableLocation(qsp::GenericConfigLocation)); + QString gtk3ConfigPath(configLocation + "/gtk-3.0/settings.ini"); + + KSharedConfig::Ptr gtk3Config = KSharedConfig::openConfig(gtk3ConfigPath, KConfig::NoGlobals); + KConfigGroup group(gtk3Config, QStringLiteral("Settings")); + + group.writeEntry(paramName, paramValue); + group.sync(); +} + +void ConfigEditor::setGtk3ConfigValueX11XSettingsd(const QString ¶mName, const QString ¶mValue) +{ + using qsp = QStandardPaths; + QString configLocation(qsp::writableLocation(qsp::GenericConfigLocation)); + + QDir xsettingsdPath(configLocation + "/xsettingsd"); + if (!xsettingsdPath.exists()) { + xsettingsdPath.mkpath("."); + } + + QString xSettingsdConfigPath(xsettingsdPath.path() + "/xsettingsd.conf"); + + QFile xSettingsdConfig(xSettingsdConfigPath); + QString xSettingsdConfigContents(readFileContents(xSettingsdConfig)); + replaceValueInXSettingsdContents(xSettingsdConfigContents, paramName, paramValue); + xSettingsdConfig.remove(); + xSettingsdConfig.open(QIODevice::WriteOnly | QIODevice::Text); + xSettingsdConfig.write(xSettingsdConfigContents.toUtf8()); + reloadXSettingsd(); +} + +void ConfigEditor::setGtk2ConfigValue(const QString ¶mName, const QString ¶mValue) +{ + QString gtkrcPath(QDir::homePath() + "/.gtkrc-2.0"); + QFile gtkrc(gtkrcPath); + QString gtkrcContents(readFileContents(gtkrc)); + replaceValueInGtkrcContents(gtkrcContents, paramName, paramValue); + gtkrc.remove(); + gtkrc.open(QIODevice::WriteOnly | QIODevice::Text); + gtkrc.write(gtkrcContents.toUtf8()); + reloadGtk2Apps(); +} + +QString ConfigEditor::readFileContents(QFile &file) +{ + if (file.open(QIODevice::ReadWrite | QIODevice::Text)) { + return file.readAll(); + } else { + return ""; + } +} + + +void ConfigEditor::replaceValueInGtkrcContents(QString >krcContents, const QString ¶mName, const QString ¶mValue) +{ + QRegularExpression regExp(paramName + "=[^\n]*($|\n)"); + + static const QStringList nonStringProperties{ + QStringLiteral("gtk-toolbar-style"), + QStringLiteral("gtk-menu-images"), + QStringLiteral("gtk-button-images"), + QStringLiteral("gtk-primary-button-warps-slider"), + }; + + QString newConfigString; + if (nonStringProperties.contains(paramName)) { + newConfigString = paramName + "=" + paramValue + "\n"; + } else { + newConfigString = paramName + "=\"" + paramValue + "\"\n"; + } + + if (gtkrcContents.contains(regExp)) { + gtkrcContents.replace(regExp, newConfigString); + } else { + gtkrcContents = newConfigString + "\n" + gtkrcContents; + } +} + +void ConfigEditor::replaceValueInXSettingsdContents(QString &xSettingsdContents, const QString ¶mName, const QString ¶mValue) +{ + QRegularExpression regExp(paramName + " [^\n]*($|\n)"); + QString newConfigString(paramName + " \"" + paramValue + "\"\n"); + + if (xSettingsdContents.contains(regExp)) { + xSettingsdContents.replace(regExp, newConfigString); + } else { + xSettingsdContents = newConfigString + "\n" + xSettingsdContents; + } +} + +void ConfigEditor::reloadGtk2Apps() +{ + QProcess::startDetached(QStandardPaths::findExecutable(QStringLiteral("gtk2apps_reloader"))); +} + +void ConfigEditor::reloadXSettingsd() +{ + pid_t pidOfXSettingsd = getPidOfXSettingsd(); + if (pidOfXSettingsd == 0) { + QProcess::startDetached(QStandardPaths::findExecutable(QStringLiteral("xsettingsd"))); + } else { + kill(pidOfXSettingsd, SIGHUP); + } +} + +pid_t ConfigEditor::getPidOfXSettingsd() +{ + char line[512]; + FILE *cmd = popen("pidof -s xsettingsd", "r"); + fgets(line, 512, cmd); + pclose(cmd); + return std::atoi(line); +} diff --git a/gtkconfig/kded/gtkconfig.h b/gtkconfig/kded/gtkconfig.h new file mode 100644 --- /dev/null +++ b/gtkconfig/kded/gtkconfig.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 Mikhail Zolotukhin + * Copyright (C) 2019 Nicolas Fella + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include + +#include "configeditor.h" + +class Q_DECL_EXPORT GtkConfig : public KDEDModule +{ + Q_CLASSINFO("D-Bus Interface", "org.kde.gtkconfig") + Q_OBJECT + +public: + GtkConfig(QObject *parent, const QVariantList& args); + + void setFont(const QFont &font); + +private: + QString getConfigFontName(const QFont &font); + + + QScopedPointer configEditor; +}; diff --git a/gtkconfig/kded/gtkconfig.cpp b/gtkconfig/kded/gtkconfig.cpp new file mode 100644 --- /dev/null +++ b/gtkconfig/kded/gtkconfig.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 Mikhail Zolotukhin + * Copyright (C) 2019 Nicolas Fella + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gtkconfig.h" + +#include +#include +#include +#include + +#include + +K_PLUGIN_CLASS_WITH_JSON(GtkConfig, "gtkconfig.json") + +GtkConfig::GtkConfig(QObject *parent, const QVariantList&) : + KDEDModule(parent), configEditor(new ConfigEditor()) +{ + connect(qGuiApp, &QGuiApplication::fontChanged, this, &GtkConfig::setFont); +} + +void GtkConfig::setFont(const QFont &font) +{ + const QString configFontName(getConfigFontName(font)); + configEditor->setGtk2ConfigValue(QStringLiteral("gtk-font-name"), configFontName); + configEditor->setGtk3ConfigValueWayland(QStringLiteral("font-name"), configFontName); + configEditor->setGtk3ConfigValueX11SettingsIni(QStringLiteral("gtk-font-name"), configFontName); + configEditor->setGtk3ConfigValueX11XSettingsd(QStringLiteral("Gtk/FontName"), configFontName); +} + +QString GtkConfig::getConfigFontName(const QFont &font) +{ + return font.family() + + ' ' + font.styleName() + + ' ' + QString::number(font.pointSize()); +} + +#include "gtkconfig.moc" diff --git a/gtkconfig/kded/gtkconfig.json b/gtkconfig/kded/gtkconfig.json new file mode 100644 --- /dev/null +++ b/gtkconfig/kded/gtkconfig.json @@ -0,0 +1,15 @@ +{ + "KPlugin": { + "Description": "GTK config management", + "Icon": "preferences-system-power-management", + "Name": "Plasma GTKd", + "ServiceTypes": [ + "KDEDModule" + ], + "Version": "0.1" + }, + "X-KDE-Kded-autoload": true, + "X-KDE-Kded-load-on-demand": false, + "X-KDE-Kded-phase": 1 +} +