Skip to content

Commit

Permalink
fix(pixbuf): properly grab pixbuf size from cairo surface
Browse files Browse the repository at this point in the history
This fixes the scaling issue when user would copy or save the file.

Commit `445980b` only solved the rendering part not the pixbuf part.

Closes #6
  • Loading branch information
jtheoof committed May 23, 2020
1 parent 445980b commit 2adcf94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/clipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <unistd.h>

#include "notification.h"
#include "pixbuf.h"
#include "util.h"

#define gtk_clipboard_t GtkClipboard
Expand Down Expand Up @@ -73,10 +74,7 @@ static void send_pixbuf_to_gdk_clipboard(gdk_pixbuf_t *pixbuf) {
}

bool clipboard_copy_drawing_area_to_selection(struct swappy_state *state) {
int width = gtk_widget_get_allocated_width(state->ui->area);
int height = gtk_widget_get_allocated_height(state->ui->area);
gdk_pixbuf_t *pixbuf =
gdk_pixbuf_get_from_surface(state->cairo_surface, 0, 0, width, height);
gdk_pixbuf_t *pixbuf = pixbuf_get_from_state(state);

// Try `wl-copy` first and fall back to gtk function. See README.md.
if (!send_pixbuf_to_wl_copy(pixbuf)) {
Expand Down
5 changes: 3 additions & 2 deletions src/pixbuf.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "pixbuf.h"

#include <cairo/cairo.h>
#include <gio/gunixoutputstream.h>

#include "notification.h"

GdkPixbuf *pixbuf_get_from_state(struct swappy_state *state) {
guint width = gtk_widget_get_allocated_width(state->ui->area);
guint height = gtk_widget_get_allocated_height(state->ui->area);
guint width = cairo_image_surface_get_width(state->cairo_surface);
guint height = cairo_image_surface_get_height(state->cairo_surface);
GdkPixbuf *pixbuf =
gdk_pixbuf_get_from_surface(state->cairo_surface, 0, 0, width, height);

Expand Down

0 comments on commit 2adcf94

Please sign in to comment.