From f59a6f539e4c00dba9d5f491451cad96014933b3 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 25 Nov 2013 18:57:59 +0100 Subject: [PATCH 1/3] Remove GTK+2 support Signed-off-by: Sebastian Ramacher --- config.c | 1 - page-widget.c | 53 +-------------------------------------------------- zathura.c | 25 ------------------------ zathura.h | 9 +-------- 4 files changed, 2 insertions(+), 86 deletions(-) diff --git a/config.c b/config.c index 33c1419..72b5100 100644 --- a/config.c +++ b/config.c @@ -15,7 +15,6 @@ #include #include #include -#include #include static void diff --git a/page-widget.c b/page-widget.c index 6f328bc..720fed9 100644 --- a/page-widget.c +++ b/page-widget.c @@ -61,9 +61,6 @@ typedef struct zathura_page_widget_private_s { zathura_page_widget_private_t)) static gboolean zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo); -#if GTK_MAJOR_VERSION == 2 -static gboolean zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event); -#endif static void zathura_page_widget_finalize(GObject* object); static void zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); static void zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec); @@ -111,11 +108,7 @@ zathura_page_widget_class_init(ZathuraPageClass* class) /* overwrite methods */ GtkWidgetClass* widget_class = GTK_WIDGET_CLASS(class); -#if GTK_MAJOR_VERSION == 2 - widget_class->expose_event = zathura_page_widget_expose; -#else widget_class->draw = zathura_page_widget_draw; -#endif widget_class->size_allocate = zathura_page_widget_size_allocate; widget_class->button_press_event = cb_zathura_page_widget_button_press_event; widget_class->button_release_event = cb_zathura_page_widget_button_release_event; @@ -368,43 +361,15 @@ zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value, } } -#if GTK_MAJOR_VERSION == 2 -static gboolean -zathura_page_widget_expose(GtkWidget* widget, GdkEventExpose* event) -{ - cairo_t* cairo = gdk_cairo_create(gtk_widget_get_window(widget)); - if (cairo == NULL) { - girara_error("Could not retrieve cairo object"); - return FALSE; - } - - /* set clip region */ - cairo_rectangle(cairo, event->area.x, event->area.y, event->area.width, event->area.height); - cairo_clip(cairo); - - const gboolean ret = zathura_page_widget_draw(widget, cairo); - cairo_destroy(cairo); - return ret; -} -#endif - static gboolean zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) { zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget); mutex_lock(&(priv->lock)); - zathura_document_t* document = zathura_page_get_document(priv->page); - -#if GTK_MAJOR_VERSION == 2 - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); - const unsigned int page_height = allocation.height; - const unsigned int page_width = allocation.width; -#else + zathura_document_t* document = zathura_page_get_document(priv->page); const unsigned int page_height = gtk_widget_get_allocated_height(widget); const unsigned int page_width = gtk_widget_get_allocated_width(widget); -#endif if (priv->surface != NULL) { cairo_save(cairo); @@ -620,11 +585,7 @@ redraw_rect(ZathuraPage* widget, zathura_rectangle_t* rectangle) grect.y = rectangle->y1; grect.width = (rectangle->x2 + 1) - rectangle->x1; grect.height = (rectangle->y2 + 1) - rectangle->y1; -#if GTK_MAJOR_VERSION == 2 - gdk_window_invalidate_rect(gtk_widget_get_window(GTK_WIDGET(widget)), &grect, TRUE); -#else gtk_widget_queue_draw_area(GTK_WIDGET(widget), grect.x, grect.y, grect.width, grect.height); -#endif } static void @@ -890,19 +851,7 @@ cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page) const int width = cairo_image_surface_get_width(surface); const int height = cairo_image_surface_get_height(surface); -#if GTK_MAJOR_VERSION == 2 - GdkPixmap* pixmap = gdk_pixmap_new(gtk_widget_get_window(GTK_WIDGET(item)), width, height, -1); - cairo_t* cairo = gdk_cairo_create(pixmap); - - cairo_set_source_surface(cairo, surface, 0, 0); - cairo_paint(cairo); - cairo_destroy(cairo); - - GdkPixbuf* pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL, 0, 0, 0, - 0, width, height); -#else GdkPixbuf* pixbuf = gdk_pixbuf_get_from_surface(surface, 0, 0, width, height); -#endif g_signal_emit(page, signals[IMAGE_SELECTED], 0, pixbuf); g_object_unref(pixbuf); cairo_surface_destroy(surface); diff --git a/zathura.c b/zathura.c index 2449698..55b72e5 100644 --- a/zathura.c +++ b/zathura.c @@ -146,13 +146,9 @@ zathura_init(zathura_t* zathura) G_CALLBACK(cb_refresh_view), zathura); /* page view */ -#if (GTK_MAJOR_VERSION == 3) zathura->ui.page_widget = gtk_grid_new(); gtk_grid_set_row_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE); gtk_grid_set_column_homogeneous(GTK_GRID(zathura->ui.page_widget), TRUE); -#else - zathura->ui.page_widget = gtk_table_new(0, 0, TRUE); -#endif if (zathura->ui.page_widget == NULL) { goto error_free; } @@ -184,13 +180,10 @@ zathura_init(zathura_t* zathura) } gtk_container_add(GTK_CONTAINER(zathura->ui.page_widget_alignment), zathura->ui.page_widget); -#if (GTK_MAJOR_VERSION == 3) gtk_widget_set_hexpand_set(zathura->ui.page_widget_alignment, TRUE); gtk_widget_set_hexpand(zathura->ui.page_widget_alignment, FALSE); gtk_widget_set_vexpand_set(zathura->ui.page_widget_alignment, TRUE); gtk_widget_set_vexpand(zathura->ui.page_widget_alignment, FALSE); -#endif - gtk_widget_show(zathura->ui.page_widget); @@ -325,11 +318,7 @@ zathura_free(zathura_t* zathura) } void -#if (GTK_MAJOR_VERSION == 2) -zathura_set_xid(zathura_t* zathura, GdkNativeWindow xid) -#else zathura_set_xid(zathura_t* zathura, Window xid) -#endif { g_return_if_fail(zathura != NULL); @@ -1060,30 +1049,16 @@ page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document); -#if (GTK_MAJOR_VERSION == 3) gtk_grid_set_row_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); gtk_grid_set_column_spacing(GTK_GRID(zathura->ui.page_widget), page_padding); -#else - gtk_table_set_row_spacings(GTK_TABLE(zathura->ui.page_widget), page_padding); - gtk_table_set_col_spacings(GTK_TABLE(zathura->ui.page_widget), page_padding); - - unsigned int ncol = pages_per_row; - unsigned int nrow = (number_of_pages + first_page_column - 1 + ncol - 1) / ncol; - gtk_table_resize(GTK_TABLE(zathura->ui.page_widget), nrow, ncol); -#endif - for (unsigned int i = 0; i < number_of_pages; i++) { int x = (i + first_page_column - 1) % pages_per_row; int y = (i + first_page_column - 1) / pages_per_row; zathura_page_t* page = zathura_document_get_page(zathura->document, i); GtkWidget* page_widget = zathura_page_get_widget(zathura, page); -#if (GTK_MAJOR_VERSION == 3) gtk_grid_attach(GTK_GRID(zathura->ui.page_widget), page_widget, x, y, 1, 1); -#else - gtk_table_attach(GTK_TABLE(zathura->ui.page_widget), page_widget, x, x + 1, y, y + 1, GTK_SHRINK, GTK_SHRINK, 0, 0); -#endif } gtk_widget_show_all(zathura->ui.page_widget); diff --git a/zathura.h b/zathura.h index 4b198ed..633e73f 100644 --- a/zathura.h +++ b/zathura.h @@ -6,13 +6,10 @@ #include #include #include +#include #include "macros.h" #include "types.h" -#if (GTK_MAJOR_VERSION == 3) -#include -#endif - enum { NEXT, PREVIOUS, LEFT, RIGHT, UP, DOWN, BOTTOM, TOP, HIDE, HIGHLIGHT, DELETE_LAST_WORD, DELETE_LAST_CHAR, DEFAULT, ERROR, WARNING, NEXT_GROUP, PREVIOUS_GROUP, ZOOM_IN, ZOOM_OUT, ZOOM_ORIGINAL, ZOOM_SPECIFIC, FORWARD, @@ -190,11 +187,7 @@ void zathura_free(zathura_t* zathura); * @param zathura The zathura session * @param xid The window id */ -#if (GTK_MAJOR_VERSION == 2) -void zathura_set_xid(zathura_t* zathura, GdkNativeWindow xid); -#else void zathura_set_xid(zathura_t* zathura, Window xid); -#endif /** * Set the path to the configuration directory From 80a54e70f8f78cd82af875a019c478d211527d7e Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 25 Nov 2013 18:59:02 +0100 Subject: [PATCH 2/3] Update README Signed-off-by: Sebastian Ramacher --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 111cdf2..04bf619 100644 --- a/README +++ b/README @@ -5,9 +5,9 @@ girara user interface library and several document libraries. Requirements ------------ -gtk2 (>= 2.18) or gtk3 +gtk3 glib (>= 2.28) -girara +girara (>= 0.1.8) sqlite3 (optional, >= 3.5.9) check (for tests) intltool From 0406cbe495ff13aaa7917f64f760b79286636283 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 25 Nov 2013 19:02:43 +0100 Subject: [PATCH 3/3] Drop compat code for glib < 2.28 Signed-off-by: Sebastian Ramacher --- glib-compat.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/glib-compat.h b/glib-compat.h index d13e59f..c76ccca 100644 --- a/glib-compat.h +++ b/glib-compat.h @@ -20,14 +20,4 @@ #define mutex_free(m) g_mutex_clear((m)) #endif -/* g_get_real_time appeared in 2.28 */ -#if !GLIB_CHECK_VERSION(2, 27, 0) -inline static gint64 g_get_real_time(void) -{ - GTimeVal tv; - g_get_current_time(&tv); - return (((gint64) tv.tv_sec) * 1000000) + tv.tv_usec; -} -#endif - #endif