Skip to content

Commit c5ec285

Browse files
committed
feat(ui): add keybindings for color change
1 parent 562a9a6 commit c5ec285

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

include/swappy.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ struct swappy_state_ui {
9393
GtkRadioButton *arrow;
9494

9595
GtkRadioButton *red;
96-
GtkColorButton *custom;
96+
GtkRadioButton *green;
97+
GtkRadioButton *blue;
98+
GtkRadioButton *custom;
99+
GtkColorButton *color;
97100

98101
GtkButton *stroke_size;
99102
};

res/swappy.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
<property name="image">edit-redo</property>
6767
<property name="always_show_image">True</property>
6868
<signal name="clicked" handler="redo_clicked_handler" swapped="no"/>
69-
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
7069
<accelerator key="y" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
70+
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
7171
</object>
7272
<packing>
7373
<property name="expand">True</property>
@@ -440,7 +440,7 @@
440440
<property name="margin_left">12</property>
441441
<property name="spacing">5</property>
442442
<child>
443-
<object class="GtkRadioButton" id="color-button-custom">
443+
<object class="GtkRadioButton" id="color-custom-button">
444444
<property name="visible">True</property>
445445
<property name="can_focus">True</property>
446446
<property name="receives_default">True</property>

src/application.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ static void action_update_color_state(struct swappy_state *state, double r,
7272
state->painting.b = b;
7373
state->painting.a = a;
7474

75-
gtk_widget_set_sensitive(GTK_WIDGET(state->ui->custom), custom);
75+
gtk_widget_set_sensitive(GTK_WIDGET(state->ui->color), custom);
7676
}
7777

7878
static void action_set_color_from_custom(struct swappy_state *state) {
7979
GdkRGBA color;
80-
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(state->ui->custom), &color);
80+
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(state->ui->color), &color);
8181

8282
action_update_color_state(state, color.red, color.green, color.blue,
8383
color.alpha, true);
@@ -272,6 +272,23 @@ void window_keypress_handler(GtkWidget *widget, GdkEventKey *event,
272272
case GDK_KEY_k:
273273
action_clear(state);
274274
break;
275+
case GDK_KEY_R:
276+
action_update_color_state(state, 1, 0, 0, 1, false);
277+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->red), true);
278+
break;
279+
case GDK_KEY_G:
280+
action_update_color_state(state, 0, 1, 0, 1, false);
281+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->green), true);
282+
break;
283+
case GDK_KEY_B:
284+
action_update_color_state(state, 0, 0, 1, 1, false);
285+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->blue), true);
286+
break;
287+
case GDK_KEY_C:
288+
action_set_color_from_custom(state);
289+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(state->ui->custom),
290+
true);
291+
break;
275292
case GDK_KEY_minus:
276293
action_stroke_size_decrease(state);
277294
break;
@@ -474,7 +491,13 @@ static bool load_layout(struct swappy_state *state) {
474491

475492
state->ui->red =
476493
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-red-button"));
494+
state->ui->green =
495+
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-green-button"));
496+
state->ui->blue =
497+
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-blue-button"));
477498
state->ui->custom =
499+
GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "color-custom-button"));
500+
state->ui->color =
478501
GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "custom-color-button"));
479502

480503
state->ui->stroke_size =

0 commit comments

Comments
 (0)