Compare commits

...

3 Commits

4 changed files with 107 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2011-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2011-2021 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Accessories */
/* All rights reserved.
*
@ -75,7 +75,7 @@ static int _usage(void);
/* callbacks */
static void _compare_on_changed(gpointer data);
static void _compare_on_close(gpointer data);
static gboolean _compare_on_closex(gpointer data);
static gboolean _compare_on_closex(GtkWidget * widget);
/* functions */
@ -91,8 +91,8 @@ static int _compare(char const * string1, char const * string2)
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window), 4);
gtk_window_set_title(GTK_WINDOW(window), _("Compare strings"));
g_signal_connect_swapped(G_OBJECT(window), "delete-event", G_CALLBACK(
_compare_on_closex), window);
g_signal_connect(window, "delete-event", G_CALLBACK(_compare_on_closex),
NULL);
#if GTK_CHECK_VERSION(3, 0, 0)
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
@ -135,7 +135,7 @@ static int _compare(char const * string1, char const * string2)
#if GTK_CHECK_VERSION(3, 10, 0)
widget = gtk_button_new_with_label(_("Close"));
gtk_button_set_image(GTK_BUTTON(widget),
gtk_image_new_from_icon_name(GTK_STOCK_CLOSE,
gtk_image_new_from_icon_name("gtk-close",
GTK_ICON_SIZE_BUTTON));
#else
widget = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
@ -145,8 +145,13 @@ static int _compare(char const * string1, char const * string2)
gtk_container_add(GTK_CONTAINER(bbox), widget);
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
#if GTK_CHECK_VERSION(4, 0, 0)
while(g_list_model_get_n_items(gtk_window_get_toplevels()) > 0)
g_main_context_iteration(NULL, TRUE);
#else
gtk_widget_show_all(window);
gtk_main();
#endif
return 0;
}
@ -203,18 +208,20 @@ static void _compare_on_close(gpointer data)
{
GtkWidget * widget = data;
gtk_widget_hide(widget);
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_window_destroy(GTK_WINDOW(widget));
#else
gtk_widget_destroy(widget);
gtk_main_quit();
#endif
}
/* compare_on_closex */
static gboolean _compare_on_closex(gpointer data)
static gboolean _compare_on_closex(GtkWidget * widget)
{
GtkWidget * widget = data;
_compare_on_close(widget);
return FALSE;
return TRUE;
}
@ -229,7 +236,11 @@ int main(int argc, char * argv[])
_error("setlocale", 1);
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_init();
#else
gtk_init(&argc, &argv);
#endif
while((o = getopt(argc, argv, "")) != -1)
switch(o)
{

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2006-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2006-2021 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Accessories */
/* All rights reserved.
*
@ -63,7 +63,7 @@ static int _usage(void);
/* functions */
/* fontsel */
static void _fontsel_on_close(gpointer data);
static gboolean _fontsel_on_closex(gpointer data);
static gboolean _fontsel_on_closex(GtkWidget * widget);
static int _fontsel(void)
{
@ -72,43 +72,70 @@ static int _fontsel(void)
GtkWidget * bbox;
GtkWidget * widget;
#if GTK_CHECK_VERSION(4, 0, 0)
window = gtk_window_new();
#else
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
#endif
gtk_window_set_title(GTK_WINDOW(window), _("Font browser"));
g_signal_connect_swapped(G_OBJECT(window), "delete-event", G_CALLBACK(
_fontsel_on_closex), window);
g_signal_connect(window, "delete-event", G_CALLBACK(_fontsel_on_closex),
NULL);
#if GTK_CHECK_VERSION(3, 0, 0)
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
vbox = gtk_vbox_new(FALSE, 4);
#endif
#if !GTK_CHECK_VERSION(4, 0, 0)
gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
#endif
#if GTK_CHECK_VERSION(3, 2, 0)
widget = gtk_font_chooser_widget_new();
#else
widget = gtk_font_selection_new();
#endif
gtk_container_add(GTK_CONTAINER(vbox), widget);
#if GTK_CHECK_VERSION(3, 0, 0)
bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_box_append(GTK_BOX(vbox), widget);
#else
bbox = gtk_hbutton_box_new();
gtk_container_add(GTK_CONTAINER(vbox), widget);
#endif
#if GTK_CHECK_VERSION(4, 0, 0)
bbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
#else
# if GTK_CHECK_VERSION(3, 0, 0)
bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
# else
bbox = gtk_hbutton_box_new();
# endif
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
#if GTK_CHECK_VERSION(3, 10, 0)
#endif
#if GTK_CHECK_VERSION(4, 0, 0)
widget = gtk_button_new_with_label(_("Close"));
#elif GTK_CHECK_VERSION(3, 10, 0)
widget = gtk_button_new_with_label(_("Close"));
gtk_button_set_image(GTK_BUTTON(widget),
gtk_image_new_from_icon_name(GTK_STOCK_CLOSE,
gtk_image_new_from_icon_name("gtk-close",
GTK_ICON_SIZE_BUTTON));
#else
widget = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
#endif
g_signal_connect_swapped(widget, "clicked", G_CALLBACK(
_fontsel_on_close), window);
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_box_append(GTK_BOX(bbox), widget);
gtk_box_append(GTK_BOX(vbox), bbox);
gtk_box_append(GTK_BOX(window), vbox);
#else
gtk_container_add(GTK_CONTAINER(bbox), widget);
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
#endif
#if GTK_CHECK_VERSION(4, 0, 0)
while(g_list_model_get_n_items(gtk_window_get_toplevels()) > 0)
g_main_context_iteration(NULL, TRUE);
#else
gtk_widget_show_all(window);
gtk_main();
#endif
return 0;
}
@ -116,16 +143,18 @@ static void _fontsel_on_close(gpointer data)
{
GtkWidget * widget = data;
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_window_destroy(GTK_WINDOW(widget));
#else
gtk_widget_hide(widget);
gtk_main_quit();
#endif
}
static gboolean _fontsel_on_closex(gpointer data)
static gboolean _fontsel_on_closex(GtkWidget * widget)
{
GtkWidget * widget = data;
_fontsel_on_close(widget);
return FALSE;
return TRUE;
}
@ -155,7 +184,11 @@ int main(int argc, char * argv[])
_error("setlocale", 1);
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_init();
#else
gtk_init(&argc, &argv);
#endif
while((o = getopt(argc, argv, "")) != -1)
switch(o)
{

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2007-2019 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2007-2021 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Accessories */
/* All rights reserved.
*
@ -42,7 +42,9 @@
#include <locale.h>
#include <libintl.h>
#include <gtk/gtk.h>
#if GTK_CHECK_VERSION(3, 0, 0)
#if GTK_CHECK_VERSION(4, 0, 0)
# include <gdk/x11/gdkx.h>
#elif GTK_CHECK_VERSION(3, 0, 0)
# include <gtk/gtkx.h>
#endif
#include "../config.h"
@ -184,7 +186,11 @@ static int _progress(Prefs * prefs, char * argv[])
/* graphical interface */
if((prefs->flags & PREFS_x) == 0)
{
#if GTK_CHECK_VERSION(4, 0, 0)
p.window = gtk_window_new();
#else
p.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
#endif
#if GTK_CHECK_VERSION(3, 0, 0) && !GTK_CHECK_VERSION(3, 14, 0)
gtk_window_set_has_resize_grip(GTK_WINDOW(p.window), FALSE);
#endif
@ -315,7 +321,11 @@ static int _progress(Prefs * prefs, char * argv[])
#else
hbox = gtk_hbox_new(FALSE, 0);
#endif
#if GTK_CHECK_VERSION(3, 10, 0)
#if GTK_CHECK_VERSION(4, 0, 0)
widget = gtk_button_new_with_label(_("Cancel"));
gtk_button_set_image(GTK_BUTTON(widget),
gtk_image_new_from_icon_name("gtk-cancel"));
#elif GTK_CHECK_VERSION(3, 10, 0)
widget = gtk_button_new_with_label(_("Cancel"));
gtk_button_set_image(GTK_BUTTON(widget),
gtk_image_new_from_icon_name(GTK_STOCK_CANCEL,
@ -340,7 +350,12 @@ static int _progress(Prefs * prefs, char * argv[])
printf("%lu\n", id);
fclose(stdout);
}
#if GTK_CHECK_VERSION(4, 0, 0)
while(g_list_model_get_n_items(gtk_window_get_toplevels()) > 0)
g_main_context_iteration(NULL, TRUE);
#else
gtk_main();
#endif
close(p.fd);
close(p.fds[1]);
return p.ret;
@ -387,7 +402,11 @@ static int _error_do(Progress * progress, char const * message,
"%s: %s", message, error);
gtk_window_set_title(GTK_WINDOW(dialog), _("Error"));
gtk_dialog_run(GTK_DIALOG(dialog));
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_window_destroy(GTK_WINDOW(dialog));
#else
gtk_widget_destroy(dialog);
#endif
return ret;
}
@ -734,7 +753,11 @@ int main(int argc, char * argv[])
_error("setlocale", 1);
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#if GTK_CHECK_VERSION(4, 0, 0)
gtk_init();
#else
gtk_init(&argc, &argv);
#endif
while((o = getopt(argc, argv, "b:ef:l:p:t:xz")) != -1)
switch(o)
{

View File

@ -25,6 +25,16 @@ cflags_force=`pkg-config --cflags libSystem gtk+-3.0` -fPIC
cflags=-W -Wall -O2 -D_FORTIFY_SOURCE=2 -fstack-protector
ldflags_force=`pkg-config --libs libSystem gtk+-3.0`
[mode::gtk4-debug]
cflags_force=`pkg-config --cflags libSystem gtk4` -fPIC
ldflags_force=`pkg-config --libs libSystem gtk4`
[mode::gtk4-release]
cppflags_force=-I ../include -DNDEBUG
cflags_force=`pkg-config --cflags libSystem gtk4` -fPIC
cflags=-W -Wall -O2 -D_FORTIFY_SOURCE=2 -fstack-protector
ldflags_force=`pkg-config --libs libSystem gtk4`
#targets
[compare]
type=binary
@ -48,6 +58,9 @@ sources=progress.c
#for Gtk+ 3
cflags=`pkg-config --cflags gtk+-x11-3.0`
ldflags=`pkg-config --cflags gtk+-x11-3.0`
#for Gtk+ 4
#cflags=`pkg-config --cflags gtk4-x11`
#ldflags=`pkg-config --cflags gtk4-x11`
install=$(BINDIR)
[progress.c]