-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(config): add quit_on_copy config #134
Conversation
Thanks for your contribution @SeppeSoete. A few things to consider:
|
39f8f7d
to
602be09
Compare
@jtheoof Thanks for your response! I've made some changes in response to your comment.
I have now changed the commit message and as far as I know it should now conform to the conventional commits standard.
Good catch, those have been added now.
The reason I wanted this behaviour is because it is the default behaviour for at least some screenshot utilities like for example flameshot, which is the utility I used before making the switch to wayland. For me it was actually counter intuitive that the application remained running after copying to the clipboard and I thought the application was bugged until I noticed it had in fact copied the image to my clipboard. |
All right let me think about it and try out flameshot. Thanks for the quick feedback. |
After putting more thoughts into it, I'm not against the idea, but I think it should a go a step further. Making it close swappy on save as well.
What do you think? |
cce9aad
to
2c1187d
Compare
I ended up calling it quit_after_export since I felt like that was most representative.
done & tested
and done |
Thanks for the update. I've still got some comments:
|
The early_exit function should gracefully exit now after freeing everything, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there.
README.md
Outdated
@@ -49,6 +49,7 @@ line_size=5 | |||
text_size=20 | |||
text_font=sans-serif | |||
paint_mode=brush | |||
quit_after_export=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quit_after_export=false | |
early_exit=false |
src/application.c
Outdated
config_free(state); | ||
} | ||
|
||
static void early_exit(struct swappy_state *state){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this function. It's actually a bit misleading from the function calling this because it doesn't always exit the app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling gtk_main_quit
will exit the main loop and call application_finish
in main.c
src/application.c
Outdated
@@ -191,6 +221,8 @@ static void save_state_to_file_or_folder(struct swappy_state *state, | |||
} | |||
|
|||
g_object_unref(pixbuf); | |||
|
|||
early_exit(state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
early_exit(state); | |
if (state->config->early_exit) { | |
gtk_main_quit(); | |
} |
src/application.c
Outdated
@@ -290,6 +300,7 @@ void copy_clicked_handler(GtkWidget *widget, struct swappy_state *state) { | |||
// Commit a potential paint (e.g. text being written) | |||
commit_state(state); | |||
clipboard_copy_drawing_area_to_selection(state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the same logic inside clipboard_copy_drawing_area_to_selection
.
i.e:
clipboard_copy_drawing_area_to_selection(state); | |
if (state->config->early_exit) { | |
gtk_main_quit(); | |
} |
src/application.c
Outdated
@@ -319,6 +330,7 @@ void window_keypress_handler(GtkWidget *widget, GdkEventKey *event, | |||
switch (event->keyval) { | |||
case GDK_KEY_c: | |||
clipboard_copy_drawing_area_to_selection(state); | |||
early_exit(state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to put the logic inside clipboard_copy_drawing_area_to_selection
From 30c04cf08bc2be2b4e949fcef68d979614aefe28 Mon Sep 17 00:00:00 2001
From: Jeremy Attali <contact@jtheoof.me>
Date: Tue, 2 Aug 2022 20:48:48 -0400
Subject: [PATCH] feat(config): fix early_exit
---
src/application.c | 15 ++++-----------
src/clipboard.c | 4 ++++
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/src/application.c b/src/application.c
index 86d35e8..8a6c2f7 100644
--- a/src/application.c
+++ b/src/application.c
@@ -46,6 +46,7 @@ static void update_ui_panel_toggle_button(struct swappy_state *state) {
}
void application_finish(struct swappy_state *state) {
+ g_debug("application finishing, cleaning up");
paint_free_all(state);
pixbuf_free(state);
cairo_surface_destroy(state->rendering_surface);
@@ -67,14 +68,6 @@ void application_finish(struct swappy_state *state) {
config_free(state);
}
-static void early_exit(struct swappy_state *state){
- // Exit the application if early_exit configuration is enabled
- if (state->config->early_exit){
- application_finish(state);
- gtk_main_quit();
- }
-}
-
static void action_undo(struct swappy_state *state) {
GList *first = state->paints;
@@ -222,7 +215,9 @@ static void save_state_to_file_or_folder(struct swappy_state *state,
g_object_unref(pixbuf);
- early_exit(state);
+ if (state->config->early_exit) {
+ gtk_main_quit();
+ }
}
static void maybe_save_output_file(struct swappy_state *state) {
@@ -300,7 +295,6 @@ void copy_clicked_handler(GtkWidget *widget, struct swappy_state *state) {
// Commit a potential paint (e.g. text being written)
commit_state(state);
clipboard_copy_drawing_area_to_selection(state);
- early_exit(state);
}
void control_modifier_changed(bool pressed, struct swappy_state *state) {
@@ -330,7 +324,6 @@ void window_keypress_handler(GtkWidget *widget, GdkEventKey *event,
switch (event->keyval) {
case GDK_KEY_c:
clipboard_copy_drawing_area_to_selection(state);
- early_exit(state);
break;
case GDK_KEY_s:
save_state_to_file_or_folder(state, NULL);
diff --git a/src/clipboard.c b/src/clipboard.c
index 188c33c..dd03dd9 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -82,5 +82,9 @@ bool clipboard_copy_drawing_area_to_selection(struct swappy_state *state) {
g_object_unref(pixbuf);
+ if (state->config->early_exit) {
+ gtk_main_quit();
+ }
+
return true;
}
--
2.37.1 |
Please apply the above patch and squash all commit into one: Thanks. |
ad3ce5b
to
27d611f
Compare
I ran clang-format -i on all the files in /include/ and /src/, no changes made though but that was after applying your patch so the format issue was already gone. |
Thanks for your contribution ! |
if the quit_on_copy config option is set to true, the application now exits after copying the selection to the keyboard