mirror of
https://github.com/jtheoof/swappy.git
synced 2024-08-16 18:20:45 +03:00
refactor(pixvuf): move pixbuf to separate file
This commit is contained in:
parent
ce42a0e5b6
commit
38b96e35f8
5
include/pixbuf.h
Normal file
5
include/pixbuf.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "swappy.h"
|
||||
|
||||
void pixbuf_save_to_file(struct swappy_state *state);
|
@ -57,6 +57,7 @@ executable(
|
||||
'src/clipboard.c',
|
||||
'src/file.c',
|
||||
'src/paint.c',
|
||||
'src/pixbuf.c',
|
||||
'src/render.c',
|
||||
'src/notification.c',
|
||||
'src/util.c',
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "file.h"
|
||||
#include "notification.h"
|
||||
#include "paint.h"
|
||||
#include "pixbuf.h"
|
||||
#include "render.h"
|
||||
#include "swappy.h"
|
||||
#include "wayland.h"
|
||||
@ -199,41 +200,8 @@ void application_finish(struct swappy_state *state) {
|
||||
config_free(state);
|
||||
}
|
||||
|
||||
static void action_save_area_to_file(struct swappy_state *state) {
|
||||
guint width = gtk_widget_get_allocated_width(state->ui->area);
|
||||
guint height = gtk_widget_get_allocated_height(state->ui->area);
|
||||
GdkPixbuf *pixbuf =
|
||||
gdk_pixbuf_get_from_surface(state->cairo_surface, 0, 0, width, height);
|
||||
GError *error = NULL;
|
||||
|
||||
time_t current_time;
|
||||
char *c_time_string;
|
||||
|
||||
time(¤t_time);
|
||||
|
||||
c_time_string = ctime(¤t_time);
|
||||
c_time_string[strlen(c_time_string) - 1] = '\0';
|
||||
char path[MAX_PATH];
|
||||
snprintf(path, MAX_PATH, "%s/%s %s.png", state->config->save_dir, "Swappshot",
|
||||
c_time_string);
|
||||
gdk_pixbuf_savev(pixbuf, path, "png", NULL, NULL, &error);
|
||||
|
||||
if (error != NULL) {
|
||||
g_critical("unable to save drawing area to pixbuf: %s", error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
char *msg = "Saved Swappshot to: ";
|
||||
size_t len = strlen(msg) + strlen(path) + 1;
|
||||
char *message = g_new(char, len);
|
||||
snprintf(message, len, "%s%s", msg, path);
|
||||
notification_send("Swappy", message);
|
||||
g_free(message);
|
||||
g_object_unref(pixbuf);
|
||||
}
|
||||
|
||||
void save_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
action_save_area_to_file(state);
|
||||
pixbuf_save_to_file(state);
|
||||
}
|
||||
|
||||
void clear_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
|
||||
@ -257,7 +225,7 @@ void window_keypress_handler(GtkWidget *widget, GdkEventKey *event,
|
||||
clipboard_copy_drawing_area_to_selection(state);
|
||||
break;
|
||||
case GDK_KEY_s:
|
||||
action_save_area_to_file(state);
|
||||
pixbuf_save_to_file(state);
|
||||
break;
|
||||
case GDK_KEY_b:
|
||||
action_toggle_painting_pane(state);
|
||||
|
36
src/pixbuf.c
Normal file
36
src/pixbuf.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include "pixbuf.h"
|
||||
|
||||
#include "notification.h"
|
||||
|
||||
void pixbuf_save_to_file(struct swappy_state *state) {
|
||||
guint width = gtk_widget_get_allocated_width(state->ui->area);
|
||||
guint height = gtk_widget_get_allocated_height(state->ui->area);
|
||||
GdkPixbuf *pixbuf =
|
||||
gdk_pixbuf_get_from_surface(state->cairo_surface, 0, 0, width, height);
|
||||
GError *error = NULL;
|
||||
|
||||
time_t current_time;
|
||||
char *c_time_string;
|
||||
|
||||
time(¤t_time);
|
||||
|
||||
c_time_string = ctime(¤t_time);
|
||||
c_time_string[strlen(c_time_string) - 1] = '\0';
|
||||
char path[MAX_PATH];
|
||||
snprintf(path, MAX_PATH, "%s/%s %s.png", state->config->save_dir, "Swappshot",
|
||||
c_time_string);
|
||||
gdk_pixbuf_savev(pixbuf, path, "png", NULL, NULL, &error);
|
||||
|
||||
if (error != NULL) {
|
||||
g_critical("unable to save drawing area to pixbuf: %s", error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
char *msg = "Saved Swappshot to: ";
|
||||
size_t len = strlen(msg) + strlen(path) + 1;
|
||||
char *message = g_new(char, len);
|
||||
snprintf(message, len, "%s%s", msg, path);
|
||||
notification_send("Swappy", message);
|
||||
g_free(message);
|
||||
g_object_unref(pixbuf);
|
||||
}
|
Loading…
Reference in New Issue
Block a user