From 57377d8dc29d590ad9c1edca61edf64d92f5a3a8 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Tue, 5 Nov 2024 07:26:57 +0100 Subject: [PATCH 1/2] feat(ui): add transparency feature It is sometimes better if the drawing is not fully covering the picture but is semi-transparent. This patch adds a simple button to enable transparency. When this button is enabled, everything will be drawn with 50% alpha channel. --- include/config.h | 1 + include/swappy.h | 2 ++ res/swappy.glade | 17 +++++++++++++++++ src/application.c | 34 ++++++++++++++++++++++++++++++++++ src/config.c | 13 +++++++++++++ src/pixbuf.c | 3 +-- src/po/de.po | 22 +++++++++++++++------- src/po/en.po | 22 +++++++++++++++------- src/po/fr.po | 22 +++++++++++++++------- src/po/pt_BR.po | 22 +++++++++++++++------- src/po/swappy.pot | 22 +++++++++++++++------- src/po/tr.po | 22 +++++++++++++++------- swappy.1.scd | 3 +++ 13 files changed, 161 insertions(+), 44 deletions(-) diff --git a/include/config.h b/include/config.h index 470962a..b08cc9e 100644 --- a/include/config.h +++ b/include/config.h @@ -10,6 +10,7 @@ #define CONFIG_FILL_SHAPE_DEFAULT false #define CONFIG_AUTO_SAVE_DEFAULT false #define CONFIG_CUSTOM_COLOR_DEFAULT "rgba(193,125,17,1)" +#define CONFIG_TRANSPARENT_DEFAULT false void config_load(struct swappy_state *state); void config_free(struct swappy_state *state); diff --git a/include/swappy.h b/include/swappy.h index cf9d87e..e0d7f50 100644 --- a/include/swappy.h +++ b/include/swappy.h @@ -139,6 +139,7 @@ struct swappy_state_ui { GtkButton *text_size; GtkToggleButton *fill_shape; + GtkToggleButton *transparent; }; struct swappy_config { @@ -147,6 +148,7 @@ struct swappy_config { char *save_filename_format; gint8 paint_mode; gboolean fill_shape; + gboolean transparent; gboolean show_panel; guint32 line_size; guint32 text_size; diff --git a/res/swappy.glade b/res/swappy.glade index 259d617..2da7fb0 100644 --- a/res/swappy.glade +++ b/res/swappy.glade @@ -604,6 +604,23 @@ 1 + + + Transparent + True + False + False + True + Toggle transparency + True + + + + False + True + 2 + + False diff --git a/src/application.c b/src/application.c index 5b98590..fb73d31 100644 --- a/src/application.c +++ b/src/application.c @@ -52,6 +52,13 @@ static void update_ui_fill_shape_toggle_button(struct swappy_state *state) { gtk_toggle_button_set_active(button, toggled); } +static void update_ui_transparent_toggle_button(struct swappy_state *state) { + GtkToggleButton *button = GTK_TOGGLE_BUTTON(state->ui->transparent); + gboolean toggled = state->config->transparent; + + gtk_toggle_button_set_active(button, toggled); +} + void application_finish(struct swappy_state *state) { g_debug("application finishing, cleaning up"); paint_free_all(state); @@ -119,6 +126,7 @@ static void action_update_color_state(struct swappy_state *state, double r, state->settings.g = g; state->settings.b = b; state->settings.a = a; + if (state->config->transparent) state->settings.a *= 0.5; gtk_widget_set_sensitive(GTK_WIDGET(state->ui->color), custom); } @@ -227,6 +235,19 @@ static void action_fill_shape_toggle(struct swappy_state *state, update_ui_fill_shape_toggle_button(state); } +static void action_transparent_toggle(struct swappy_state *state, + gboolean *toggled) { + gboolean toggle = (toggled == NULL) ? !state->config->transparent : *toggled; + state->config->transparent = toggle; + + if (toggle) + state->settings.a *= 0.5; + else + state->settings.a *= 2; + + update_ui_transparent_toggle_button(state); +} + static void save_state_to_file_or_folder(struct swappy_state *state, char *file) { GdkPixbuf *pixbuf = pixbuf_get_from_state(state); @@ -437,6 +458,9 @@ void window_keypress_handler(GtkWidget *widget, GdkEventKey *event, case GDK_KEY_f: action_fill_shape_toggle(state, NULL); break; + case GDK_KEY_T: + action_transparent_toggle(state, NULL); + break; default: break; } @@ -647,6 +671,13 @@ void fill_shape_toggled_handler(GtkWidget *widget, struct swappy_state *state) { action_fill_shape_toggle(state, &toggled); } +void transparent_toggled_handler(GtkWidget *widget, + struct swappy_state *state) { + GtkToggleButton *button = GTK_TOGGLE_BUTTON(widget); + gboolean toggled = gtk_toggle_button_get_active(button); + action_transparent_toggle(state, &toggled); +} + static void compute_window_size_and_scaling_factor(struct swappy_state *state) { GdkRectangle workarea = {0}; GdkDisplay *display = gdk_display_get_default(); @@ -789,6 +820,8 @@ static bool load_layout(struct swappy_state *state) { gdk_rgba_parse(&color, state->config->custom_color); gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(state->ui->color), &color); + state->ui->transparent = GTK_TOGGLE_BUTTON( + gtk_builder_get_object(builder, "transparent-toggle-button")); state->ui->brush = brush; state->ui->text = text; @@ -862,6 +895,7 @@ static bool init_gtk_window(struct swappy_state *state) { update_ui_undo_redo(state); update_ui_panel_toggle_button(state); update_ui_fill_shape_toggle_button(state); + update_ui_transparent_toggle_button(state); return true; } diff --git a/src/config.c b/src/config.c index f44ab00..7b303fb 100644 --- a/src/config.c +++ b/src/config.c @@ -24,6 +24,7 @@ static void print_config(struct swappy_config *config) { g_info("fill_shape: %d", config->fill_shape); g_info("auto_save: %d", config->auto_save); g_info("custom_color: %s", config->custom_color); + g_info("transparent: %d", config->transparent); } static char *get_default_save_dir() { @@ -85,6 +86,7 @@ static void load_config_from_file(struct swappy_config *config, gboolean fill_shape; gboolean auto_save; gchar *custom_color = NULL; + gboolean transparent; GError *error = NULL; if (file == NULL) { @@ -256,6 +258,16 @@ static void load_config_from_file(struct swappy_config *config, error = NULL; } + transparent = g_key_file_get_boolean(gkf, group, "transparent", &error); + + if (error == NULL) { + config->transparent = transparent; + } else { + g_info("transparent is missing in %s (%s)", file, error->message); + g_error_free(error); + error = NULL; + } + g_key_file_free(gkf); } @@ -275,6 +287,7 @@ static void load_default_config(struct swappy_config *config) { config->fill_shape = CONFIG_FILL_SHAPE_DEFAULT; config->auto_save = CONFIG_AUTO_SAVE_DEFAULT; config->custom_color = g_strdup(CONFIG_CUSTOM_COLOR_DEFAULT); + config->transparent = CONFIG_TRANSPARENT_DEFAULT; } void config_load(struct swappy_state *state) { diff --git a/src/pixbuf.c b/src/pixbuf.c index 8a63671..a0f98c0 100644 --- a/src/pixbuf.c +++ b/src/pixbuf.c @@ -93,8 +93,7 @@ void pixbuf_scale_surface_from_widget(struct swappy_state *state, GdkPixbuf *image = state->original_image; gtk_widget_get_allocation(widget, alloc); - gboolean has_alpha = gdk_pixbuf_get_has_alpha(image); - cairo_format_t format = has_alpha ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24; + cairo_format_t format = CAIRO_FORMAT_ARGB32; gint image_width = gdk_pixbuf_get_width(image); gint image_height = gdk_pixbuf_get_height(image); diff --git a/src/po/de.po b/src/po/de.po index b3e4439..5c4edf9 100644 --- a/src/po/de.po +++ b/src/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-18 16:07-0500\n" +"POT-Creation-Date: 2024-02-24 18:32+0100\n" "PO-Revision-Date: 2020-11-19 18:03+0300\n" "Last-Translator: Brodi \n" "Language-Team: none\n" @@ -33,26 +33,34 @@ msgstr "" msgid "Toggle shape filling" msgstr "" -#: res/swappy.glade:671 +#: res/swappy.glade:609 +msgid "Transparent" +msgstr "" + +#: res/swappy.glade:614 +msgid "Toggle transparency" +msgstr "" + +#: res/swappy.glade:688 msgid "Toggle Paint Panel" msgstr "Farbtafel umschalten" -#: res/swappy.glade:697 +#: res/swappy.glade:714 msgid "Undo Last Paint" msgstr "Letzte Bemalung rückgängig machen" -#: res/swappy.glade:716 +#: res/swappy.glade:733 msgid "Redo Previous Paint" msgstr "Vorherige Bemalung wiederherstellen" -#: res/swappy.glade:735 +#: res/swappy.glade:752 msgid "Clear Paints" msgstr "Bemalung löschen" -#: res/swappy.glade:763 +#: res/swappy.glade:780 msgid "Copy Surface" msgstr "Fläche kopieren" -#: res/swappy.glade:779 +#: res/swappy.glade:796 msgid "Save Surface" msgstr "Fläche speichern" diff --git a/src/po/en.po b/src/po/en.po index cf01b19..762dcea 100644 --- a/src/po/en.po +++ b/src/po/en.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-18 16:07-0500\n" +"POT-Creation-Date: 2024-02-24 18:32+0100\n" "PO-Revision-Date: 2020-06-21 21:57-0400\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -33,26 +33,34 @@ msgstr "Fill shape" msgid "Toggle shape filling" msgstr "Toggle shape filling" -#: res/swappy.glade:671 +#: res/swappy.glade:609 +msgid "Transparent" +msgstr "" + +#: res/swappy.glade:614 +msgid "Toggle transparency" +msgstr "" + +#: res/swappy.glade:688 msgid "Toggle Paint Panel" msgstr "Toggle Paint Panel" -#: res/swappy.glade:697 +#: res/swappy.glade:714 msgid "Undo Last Paint" msgstr "Undo Last Paint" -#: res/swappy.glade:716 +#: res/swappy.glade:733 msgid "Redo Previous Paint" msgstr "Redo Previous Paint" -#: res/swappy.glade:735 +#: res/swappy.glade:752 msgid "Clear Paints" msgstr "Clear Paints" -#: res/swappy.glade:763 +#: res/swappy.glade:780 msgid "Copy Surface" msgstr "Copy Surface" -#: res/swappy.glade:779 +#: res/swappy.glade:796 msgid "Save Surface" msgstr "Save Surface" diff --git a/src/po/fr.po b/src/po/fr.po index 21aa351..830321f 100644 --- a/src/po/fr.po +++ b/src/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-18 16:07-0500\n" +"POT-Creation-Date: 2024-02-24 18:32+0100\n" "PO-Revision-Date: 2021-02-20 21:00-0500\n" "Last-Translator: Jeremy Attali \n" "Language-Team: none\n" @@ -33,26 +33,34 @@ msgstr "Remplir la forme" msgid "Toggle shape filling" msgstr "Activer/Désactiver le remplissage de forme" -#: res/swappy.glade:671 +#: res/swappy.glade:609 +msgid "Transparent" +msgstr "" + +#: res/swappy.glade:614 +msgid "Toggle transparency" +msgstr "" + +#: res/swappy.glade:688 msgid "Toggle Paint Panel" msgstr "Afficher/Cacher le panneau de peinture" -#: res/swappy.glade:697 +#: res/swappy.glade:714 msgid "Undo Last Paint" msgstr "Annuler la dernière peinture" -#: res/swappy.glade:716 +#: res/swappy.glade:733 msgid "Redo Previous Paint" msgstr "Rétablir la dernière peinture" -#: res/swappy.glade:735 +#: res/swappy.glade:752 msgid "Clear Paints" msgstr "Supprimer les peintures" -#: res/swappy.glade:763 +#: res/swappy.glade:780 msgid "Copy Surface" msgstr "Copier la surface" -#: res/swappy.glade:779 +#: res/swappy.glade:796 msgid "Save Surface" msgstr "Sauvegarder la surface" diff --git a/src/po/pt_BR.po b/src/po/pt_BR.po index ec68154..c2a26c7 100644 --- a/src/po/pt_BR.po +++ b/src/po/pt_BR.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-18 16:07-0500\n" +"POT-Creation-Date: 2024-02-24 18:32+0100\n" "PO-Revision-Date: 2021-02-14 20:38-0300\n" "Last-Translator: Gustavo Costa \n" "Language-Team: \n" @@ -34,26 +34,34 @@ msgstr "" msgid "Toggle shape filling" msgstr "" -#: res/swappy.glade:671 +#: res/swappy.glade:609 +msgid "Transparent" +msgstr "" + +#: res/swappy.glade:614 +msgid "Toggle transparency" +msgstr "" + +#: res/swappy.glade:688 msgid "Toggle Paint Panel" msgstr "Alternar painel de pintura" -#: res/swappy.glade:697 +#: res/swappy.glade:714 msgid "Undo Last Paint" msgstr "Desfazer última pintura" -#: res/swappy.glade:716 +#: res/swappy.glade:733 msgid "Redo Previous Paint" msgstr "Refazer pintura anterior" -#: res/swappy.glade:735 +#: res/swappy.glade:752 msgid "Clear Paints" msgstr "Limpar pinturas" -#: res/swappy.glade:763 +#: res/swappy.glade:780 msgid "Copy Surface" msgstr "Copiar superfície" -#: res/swappy.glade:779 +#: res/swappy.glade:796 msgid "Save Surface" msgstr "Salvar superfície" diff --git a/src/po/swappy.pot b/src/po/swappy.pot index 30f6b4d..568488e 100644 --- a/src/po/swappy.pot +++ b/src/po/swappy.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-18 16:07-0500\n" +"POT-Creation-Date: 2024-02-24 18:32+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -33,26 +33,34 @@ msgstr "" msgid "Toggle shape filling" msgstr "" -#: res/swappy.glade:671 +#: res/swappy.glade:609 +msgid "Transparent" +msgstr "" + +#: res/swappy.glade:614 +msgid "Toggle transparency" +msgstr "" + +#: res/swappy.glade:688 msgid "Toggle Paint Panel" msgstr "" -#: res/swappy.glade:697 +#: res/swappy.glade:714 msgid "Undo Last Paint" msgstr "" -#: res/swappy.glade:716 +#: res/swappy.glade:733 msgid "Redo Previous Paint" msgstr "" -#: res/swappy.glade:735 +#: res/swappy.glade:752 msgid "Clear Paints" msgstr "" -#: res/swappy.glade:763 +#: res/swappy.glade:780 msgid "Copy Surface" msgstr "" -#: res/swappy.glade:779 +#: res/swappy.glade:796 msgid "Save Surface" msgstr "" diff --git a/src/po/tr.po b/src/po/tr.po index bcc74a1..3cafab3 100644 --- a/src/po/tr.po +++ b/src/po/tr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-18 16:07-0500\n" +"POT-Creation-Date: 2024-02-24 18:32+0100\n" "PO-Revision-Date: 2022-11-25 10:36+0300\n" "Last-Translator: Oğuz Ersen \n" "Language-Team: Turkish \n" @@ -33,26 +33,34 @@ msgstr "Şekli Doldur" msgid "Toggle shape filling" msgstr "Şekil Doldurmayı Aç/Kapat" -#: res/swappy.glade:671 +#: res/swappy.glade:609 +msgid "Transparent" +msgstr "" + +#: res/swappy.glade:614 +msgid "Toggle transparency" +msgstr "" + +#: res/swappy.glade:688 msgid "Toggle Paint Panel" msgstr "Boyama Panelini Aç/Kapat" -#: res/swappy.glade:697 +#: res/swappy.glade:714 msgid "Undo Last Paint" msgstr "Son Boyamayı Geri Al" -#: res/swappy.glade:716 +#: res/swappy.glade:733 msgid "Redo Previous Paint" msgstr "Önceki Boyamayı Tekrarla" -#: res/swappy.glade:735 +#: res/swappy.glade:752 msgid "Clear Paints" msgstr "Boyamaları Temizle" -#: res/swappy.glade:763 +#: res/swappy.glade:780 msgid "Copy Surface" msgstr "Yüzeyi Kopyala" -#: res/swappy.glade:779 +#: res/swappy.glade:796 msgid "Save Surface" msgstr "Yüzeyi Kaydet" diff --git a/swappy.1.scd b/swappy.1.scd index 6452d41..ad2ff6d 100644 --- a/swappy.1.scd +++ b/swappy.1.scd @@ -68,6 +68,7 @@ The following lines can be used as swappy's default: fill_shape=false auto_save=false custom_color=rgba(192,125,17,1) + transparent=false ``` - *save_dir* is where swappshots will be saved, can contain env variables, when it does not exist, swappy attempts to create it first, but does not abort if directory creation fails @@ -82,6 +83,7 @@ The following lines can be used as swappy's default: - *auto_save* is used to toggle auto saving of final buffer to *save_dir* upon exit - *custom_color* is used to set a default value for the custom color. Accepted formats are: standard name (one of: https://github.com/rgb-x/system/blob/master/root/etc/X11/rgb.txt), #rgb, #rrggbb, #rrrgggbbb, #rrrrggggbbbb, rgb(r,b,g), rgba(r,g,b,a) +- *transparent* is used to toggle transparency (50% oppacity of everything that is drawn) during startup # KEY BINDINGS @@ -107,6 +109,7 @@ formats are: standard name (one of: https://github.com/rgb-x/system/blob/master/ - *Plus*: Increase Stroke Size - *Equal*: Reset Stroke Size - *f*: Toggle Shape Filling +- *T*: Toggle Transparency - *k*: Clear Paints (cannot be undone) ## MODIFIERS From f2b703cff5e5548bbe2c0ee5bc309320d4d654e3 Mon Sep 17 00:00:00 2001 From: Krzysztof Adamski Date: Wed, 6 Nov 2024 21:24:45 +0100 Subject: [PATCH 2/2] feat(ui): make transparency configurable This commit adds UI elements and config option for configuring the transparency value. The default value is 50% but it can be changed in the 5% - 95% range in 10% steps. --- include/application.h | 6 ++++ include/config.h | 1 + include/swappy.h | 8 +++++ res/swappy.glade | 77 ++++++++++++++++++++++++++++++++++++++++++- src/application.c | 69 ++++++++++++++++++++++++++++++++++---- src/config.c | 20 +++++++++++ src/paint.c | 2 ++ src/po/de.po | 30 +++++++++-------- src/po/en.po | 30 +++++++++-------- src/po/fr.po | 30 +++++++++-------- src/po/pt_BR.po | 30 +++++++++-------- src/po/swappy.pot | 30 +++++++++-------- src/po/tr.po | 30 +++++++++-------- src/po/zh_CN.po | 35 +++++++++++++------- swappy.1.scd | 4 ++- 15 files changed, 304 insertions(+), 98 deletions(-) diff --git a/include/application.h b/include/application.h index ba84a8d..112c050 100644 --- a/include/application.h +++ b/include/application.h @@ -57,3 +57,9 @@ void stroke_size_increase_handler(GtkWidget *widget, void text_size_decrease_handler(GtkWidget *widget, struct swappy_state *state); void text_size_reset_handler(GtkWidget *widget, struct swappy_state *state); void text_size_increase_handler(GtkWidget *widget, struct swappy_state *state); + +void transparency_decrease_handler(GtkWidget *widget, + struct swappy_state *state); +void transparency_reset_handler(GtkWidget *widget, struct swappy_state *state); +void transparency_increase_handler(GtkWidget *widget, + struct swappy_state *state); diff --git a/include/config.h b/include/config.h index b08cc9e..0703afc 100644 --- a/include/config.h +++ b/include/config.h @@ -3,6 +3,7 @@ #define CONFIG_LINE_SIZE_DEFAULT 5 #define CONFIG_TEXT_FONT_DEFAULT "sans-serif" #define CONFIG_TEXT_SIZE_DEFAULT 20 +#define CONFIG_TRANSPARENCY_DEFAULT 50 #define CONFIG_SHOW_PANEL_DEFAULT false #define CONFIG_SAVE_FILENAME_FORMAT_DEFAULT "swappy-%Y%m%d_%H%M%S.png" #define CONFIG_PAINT_MODE_DEFAULT SWAPPY_PAINT_MODE_BRUSH diff --git a/include/swappy.h b/include/swappy.h index e0d7f50..6e86556 100644 --- a/include/swappy.h +++ b/include/swappy.h @@ -14,6 +14,9 @@ #define SWAPPY_TEXT_SIZE_MIN 10 #define SWAPPY_TEXT_SIZE_MAX 50 +#define SWAPPY_TRANSPARENCY_MIN 5 +#define SWAPPY_TRANSPARENCY_MAX 95 + enum swappy_paint_type { SWAPPY_PAINT_MODE_BRUSH = 0, /* Brush mode to draw arbitrary shapes */ SWAPPY_PAINT_MODE_TEXT, /* Mode to draw texts */ @@ -106,6 +109,7 @@ struct swappy_state_settings { double a; double w; double t; + int32_t tr; }; struct swappy_state_ui { @@ -137,6 +141,9 @@ struct swappy_state_ui { GtkButton *line_size; GtkButton *text_size; + GtkButton *transparency; + GtkButton *transparency_plus; + GtkButton *transparency_minus; GtkToggleButton *fill_shape; GtkToggleButton *transparent; @@ -152,6 +159,7 @@ struct swappy_config { gboolean show_panel; guint32 line_size; guint32 text_size; + guint32 transparency; char *text_font; gboolean early_exit; gboolean auto_save; diff --git a/res/swappy.glade b/res/swappy.glade index 2da7fb0..e12a14f 100644 --- a/res/swappy.glade +++ b/res/swappy.glade @@ -57,6 +57,11 @@ False zoom-out-symbolic + + True + False + zoom-out-symbolic + True False @@ -582,6 +587,76 @@ 4 + + + True + False + 10 + 2 + True + + + True + False + Transparency + + + False + True + 0 + + + + + True + True + True + zoom-out2 + True + + + + False + False + 1 + + + + + True + True + True + True + + + + False + True + 2 + + + + + True + True + True + zoom-in2 + True + + + + False + False + 3 + + + + + False + True + 5 + + True @@ -625,7 +700,7 @@ False True - 5 + 6 diff --git a/src/application.c b/src/application.c index fb73d31..de20d8a 100644 --- a/src/application.c +++ b/src/application.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,13 @@ static void update_ui_text_size_widget(struct swappy_state *state) { gtk_button_set_label(button, label); } +static void update_ui_transparency_widget(struct swappy_state *state) { + GtkButton *button = GTK_BUTTON(state->ui->transparency); + char label[255]; + g_snprintf(label, 255, "%" PRId32, state->settings.tr); + gtk_button_set_label(button, label); +} + static void update_ui_panel_toggle_button(struct swappy_state *state) { GtkWidget *painting_box = GTK_WIDGET(state->ui->painting_box); GtkToggleButton *button = GTK_TOGGLE_BUTTON(state->ui->panel_toggle_button); @@ -57,6 +65,9 @@ static void update_ui_transparent_toggle_button(struct swappy_state *state) { gboolean toggled = state->config->transparent; gtk_toggle_button_set_active(button, toggled); + gtk_widget_set_sensitive(GTK_WIDGET(state->ui->transparency), toggled); + gtk_widget_set_sensitive(GTK_WIDGET(state->ui->transparency_minus), toggled); + gtk_widget_set_sensitive(GTK_WIDGET(state->ui->transparency_plus), toggled); } void application_finish(struct swappy_state *state) { @@ -126,7 +137,6 @@ static void action_update_color_state(struct swappy_state *state, double r, state->settings.g = g; state->settings.b = b; state->settings.a = a; - if (state->config->transparent) state->settings.a *= 0.5; gtk_widget_set_sensitive(GTK_WIDGET(state->ui->color), custom); } @@ -223,6 +233,38 @@ static void action_text_size_increase(struct swappy_state *state) { update_ui_text_size_widget(state); } +static void action_transparency_decrease(struct swappy_state *state) { + state->settings.tr -= 10; + + if (state->settings.tr < SWAPPY_TRANSPARENCY_MIN) { + state->settings.tr = SWAPPY_TRANSPARENCY_MIN; + } else { + // ceil to 10 + state->settings.tr += 5; + state->settings.tr /= 10; + state->settings.tr *= 10; + } + + update_ui_transparency_widget(state); +} +static void action_transparency_reset(struct swappy_state *state) { + state->settings.tr = state->config->transparency; + update_ui_transparency_widget(state); +} +static void action_transparency_increase(struct swappy_state *state) { + state->settings.tr += 10; + + if (state->settings.tr > SWAPPY_TRANSPARENCY_MAX) { + state->settings.tr = SWAPPY_TRANSPARENCY_MAX; + } else { + // floor to 10 + state->settings.tr /= 10; + state->settings.tr *= 10; + } + + update_ui_transparency_widget(state); +} + static void action_fill_shape_toggle(struct swappy_state *state, gboolean *toggled) { // Don't allow changing the state via a shortcut if the button can't be @@ -240,11 +282,6 @@ static void action_transparent_toggle(struct swappy_state *state, gboolean toggle = (toggled == NULL) ? !state->config->transparent : *toggled; state->config->transparent = toggle; - if (toggle) - state->settings.a *= 0.5; - else - state->settings.a *= 2; - update_ui_transparent_toggle_button(state); } @@ -665,6 +702,18 @@ void text_size_increase_handler(GtkWidget *widget, struct swappy_state *state) { action_text_size_increase(state); } +void transparency_decrease_handler(GtkWidget *widget, + struct swappy_state *state) { + action_transparency_decrease(state); +} +void transparency_reset_handler(GtkWidget *widget, struct swappy_state *state) { + action_transparency_reset(state); +} +void transparency_increase_handler(GtkWidget *widget, + struct swappy_state *state) { + action_transparency_increase(state); +} + void fill_shape_toggled_handler(GtkWidget *widget, struct swappy_state *state) { GtkToggleButton *button = GTK_TOGGLE_BUTTON(widget); gboolean toggled = gtk_toggle_button_get_active(button); @@ -814,6 +863,12 @@ static bool load_layout(struct swappy_state *state) { GTK_BUTTON(gtk_builder_get_object(builder, "stroke-size-button")); state->ui->text_size = GTK_BUTTON(gtk_builder_get_object(builder, "text-size-button")); + state->ui->transparency = + GTK_BUTTON(gtk_builder_get_object(builder, "transparency-button")); + state->ui->transparency_plus = + GTK_BUTTON(gtk_builder_get_object(builder, "transparency-plus-button")); + state->ui->transparency_minus = + GTK_BUTTON(gtk_builder_get_object(builder, "transparency-minus-button")); state->ui->fill_shape = GTK_TOGGLE_BUTTON( gtk_builder_get_object(builder, "fill-shape-toggle-button")); @@ -892,6 +947,7 @@ static bool init_gtk_window(struct swappy_state *state) { update_ui_stroke_size_widget(state); update_ui_text_size_widget(state); + update_ui_transparency_widget(state); update_ui_undo_redo(state); update_ui_panel_toggle_button(state); update_ui_fill_shape_toggle_button(state); @@ -915,6 +971,7 @@ static void init_settings(struct swappy_state *state) { state->settings.a = 1; state->settings.w = state->config->line_size; state->settings.t = state->config->text_size; + state->settings.tr = state->config->transparency; state->mode = state->config->paint_mode; } diff --git a/src/config.c b/src/config.c index 7b303fb..a5cc3fa 100644 --- a/src/config.c +++ b/src/config.c @@ -19,6 +19,7 @@ static void print_config(struct swappy_config *config) { g_info("line_size: %d", config->line_size); g_info("text_font: %s", config->text_font); g_info("text_size: %d", config->text_size); + g_info("transparency: %d", config->transparency); g_info("paint_mode: %d", config->paint_mode); g_info("early_exit: %d", config->early_exit); g_info("fill_shape: %d", config->fill_shape); @@ -80,6 +81,7 @@ static void load_config_from_file(struct swappy_config *config, gboolean show_panel; gchar *save_dir_expanded = NULL; guint64 line_size, text_size; + guint64 transparency; gchar *text_font = NULL; gchar *paint_mode = NULL; gboolean early_exit; @@ -182,6 +184,23 @@ static void load_config_from_file(struct swappy_config *config, error = NULL; } + transparency = g_key_file_get_uint64(gkf, group, "transparency", &error); + + if (error == NULL) { + if (transparency >= SWAPPY_TRANSPARENCY_MIN && + transparency <= SWAPPY_TRANSPARENCY_MAX) { + config->transparency = transparency; + } else { + g_warning("transparency is not a valid value: %" PRIu64 + " - see man page for details", + transparency); + } + } else { + g_info("transparency is missing in %s (%s)", file, error->message); + g_error_free(error); + error = NULL; + } + show_panel = g_key_file_get_boolean(gkf, group, "show_panel", &error); if (error == NULL) { @@ -288,6 +307,7 @@ static void load_default_config(struct swappy_config *config) { config->auto_save = CONFIG_AUTO_SAVE_DEFAULT; config->custom_color = g_strdup(CONFIG_CUSTOM_COLOR_DEFAULT); config->transparent = CONFIG_TRANSPARENT_DEFAULT; + config->transparency = CONFIG_TRANSPARENCY_DEFAULT; } void config_load(struct swappy_state *state) { diff --git a/src/paint.c b/src/paint.c index 142297a..36ea463 100644 --- a/src/paint.c +++ b/src/paint.c @@ -68,6 +68,8 @@ void paint_add_temporary(struct swappy_state *state, double x, double y, double w = state->settings.w; double t = state->settings.t; + if (state->config->transparent) a *= (1 - state->settings.tr / 100.0); + paint->type = type; paint->is_committed = false; diff --git a/src/po/de.po b/src/po/de.po index 5c4edf9..e3cb16f 100644 --- a/src/po/de.po +++ b/src/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-24 18:32+0100\n" +"POT-Creation-Date: 2024-11-06 23:00+0100\n" "PO-Revision-Date: 2020-11-19 18:03+0300\n" "Last-Translator: Brodi \n" "Language-Team: none\n" @@ -17,50 +17,54 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: res/swappy.glade:456 +#: res/swappy.glade:461 msgid "Line Width" msgstr "Linienstärke" -#: res/swappy.glade:526 +#: res/swappy.glade:531 msgid "Text Size" msgstr "Textgröße" -#: res/swappy.glade:592 +#: res/swappy.glade:601 +msgid "Transparency" +msgstr "" + +#: res/swappy.glade:667 msgid "Fill shape" msgstr "" -#: res/swappy.glade:597 +#: res/swappy.glade:672 msgid "Toggle shape filling" msgstr "" -#: res/swappy.glade:609 +#: res/swappy.glade:684 msgid "Transparent" msgstr "" -#: res/swappy.glade:614 +#: res/swappy.glade:689 msgid "Toggle transparency" msgstr "" -#: res/swappy.glade:688 +#: res/swappy.glade:763 msgid "Toggle Paint Panel" msgstr "Farbtafel umschalten" -#: res/swappy.glade:714 +#: res/swappy.glade:789 msgid "Undo Last Paint" msgstr "Letzte Bemalung rückgängig machen" -#: res/swappy.glade:733 +#: res/swappy.glade:808 msgid "Redo Previous Paint" msgstr "Vorherige Bemalung wiederherstellen" -#: res/swappy.glade:752 +#: res/swappy.glade:827 msgid "Clear Paints" msgstr "Bemalung löschen" -#: res/swappy.glade:780 +#: res/swappy.glade:855 msgid "Copy Surface" msgstr "Fläche kopieren" -#: res/swappy.glade:796 +#: res/swappy.glade:871 msgid "Save Surface" msgstr "Fläche speichern" diff --git a/src/po/en.po b/src/po/en.po index 762dcea..b6cf59e 100644 --- a/src/po/en.po +++ b/src/po/en.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-24 18:32+0100\n" +"POT-Creation-Date: 2024-11-06 23:00+0100\n" "PO-Revision-Date: 2020-06-21 21:57-0400\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -17,50 +17,54 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: res/swappy.glade:456 +#: res/swappy.glade:461 msgid "Line Width" msgstr "Line Width" -#: res/swappy.glade:526 +#: res/swappy.glade:531 msgid "Text Size" msgstr "Text Size" -#: res/swappy.glade:592 +#: res/swappy.glade:601 +msgid "Transparency" +msgstr "" + +#: res/swappy.glade:667 msgid "Fill shape" msgstr "Fill shape" -#: res/swappy.glade:597 +#: res/swappy.glade:672 msgid "Toggle shape filling" msgstr "Toggle shape filling" -#: res/swappy.glade:609 +#: res/swappy.glade:684 msgid "Transparent" msgstr "" -#: res/swappy.glade:614 +#: res/swappy.glade:689 msgid "Toggle transparency" msgstr "" -#: res/swappy.glade:688 +#: res/swappy.glade:763 msgid "Toggle Paint Panel" msgstr "Toggle Paint Panel" -#: res/swappy.glade:714 +#: res/swappy.glade:789 msgid "Undo Last Paint" msgstr "Undo Last Paint" -#: res/swappy.glade:733 +#: res/swappy.glade:808 msgid "Redo Previous Paint" msgstr "Redo Previous Paint" -#: res/swappy.glade:752 +#: res/swappy.glade:827 msgid "Clear Paints" msgstr "Clear Paints" -#: res/swappy.glade:780 +#: res/swappy.glade:855 msgid "Copy Surface" msgstr "Copy Surface" -#: res/swappy.glade:796 +#: res/swappy.glade:871 msgid "Save Surface" msgstr "Save Surface" diff --git a/src/po/fr.po b/src/po/fr.po index 830321f..1179679 100644 --- a/src/po/fr.po +++ b/src/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-24 18:32+0100\n" +"POT-Creation-Date: 2024-11-06 23:00+0100\n" "PO-Revision-Date: 2021-02-20 21:00-0500\n" "Last-Translator: Jeremy Attali \n" "Language-Team: none\n" @@ -17,50 +17,54 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: res/swappy.glade:456 +#: res/swappy.glade:461 msgid "Line Width" msgstr "Epaisseur de ligne" -#: res/swappy.glade:526 +#: res/swappy.glade:531 msgid "Text Size" msgstr "Taille du texte" -#: res/swappy.glade:592 +#: res/swappy.glade:601 +msgid "Transparency" +msgstr "" + +#: res/swappy.glade:667 msgid "Fill shape" msgstr "Remplir la forme" -#: res/swappy.glade:597 +#: res/swappy.glade:672 msgid "Toggle shape filling" msgstr "Activer/Désactiver le remplissage de forme" -#: res/swappy.glade:609 +#: res/swappy.glade:684 msgid "Transparent" msgstr "" -#: res/swappy.glade:614 +#: res/swappy.glade:689 msgid "Toggle transparency" msgstr "" -#: res/swappy.glade:688 +#: res/swappy.glade:763 msgid "Toggle Paint Panel" msgstr "Afficher/Cacher le panneau de peinture" -#: res/swappy.glade:714 +#: res/swappy.glade:789 msgid "Undo Last Paint" msgstr "Annuler la dernière peinture" -#: res/swappy.glade:733 +#: res/swappy.glade:808 msgid "Redo Previous Paint" msgstr "Rétablir la dernière peinture" -#: res/swappy.glade:752 +#: res/swappy.glade:827 msgid "Clear Paints" msgstr "Supprimer les peintures" -#: res/swappy.glade:780 +#: res/swappy.glade:855 msgid "Copy Surface" msgstr "Copier la surface" -#: res/swappy.glade:796 +#: res/swappy.glade:871 msgid "Save Surface" msgstr "Sauvegarder la surface" diff --git a/src/po/pt_BR.po b/src/po/pt_BR.po index c2a26c7..99d29d6 100644 --- a/src/po/pt_BR.po +++ b/src/po/pt_BR.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-24 18:32+0100\n" +"POT-Creation-Date: 2024-11-06 23:00+0100\n" "PO-Revision-Date: 2021-02-14 20:38-0300\n" "Last-Translator: Gustavo Costa \n" "Language-Team: \n" @@ -18,50 +18,54 @@ msgstr "" "X-Generator: Poedit 2.4.2\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: res/swappy.glade:456 +#: res/swappy.glade:461 msgid "Line Width" msgstr "Espessura da linha" -#: res/swappy.glade:526 +#: res/swappy.glade:531 msgid "Text Size" msgstr "Tamanho do texto" -#: res/swappy.glade:592 +#: res/swappy.glade:601 +msgid "Transparency" +msgstr "" + +#: res/swappy.glade:667 msgid "Fill shape" msgstr "" -#: res/swappy.glade:597 +#: res/swappy.glade:672 msgid "Toggle shape filling" msgstr "" -#: res/swappy.glade:609 +#: res/swappy.glade:684 msgid "Transparent" msgstr "" -#: res/swappy.glade:614 +#: res/swappy.glade:689 msgid "Toggle transparency" msgstr "" -#: res/swappy.glade:688 +#: res/swappy.glade:763 msgid "Toggle Paint Panel" msgstr "Alternar painel de pintura" -#: res/swappy.glade:714 +#: res/swappy.glade:789 msgid "Undo Last Paint" msgstr "Desfazer última pintura" -#: res/swappy.glade:733 +#: res/swappy.glade:808 msgid "Redo Previous Paint" msgstr "Refazer pintura anterior" -#: res/swappy.glade:752 +#: res/swappy.glade:827 msgid "Clear Paints" msgstr "Limpar pinturas" -#: res/swappy.glade:780 +#: res/swappy.glade:855 msgid "Copy Surface" msgstr "Copiar superfície" -#: res/swappy.glade:796 +#: res/swappy.glade:871 msgid "Save Surface" msgstr "Salvar superfície" diff --git a/src/po/swappy.pot b/src/po/swappy.pot index 568488e..3e256b1 100644 --- a/src/po/swappy.pot +++ b/src/po/swappy.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-24 18:32+0100\n" +"POT-Creation-Date: 2024-11-06 23:00+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,50 +17,54 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: res/swappy.glade:456 +#: res/swappy.glade:461 msgid "Line Width" msgstr "" -#: res/swappy.glade:526 +#: res/swappy.glade:531 msgid "Text Size" msgstr "" -#: res/swappy.glade:592 +#: res/swappy.glade:601 +msgid "Transparency" +msgstr "" + +#: res/swappy.glade:667 msgid "Fill shape" msgstr "" -#: res/swappy.glade:597 +#: res/swappy.glade:672 msgid "Toggle shape filling" msgstr "" -#: res/swappy.glade:609 +#: res/swappy.glade:684 msgid "Transparent" msgstr "" -#: res/swappy.glade:614 +#: res/swappy.glade:689 msgid "Toggle transparency" msgstr "" -#: res/swappy.glade:688 +#: res/swappy.glade:763 msgid "Toggle Paint Panel" msgstr "" -#: res/swappy.glade:714 +#: res/swappy.glade:789 msgid "Undo Last Paint" msgstr "" -#: res/swappy.glade:733 +#: res/swappy.glade:808 msgid "Redo Previous Paint" msgstr "" -#: res/swappy.glade:752 +#: res/swappy.glade:827 msgid "Clear Paints" msgstr "" -#: res/swappy.glade:780 +#: res/swappy.glade:855 msgid "Copy Surface" msgstr "" -#: res/swappy.glade:796 +#: res/swappy.glade:871 msgid "Save Surface" msgstr "" diff --git a/src/po/tr.po b/src/po/tr.po index 3cafab3..a258bfe 100644 --- a/src/po/tr.po +++ b/src/po/tr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-24 18:32+0100\n" +"POT-Creation-Date: 2024-11-06 23:00+0100\n" "PO-Revision-Date: 2022-11-25 10:36+0300\n" "Last-Translator: Oğuz Ersen \n" "Language-Team: Turkish \n" @@ -17,50 +17,54 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: res/swappy.glade:456 +#: res/swappy.glade:461 msgid "Line Width" msgstr "Çizgi Genişliği" -#: res/swappy.glade:526 +#: res/swappy.glade:531 msgid "Text Size" msgstr "Metin Boyutu" -#: res/swappy.glade:592 +#: res/swappy.glade:601 +msgid "Transparency" +msgstr "" + +#: res/swappy.glade:667 msgid "Fill shape" msgstr "Şekli Doldur" -#: res/swappy.glade:597 +#: res/swappy.glade:672 msgid "Toggle shape filling" msgstr "Şekil Doldurmayı Aç/Kapat" -#: res/swappy.glade:609 +#: res/swappy.glade:684 msgid "Transparent" msgstr "" -#: res/swappy.glade:614 +#: res/swappy.glade:689 msgid "Toggle transparency" msgstr "" -#: res/swappy.glade:688 +#: res/swappy.glade:763 msgid "Toggle Paint Panel" msgstr "Boyama Panelini Aç/Kapat" -#: res/swappy.glade:714 +#: res/swappy.glade:789 msgid "Undo Last Paint" msgstr "Son Boyamayı Geri Al" -#: res/swappy.glade:733 +#: res/swappy.glade:808 msgid "Redo Previous Paint" msgstr "Önceki Boyamayı Tekrarla" -#: res/swappy.glade:752 +#: res/swappy.glade:827 msgid "Clear Paints" msgstr "Boyamaları Temizle" -#: res/swappy.glade:780 +#: res/swappy.glade:855 msgid "Copy Surface" msgstr "Yüzeyi Kopyala" -#: res/swappy.glade:796 +#: res/swappy.glade:871 msgid "Save Surface" msgstr "Yüzeyi Kaydet" diff --git a/src/po/zh_CN.po b/src/po/zh_CN.po index 03f8865..3115369 100644 --- a/src/po/zh_CN.po +++ b/src/po/zh_CN.po @@ -1,4 +1,3 @@ - # English translations for swappy package. # Copyright (C) 2020 THE swappy'S COPYRIGHT HOLDER # This file is distributed under the same license as the swappy package. @@ -8,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: swappy\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-18 16:07-0500\n" +"POT-Creation-Date: 2024-11-06 23:00+0100\n" "PO-Revision-Date: 2020-06-21 21:57-0400\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -18,42 +17,54 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -#: res/swappy.glade:456 +#: res/swappy.glade:461 msgid "Line Width" msgstr "行宽" -#: res/swappy.glade:526 +#: res/swappy.glade:531 msgid "Text Size" msgstr "文本大小" -#: res/swappy.glade:592 +#: res/swappy.glade:601 +msgid "Transparency" +msgstr "" + +#: res/swappy.glade:667 msgid "Fill shape" msgstr "填充" -#: res/swappy.glade:597 +#: res/swappy.glade:672 msgid "Toggle shape filling" msgstr "切换填充状态" -#: res/swappy.glade:671 +#: res/swappy.glade:684 +msgid "Transparent" +msgstr "" + +#: res/swappy.glade:689 +msgid "Toggle transparency" +msgstr "" + +#: res/swappy.glade:763 msgid "Toggle Paint Panel" msgstr "切换绘图板状态" -#: res/swappy.glade:697 +#: res/swappy.glade:789 msgid "Undo Last Paint" msgstr "撤销" -#: res/swappy.glade:716 +#: res/swappy.glade:808 msgid "Redo Previous Paint" msgstr "恢复" -#: res/swappy.glade:735 +#: res/swappy.glade:827 msgid "Clear Paints" msgstr "清除绘图" -#: res/swappy.glade:763 +#: res/swappy.glade:855 msgid "Copy Surface" msgstr "复制" -#: res/swappy.glade:779 +#: res/swappy.glade:871 msgid "Save Surface" msgstr "保存" diff --git a/swappy.1.scd b/swappy.1.scd index ad2ff6d..62cb13f 100644 --- a/swappy.1.scd +++ b/swappy.1.scd @@ -69,6 +69,7 @@ The following lines can be used as swappy's default: auto_save=false custom_color=rgba(192,125,17,1) transparent=false + transparency=50 ``` - *save_dir* is where swappshots will be saved, can contain env variables, when it does not exist, swappy attempts to create it first, but does not abort if directory creation fails @@ -83,7 +84,8 @@ The following lines can be used as swappy's default: - *auto_save* is used to toggle auto saving of final buffer to *save_dir* upon exit - *custom_color* is used to set a default value for the custom color. Accepted formats are: standard name (one of: https://github.com/rgb-x/system/blob/master/root/etc/X11/rgb.txt), #rgb, #rrggbb, #rrrgggbbb, #rrrrggggbbbb, rgb(r,b,g), rgba(r,g,b,a) -- *transparent* is used to toggle transparency (50% oppacity of everything that is drawn) during startup +- *transparency* is used to set transparency of everything that is drawn during startup +- *transparent* is used to toggle transparency during startup # KEY BINDINGS