Commit 88dc86e8 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

create a gtk3 preview program too

parent 0d0d8444
......@@ -43,4 +43,5 @@ install(FILES ${GHNS_FILES} DESTINATION ${CONFIG_INSTALL_DIR})
install(FILES kde-gtk-config.desktop DESTINATION ${SERVICES_INSTALL_DIR})
add_subdirectory(gtkproxies)
add_subdirectory(gtk3proxies)
add_subdirectory(icons)
# - 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})
#
# 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})
#
# 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} ${CAIRO_LIBRARY} ${GDKPIXBUF_LIBRARY} ${ATK_LIBRARY})
SET(GTK3_INCLUDE_DIRS ${GTK3_INCLUDE_DIR} ${GLIB2_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)
find_package(GTK3 REQUIRED)
include_directories(${GTK3_INCLUDE_DIRS})
add_definitions("-DDATA_DIR=\\\"${DATA_INSTALL_DIR}/kcm-gtk-module/\\\"")
add_executable(gtk3_preview preview3.c)
target_link_libraries(gtk3_preview ${GTK3_LIBRARY} ${GOBJECT2_LIBRARY} ${GLIB2_LIBRARY})
install(TARGETS gtk3_preview ${INSTALL_TARGETS_DEFAULT_ARGS})
/* Copyright 2011 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* 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 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/inotify.h>
int inotifyDescriptor;
static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
{
switch(res)
{
default:
gtk_main_quit();
}
}
void initializeInotify(gchar* target)
{
inotifyDescriptor = inotify_init();
if(inotifyDescriptor<0) {
perror("gtk-preview");
exit(123);
}
int r = inotify_add_watch (inotifyDescriptor, target, IN_CLOSE_WRITE);
if(r<0) {
perror("gtk-preview");
exit(124);
}
fprintf(stderr, "watching %s\n", target);
}
void reloadstyle(GIOChannel *source,
GIOCondition condition,
gpointer data)
{
fprintf(stderr, "changing settings...\n");
char buf[200];
ssize_t r = read(inotifyDescriptor, buf, 200);
gtk_rc_reparse_all();
fprintf(stderr, "settings changed!! %d\n", r);
}
int main(int argc, char **argv)
{
GError *error = NULL;
unsigned long wid=0;
if(argc==2)
sscanf(argv[1], "%ld", &wid);
/* fprintf(stderr, "holaaa %ld %s\n", argc, argv[1]);*/
gtk_init( &argc, &argv );
const char* ui_file = DATA_DIR "/preview.ui";
GtkBuilder *builder = gtk_builder_new();
if( ! gtk_builder_add_from_file( builder, ui_file, &error ) ) {
g_warning( "%s", error->message );
g_free( error );
return 1;
}
GtkWidget *previewUI = GTK_WIDGET( gtk_builder_get_object( builder, "frame1" ) );
gtk_builder_connect_signals( builder, NULL );
/* a plug when embedded, a window when a window */
GtkWidget* window;
if(wid==0) {
window = gtk_dialog_new();
gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG(window))), previewUI);
g_signal_connect(window, "response", G_CALLBACK(on_dlg_response), NULL);
} else {
window = gtk_plug_new(wid);
gtk_container_add (GTK_CONTAINER (window), previewUI);
}
GdkColor black = {0, 0, 0, 0};
gtk_widget_modify_bg(previewUI, GTK_STATE_NORMAL, &black);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed),
&window);
gtk_widget_show_all ( window );
g_object_unref( G_OBJECT( builder ) );
if(wid)
fprintf(stderr, "--- is embedded gtk3: %d\n", gtk_plug_get_embedded(GTK_PLUG(window)));
gchar** files = gtk_rc_get_default_files();
GIOChannel* channel = 0;
if(files) {
initializeInotify(files[0]);
channel = g_io_channel_unix_new(inotifyDescriptor);
guint ret = g_io_add_watch(channel, G_IO_IN, reloadstyle, NULL);
}
gtk_main();
g_io_channel_unref(channel);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment