From ae56df73c385e4994e1a748b79fcdc96ad5477d0 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 2 Feb 2020 17:36:49 +0800 Subject: [PATCH] Build against Gtk3 --- configure.ac | 2 +- src/bubblegen.c | 44 ++++++++++++++------------------------------ src/display_cow.c | 5 ++++- src/floating_shape.c | 7 +++---- src/floating_shape.h | 3 +-- 5 files changed, 23 insertions(+), 38 deletions(-) diff --git a/configure.ac b/configure.ac index 334884f..eec04a3 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ AC_CHECK_FUNCS([strtol setlocale strcasecmp strdup strchr \ getcwd strerror realpath]) # Check for pkg-config packages -modules="gtk+-2.0 gdk-pixbuf-2.0" +modules="gtk+-3.0 gdk-3.0" xcowsayd_modules="$modules dbus-glib-1 gthread-2.0" AC_ARG_ENABLE(dbus, [AS_HELP_STRING([--enable-dbus], [Build the DBus daemon.])], diff --git a/src/bubblegen.c b/src/bubblegen.c index da0c42f..6714d15 100644 --- a/src/bubblegen.c +++ b/src/bubblegen.c @@ -58,27 +58,12 @@ typedef struct { int width, height; - GdkPixmap *pixmap; + cairo_surface_t *surface; cairo_t *cr; } bubble_t; typedef enum { NORMAL, THOUGHT } bubble_style_t; -static void get_colour(guint16 r, guint16 g, guint16 b, GdkColor *c) -{ - GdkColormap *colormap; - gboolean ok; - - colormap = gdk_colormap_get_system(); - - c->red = r; - c->green = g; - c->blue = b; - - ok = gdk_colormap_alloc_color(colormap, c, FALSE, TRUE); - g_assert(ok); -} - static void bubble_corner_arcs(bubble_t *b, bubble_style_t style, int corners[4][2]) { @@ -115,14 +100,9 @@ static void bubble_corner_arcs(bubble_t *b, bubble_style_t style, static void bubble_init_cairo(bubble_t *b, cairo_t *cr, bubble_style_t style) { - GdkColor black, white, bright_green; GdkPoint tip_points[5]; bool right = !get_bool_option("left"); - get_colour(0, 0, 0, &black); - get_colour(0xffff, 0xffff, 0xffff, &white); - get_colour(0, 0xffff, 0, &bright_green); - cairo_set_source_rgb(cr, 0.0, 1.0, 0.0); cairo_rectangle(cr, 0, 0, b->width, b->height); cairo_fill(cr); @@ -300,11 +280,13 @@ static void bubble_init(bubble_t *b, bubble_style_t style) GdkVisual *root_visual; root_visual = gdk_visual_get_system(); - b->pixmap = gdk_pixmap_new(NULL, b->width, b->height, - gdk_visual_get_depth(root_visual)); - g_assert(b->pixmap); + //b->pixmap = gdk_pixmap_new(NULL, b->width, b->height, + // gdk_visual_get_depth(root_visual)); + b->surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, + b->width, b->height); + g_assert(b->surface); - b->cr = gdk_cairo_create(b->pixmap); + b->cr = cairo_create(b->surface); bubble_init_cairo(b, b->cr, style); } @@ -320,11 +302,13 @@ static void bubble_size_from_content(bubble_t *b, bubble_style_t style, static GdkPixbuf *bubble_tidy(bubble_t *b) { GdkPixbuf *pixbuf = - gdk_pixbuf_get_from_drawable(NULL, b->pixmap, NULL, - 0, 0, 0, 0, - b->width + BUBBLE_BORDER, - b->height + BUBBLE_BORDER); - g_object_unref(b->pixmap); + gdk_pixbuf_get_from_surface(b->surface, 0, 0, b->width + BUBBLE_BORDER, b->height + BUBBLE_BORDER); + + // gdk_pixbuf_get_from_drawable(NULL, b->pixmap, NULL, + // 0, 0, 0, 0, + // b->width + BUBBLE_BORDER, + // b->height + BUBBLE_BORDER); + cairo_surface_destroy(b->surface); return pixbuf; } diff --git a/src/display_cow.c b/src/display_cow.c index c8aa88f..28e322e 100644 --- a/src/display_cow.c +++ b/src/display_cow.c @@ -1,5 +1,5 @@ /* display_cow.c -- Display a cow in a popup window. - * Copyright (C) 2008-2010 Nick Gasson + * Copyright (C) 2008-2020 Nick Gasson * * 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 @@ -157,6 +157,9 @@ static gboolean tick(gpointer data) void cowsay_init(int *argc, char ***argv) { + // Window positioning doesn't work on Wayland + setenv("GDK_BACKEND", "x11", 1); + gtk_init(argc, argv); xcowsay.cow = NULL; diff --git a/src/floating_shape.c b/src/floating_shape.c index e163f40..7888526 100644 --- a/src/floating_shape.c +++ b/src/floating_shape.c @@ -1,5 +1,5 @@ /* floating_shape.c -- Low-ish level window creation and management. - * Copyright (C) 2008-2019 Nick Gasson + * Copyright (C) 2008-2020 Nick Gasson * * 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 @@ -112,6 +112,7 @@ float_shape_t *make_shape_from_pixbuf(GdkPixbuf *pixbuf) gtk_window_set_title(GTK_WINDOW(s->window), "shape"); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(s->window), TRUE); gtk_window_set_keep_above(GTK_WINDOW(s->window), TRUE); + gtk_window_set_resizable(GTK_WINDOW(s->window), FALSE); s->image = gtk_image_new_from_pixbuf(pixbuf); gtk_container_add(GTK_CONTAINER(s->window), s->image); @@ -127,11 +128,9 @@ float_shape_t *make_shape_from_pixbuf(GdkPixbuf *pixbuf) void show_shape(float_shape_t *shape) { - gtk_window_move(GTK_WINDOW(shape->window), shape->x, shape->y); gtk_window_resize(GTK_WINDOW(shape->window), shape->width, shape->height); + gtk_window_move(GTK_WINDOW(shape->window), shape->x, shape->y); gtk_widget_show_all(shape->window); - - gdk_window_set_back_pixmap(gtk_widget_get_window(shape->window), NULL, TRUE); } void hide_shape(float_shape_t *shape) diff --git a/src/floating_shape.h b/src/floating_shape.h index 7158ce3..fa2d033 100644 --- a/src/floating_shape.h +++ b/src/floating_shape.h @@ -1,5 +1,5 @@ /* floating_shape.h -- Low-ish level window creation and management. - * Copyright (C) 2008 Nick Gasson + * Copyright (C) 2008-2020 Nick Gasson * * 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 @@ -27,7 +27,6 @@ typedef struct { GtkWidget *window; GtkWidget *image; GdkPixbuf *pixbuf; - GdkDrawable *mask_bitmap; int x, y, width, height; } float_shape_t; -- 2.39.2