Add a mode keeping pressed to light
This commit is contained in:
parent
ee8b80f8b0
commit
333a228529
|
@ -46,12 +46,16 @@ struct _Flashlight
|
||||||
/* image */
|
/* image */
|
||||||
GtkWidget * image;
|
GtkWidget * image;
|
||||||
/* controls */
|
/* controls */
|
||||||
GtkWidget * co_main;
|
gboolean control;
|
||||||
|
GtkWidget * co_press;
|
||||||
|
GtkWidget * co_toggle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
|
static gboolean _flashlight_on_button_pressed(gpointer data);
|
||||||
|
static gboolean _flashlight_on_button_released(gpointer data);
|
||||||
static void _flashlight_on_toggled(gpointer data);
|
static void _flashlight_on_toggled(gpointer data);
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,20 +84,33 @@ Flashlight * flashlight_new(GtkOrientation orientation)
|
||||||
TRUE, 0);
|
TRUE, 0);
|
||||||
/* controls */
|
/* controls */
|
||||||
widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
|
widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
|
||||||
|
/* press switch */
|
||||||
|
flashlight->co_press = gtk_button_new_with_mnemonic(_("_Press"));
|
||||||
|
g_signal_connect_swapped(flashlight->co_press, "button-press-event",
|
||||||
|
G_CALLBACK(_flashlight_on_button_pressed), flashlight);
|
||||||
|
g_signal_connect_swapped(flashlight->co_press, "button-release-event",
|
||||||
|
G_CALLBACK(_flashlight_on_button_released), flashlight);
|
||||||
|
gtk_widget_set_no_show_all(flashlight->co_press, TRUE);
|
||||||
|
gtk_box_pack_start(GTK_BOX(widget), flashlight->co_press, TRUE, TRUE,
|
||||||
|
0);
|
||||||
|
/* toggle switch */
|
||||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||||
flashlight->co_main = gtk_switch_new();
|
flashlight->co_toggle = gtk_switch_new();
|
||||||
g_signal_connect_swapped(flashlight->co_main, "notify::active",
|
g_signal_connect_swapped(flashlight->co_toggle, "notify::active",
|
||||||
G_CALLBACK(_flashlight_on_toggled), flashlight);
|
G_CALLBACK(_flashlight_on_toggled), flashlight);
|
||||||
#else
|
#else
|
||||||
# warning Switch widget is not available (needs Gtk+ >= 3.0)
|
# warning Switch widget is not available (needs Gtk+ >= 3.0)
|
||||||
flashlight->co_main = gtk_toggle_button_new_with_mnemonic(
|
flashlight->co_toggle = gtk_toggle_button_new_with_mnemonic(
|
||||||
_("_Switch"));
|
_("_Switch"));
|
||||||
g_signal_connect_swapped(flashlight->co_main, "toggled", G_CALLBACK(
|
g_signal_connect_swapped(flashlight->co_toggle, "toggled", G_CALLBACK(
|
||||||
_flashlight_on_toggled), flashlight);
|
_flashlight_on_toggled), flashlight);
|
||||||
#endif
|
#endif
|
||||||
gtk_box_pack_start(GTK_BOX(widget), flashlight->co_main, TRUE, TRUE, 0);
|
gtk_widget_set_no_show_all(flashlight->co_toggle, TRUE);
|
||||||
|
gtk_box_pack_start(GTK_BOX(widget), flashlight->co_toggle, TRUE, TRUE,
|
||||||
|
0);
|
||||||
gtk_box_pack_start(GTK_BOX(flashlight->box), widget, FALSE, TRUE, 0);
|
gtk_box_pack_start(GTK_BOX(flashlight->box), widget, FALSE, TRUE, 0);
|
||||||
flashlight_set_active(flashlight, flashlight_get_active(flashlight));
|
flashlight_set_active(flashlight, flashlight_get_active(flashlight));
|
||||||
|
flashlight_set_keep_lit(flashlight, TRUE);
|
||||||
return flashlight;
|
return flashlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,15 +137,22 @@ gboolean flashlight_get_active(Flashlight * flashlight)
|
||||||
default:
|
default:
|
||||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||||
return gtk_switch_get_active(GTK_SWITCH(
|
return gtk_switch_get_active(GTK_SWITCH(
|
||||||
flashlight->co_main));
|
flashlight->co_toggle));
|
||||||
#else
|
#else
|
||||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
||||||
flashlight->co_main));
|
flashlight->co_toggle));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* flashlight_get_keep_lit */
|
||||||
|
gboolean flashlight_get_keep_lit(Flashlight * flashlight)
|
||||||
|
{
|
||||||
|
return flashlight->control;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* flashlight_get_widget */
|
/* flashlight_get_widget */
|
||||||
GtkWidget * flashlight_get_widget(Flashlight * flashlight)
|
GtkWidget * flashlight_get_widget(Flashlight * flashlight)
|
||||||
{
|
{
|
||||||
|
@ -142,14 +166,23 @@ void flashlight_set_active(Flashlight * flashlight, gboolean active)
|
||||||
flashlightbackend_set(active);
|
flashlightbackend_set(active);
|
||||||
gtk_widget_set_sensitive(flashlight->image, active);
|
gtk_widget_set_sensitive(flashlight->image, active);
|
||||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||||
gtk_switch_set_active(GTK_SWITCH(flashlight->co_main), active);
|
gtk_switch_set_active(GTK_SWITCH(flashlight->co_toggle), active);
|
||||||
#else
|
#else
|
||||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(flashlight->co_main),
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(flashlight->co_toggle),
|
||||||
active);
|
active);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* flashlight_set_keep_lit */
|
||||||
|
void flashlight_set_keep_lit(Flashlight * flashlight, gboolean active)
|
||||||
|
{
|
||||||
|
flashlight->control = active;
|
||||||
|
gtk_widget_hide(active ? flashlight->co_press : flashlight->co_toggle);
|
||||||
|
gtk_widget_show(active ? flashlight->co_toggle : flashlight->co_press);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* flashlight_set_orientation */
|
/* flashlight_set_orientation */
|
||||||
void flashlight_set_orientation(Flashlight * flashlight,
|
void flashlight_set_orientation(Flashlight * flashlight,
|
||||||
GtkOrientation orientation)
|
GtkOrientation orientation)
|
||||||
|
@ -176,6 +209,24 @@ void flashlight_toggle(Flashlight * flashlight)
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
|
static gboolean _flashlight_on_button_pressed(gpointer data)
|
||||||
|
{
|
||||||
|
Flashlight * flashlight = data;
|
||||||
|
|
||||||
|
flashlight_set_active(flashlight, TRUE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean _flashlight_on_button_released(gpointer data)
|
||||||
|
{
|
||||||
|
Flashlight * flashlight = data;
|
||||||
|
|
||||||
|
flashlight_set_active(flashlight, FALSE);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* flashlight_on_toggled */
|
/* flashlight_on_toggled */
|
||||||
static void _flashlight_on_toggled(gpointer data)
|
static void _flashlight_on_toggled(gpointer data)
|
||||||
{
|
{
|
||||||
|
@ -183,9 +234,9 @@ static void _flashlight_on_toggled(gpointer data)
|
||||||
|
|
||||||
#if GTK_CHECK_VERSION(3, 0, 0)
|
#if GTK_CHECK_VERSION(3, 0, 0)
|
||||||
flashlight_set_active(flashlight, gtk_switch_get_active(
|
flashlight_set_active(flashlight, gtk_switch_get_active(
|
||||||
GTK_SWITCH(flashlight->co_main)));
|
GTK_SWITCH(flashlight->co_toggle)));
|
||||||
#else
|
#else
|
||||||
flashlight_set_active(flashlight, gtk_toggle_button_get_active(
|
flashlight_set_active(flashlight, gtk_toggle_button_get_active(
|
||||||
GTK_TOGGLE_BUTTON(flashlight->co_main)));
|
GTK_TOGGLE_BUTTON(flashlight->co_toggle)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,11 @@ void flashlight_delete(Flashlight * window);
|
||||||
|
|
||||||
/* accessors */
|
/* accessors */
|
||||||
gboolean flashlight_get_active(Flashlight * flashlight);
|
gboolean flashlight_get_active(Flashlight * flashlight);
|
||||||
|
gboolean flashlight_get_keep_lit(Flashlight * flashlight);
|
||||||
GtkWidget * flashlight_get_widget(Flashlight * flashlight);
|
GtkWidget * flashlight_get_widget(Flashlight * flashlight);
|
||||||
|
|
||||||
void flashlight_set_active(Flashlight * flashlight, gboolean active);
|
void flashlight_set_active(Flashlight * flashlight, gboolean active);
|
||||||
|
void flashlight_set_keep_lit(Flashlight * flashlight, gboolean active);
|
||||||
void flashlight_set_orientation(Flashlight * flashlight,
|
void flashlight_set_orientation(Flashlight * flashlight,
|
||||||
GtkOrientation orientation);
|
GtkOrientation orientation);
|
||||||
|
|
||||||
|
|
38
src/window.c
38
src/window.c
|
@ -56,6 +56,7 @@ static void _flashlightwindow_on_about(gpointer data);
|
||||||
static gboolean _flashlightwindow_on_closex(void);
|
static gboolean _flashlightwindow_on_closex(void);
|
||||||
static gboolean _flashlightwindow_on_configure(gpointer data);
|
static gboolean _flashlightwindow_on_configure(gpointer data);
|
||||||
static gboolean _flashlightwindow_on_idle(gpointer data);
|
static gboolean _flashlightwindow_on_idle(gpointer data);
|
||||||
|
static void _flashlightwindow_on_preferences(gpointer data);
|
||||||
|
|
||||||
|
|
||||||
/* constants */
|
/* constants */
|
||||||
|
@ -119,6 +120,11 @@ FlashlightWindow * flashlightwindow_new(void)
|
||||||
/* about */
|
/* about */
|
||||||
bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
|
bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
|
||||||
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
||||||
|
gtk_box_set_spacing(GTK_BOX(bbox), 4);
|
||||||
|
widget = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
|
||||||
|
g_signal_connect_swapped(widget, "clicked", G_CALLBACK(
|
||||||
|
_flashlightwindow_on_preferences), window);
|
||||||
|
gtk_container_add(GTK_CONTAINER(bbox), widget);
|
||||||
widget = gtk_button_new_from_stock(GTK_STOCK_ABOUT);
|
widget = gtk_button_new_from_stock(GTK_STOCK_ABOUT);
|
||||||
g_signal_connect_swapped(widget, "clicked", G_CALLBACK(
|
g_signal_connect_swapped(widget, "clicked", G_CALLBACK(
|
||||||
_flashlightwindow_on_about), window);
|
_flashlightwindow_on_about), window);
|
||||||
|
@ -201,3 +207,35 @@ static gboolean _flashlightwindow_on_idle(gpointer data)
|
||||||
window->source = 0;
|
window->source = 0;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* flashlightwindow_on_preferences */
|
||||||
|
static void _flashlightwindow_on_preferences(gpointer data)
|
||||||
|
{
|
||||||
|
FlashlightWindow * window = data;
|
||||||
|
GtkWidget * dialog;
|
||||||
|
const unsigned int flags = GTK_DIALOG_MODAL
|
||||||
|
| GTK_DIALOG_DESTROY_WITH_PARENT;
|
||||||
|
GtkWidget * content;
|
||||||
|
GtkWidget * widget;
|
||||||
|
gboolean active;
|
||||||
|
|
||||||
|
dialog = gtk_dialog_new_with_buttons(_("Preferences"),
|
||||||
|
GTK_WINDOW(window->window), flags,
|
||||||
|
_("_Close"), GTK_RESPONSE_CLOSE, NULL);
|
||||||
|
#if GTK_CHECK_VERSION(2, 14, 0)
|
||||||
|
content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||||
|
#else
|
||||||
|
content = GTK_DIALOG(dialog)->content_area;
|
||||||
|
#endif
|
||||||
|
widget = gtk_check_button_new_with_mnemonic(
|
||||||
|
_("Stay lit when released"));
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
|
||||||
|
flashlight_get_keep_lit(window->flashlight));
|
||||||
|
gtk_widget_show(widget);
|
||||||
|
gtk_box_pack_start(GTK_BOX(content), widget, FALSE, TRUE, 0);
|
||||||
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
||||||
|
active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
||||||
|
flashlight_set_keep_lit(window->flashlight, active);
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user