-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: keyboard backlight button and cli
Signed-off-by: ldelossa <[email protected]>
- Loading branch information
Showing
14 changed files
with
788 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...ettings_grid/quick_settings_keyboard_brightness/quick_settings_grid_keyboard_brightness.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "./quick_settings_grid_keyboard_brightness.h" | ||
|
||
#include <adwaita.h> | ||
|
||
#include "../../../../services/brightness_service/brightness_service.h" | ||
#include "glib-object.h" | ||
|
||
void quick_settings_grid_keyboard_brightness_button_layout( | ||
QuickSettingsGridKeyboardBrightnessButton *self) { | ||
// create associated menu | ||
self->menu = | ||
g_object_new(QUICK_SETTINGS_GRID_KEYBOARD_BRIGHTNESS_MENU_TYPE, NULL); | ||
|
||
quick_settings_grid_button_init( | ||
&self->button, QUICK_SETTINGS_BUTTON_KEYBOARD_BRIGHTNESS, "Keyboard", | ||
NULL, "keyboard-brightness-symbolic", | ||
quick_settings_grid_keyboard_brightness_button_get_menu_widget(self), | ||
quick_settings_grid_keyboard_brightness_menu_on_reveal); | ||
} | ||
|
||
static void on_toggle_button_clicked( | ||
GtkButton *button, QuickSettingsGridKeyboardBrightnessButton *self) { | ||
g_debug( | ||
"quick_settings_grid_keyboard_brightness.c: " | ||
"on_toggle_button_clicked(): " | ||
"toggling keyboard backlight"); | ||
|
||
BrightnessService *bs = brightness_service_get_global(); | ||
guint keyboard_brightness = brightness_service_get_keyboard(bs); | ||
|
||
if (keyboard_brightness > 0) | ||
brightness_service_set_keyboard(bs, 0); | ||
else | ||
brightness_service_set_keyboard(bs, 1); | ||
} | ||
|
||
static void on_keyboard_brightness_changed( | ||
BrightnessService *bs, guint keyboard_brightness, | ||
QuickSettingsGridKeyboardBrightnessButton *self) { | ||
g_debug( | ||
"quick_settings_grid_keyboard_brightness.c: " | ||
"on_keyboard_brightness_changed(): " | ||
"keyboard_brightness = %d", | ||
keyboard_brightness); | ||
|
||
if (keyboard_brightness > 0) | ||
quick_settings_grid_button_set_toggled(&self->button, TRUE); | ||
else | ||
quick_settings_grid_button_set_toggled(&self->button, FALSE); | ||
} | ||
|
||
QuickSettingsGridKeyboardBrightnessButton * | ||
quick_settings_grid_keyboard_brightness_button_init() { | ||
QuickSettingsGridKeyboardBrightnessButton *self = | ||
g_malloc0(sizeof(QuickSettingsGridKeyboardBrightnessButton)); | ||
|
||
quick_settings_grid_keyboard_brightness_button_layout(self); | ||
|
||
BrightnessService *bs = brightness_service_get_global(); | ||
|
||
guint keyboard_brightness = brightness_service_get_keyboard(bs); | ||
on_keyboard_brightness_changed(bs, keyboard_brightness, self); | ||
|
||
g_signal_connect(self->button.toggle, "clicked", | ||
G_CALLBACK(on_toggle_button_clicked), self); | ||
g_signal_connect(bs, "keyboard-brightness-changed", | ||
G_CALLBACK(on_keyboard_brightness_changed), self); | ||
|
||
return self; | ||
} | ||
|
||
GtkWidget *quick_settings_grid_keyboard_brightness_button_get_menu_widget( | ||
QuickSettingsGridKeyboardBrightnessButton *self) { | ||
return GTK_WIDGET( | ||
quick_settings_grid_keyboard_brightness_menu_get_widget(self->menu)); | ||
} | ||
|
||
void quick_settings_grid_keyboard_brightness_button_free( | ||
QuickSettingsGridKeyboardBrightnessButton *self) { | ||
g_debug( | ||
"quick_settings_grid_keyboard_brightness.c:qs_grid_keyboard_brightness_" | ||
"button_free() " | ||
"called"); | ||
|
||
// kill signals | ||
BrightnessService *bs = brightness_service_get_global(); | ||
g_signal_handlers_disconnect_by_func(bs, on_keyboard_brightness_changed, | ||
self); | ||
|
||
// free ourselves | ||
g_free(self); | ||
} |
29 changes: 29 additions & 0 deletions
29
...ettings_grid/quick_settings_keyboard_brightness/quick_settings_grid_keyboard_brightness.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <NetworkManager.h> | ||
#include <adwaita.h> | ||
|
||
#include "../quick_settings_grid_button.h" | ||
#include "quick_settings_grid_keyboard_brightness_menu.h" | ||
|
||
#define QUICK_SETTINGS_KEYBOARD_BRIGHTNESS_TYPE "keyboard-brightness" | ||
|
||
typedef struct _QuickSesstingsGridKeyboardBrightnessButton { | ||
// embedd this as first argument so we can cast to it. | ||
QuickSettingsGridButton button; | ||
QuickSettingsGridKeyboardBrightnessMenu *menu; | ||
gboolean enabled; | ||
|
||
} QuickSettingsGridKeyboardBrightnessButton; | ||
|
||
QuickSettingsGridKeyboardBrightnessButton * | ||
quick_settings_grid_keyboard_brightness_button_init(); | ||
|
||
void quick_settings_grid_keyboard_brightness_button_free( | ||
QuickSettingsGridKeyboardBrightnessButton *self); | ||
|
||
GtkWidget *quick_settings_grid_keyboard_brightness_button_get_menu_widget( | ||
QuickSettingsGridKeyboardBrightnessButton *self); | ||
|
||
void quick_settings_grid_keyboard_brightness_menu_on_reveal( | ||
QuickSettingsGridButton *button, gboolean is_revealed); |
158 changes: 158 additions & 0 deletions
158
...gs_grid/quick_settings_keyboard_brightness/quick_settings_grid_keyboard_brightness_menu.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#include "quick_settings_grid_keyboard_brightness_menu.h" | ||
|
||
#include <adwaita.h> | ||
|
||
#include "../../../../services/brightness_service/brightness_service.h" | ||
#include "../../quick_settings.h" | ||
#include "../../quick_settings_menu_widget.h" | ||
#include "gtk/gtk.h" | ||
#include "quick_settings_grid_keyboard_brightness.h" | ||
|
||
enum signals { signals_n }; | ||
|
||
typedef struct _QuickSettingsGridKeyboardBrightnessMenu { | ||
GObject parent_instance; | ||
QuickSettingsMenuWidget menu; | ||
GtkScale *brightness_slider; | ||
} QuickSettingsGridKeyboardBrightnessMenu; | ||
G_DEFINE_TYPE(QuickSettingsGridKeyboardBrightnessMenu, | ||
quick_settings_grid_keyboard_brightness_menu, G_TYPE_OBJECT); | ||
|
||
// stub out dispose, finalize, init and class init functions for GObject | ||
static void quick_settings_grid_keyboard_brightness_menu_dispose( | ||
GObject *object) { | ||
QuickSettingsGridKeyboardBrightnessMenu *self = | ||
QUICK_SETTINGS_GRID_KEYBOARD_BRIGHTNESS_MENU(object); | ||
} | ||
|
||
static void quick_settings_grid_keyboard_brightness_menu_finalize( | ||
GObject *object) {} | ||
|
||
static void quick_settings_grid_keyboard_brightness_menu_class_init( | ||
QuickSettingsGridKeyboardBrightnessMenuClass *klass) { | ||
GObjectClass *object_class = G_OBJECT_CLASS(klass); | ||
object_class->dispose = | ||
quick_settings_grid_keyboard_brightness_menu_dispose; | ||
object_class->finalize = | ||
quick_settings_grid_keyboard_brightness_menu_finalize; | ||
} | ||
|
||
static void on_value_changed(GtkRange *range, | ||
QuickSettingsGridKeyboardBrightnessMenu *self); | ||
|
||
static void on_keyboard_brightness_changed( | ||
BrightnessService *bs, guint32 brightness, | ||
QuickSettingsGridKeyboardBrightnessMenu *self); | ||
|
||
static void block_brightness_service_signals( | ||
QuickSettingsGridKeyboardBrightnessMenu *self, gboolean block) { | ||
BrightnessService *bs = brightness_service_get_global(); | ||
if (block) { | ||
g_signal_handlers_block_by_func(bs, on_keyboard_brightness_changed, | ||
self); | ||
} else { | ||
g_signal_handlers_unblock_by_func(bs, on_keyboard_brightness_changed, | ||
self); | ||
} | ||
} | ||
|
||
static void block_brightness_scale_signals( | ||
QuickSettingsGridKeyboardBrightnessMenu *self, gboolean block) { | ||
if (block) { | ||
g_signal_handlers_block_by_func(self->brightness_slider, | ||
on_value_changed, self); | ||
} else { | ||
g_signal_handlers_unblock_by_func(self->brightness_slider, | ||
on_value_changed, self); | ||
} | ||
} | ||
|
||
static void on_keyboard_brightness_changed( | ||
BrightnessService *bs, guint32 brightness, | ||
QuickSettingsGridKeyboardBrightnessMenu *self) { | ||
g_debug( | ||
"quick_settings_grid_keyboard_brightness_menu.c:on_keyboard_brightness_" | ||
"changed() " | ||
"called: %d", | ||
brightness); | ||
|
||
// we are setting out scale, so ignore next scale event | ||
block_brightness_scale_signals(self, true); | ||
|
||
gtk_range_set_value(GTK_RANGE(self->brightness_slider), brightness); | ||
|
||
block_brightness_scale_signals(self, false); | ||
} | ||
|
||
static void on_value_changed(GtkRange *range, | ||
QuickSettingsGridKeyboardBrightnessMenu *self) { | ||
g_debug( | ||
"quick_settings_grid_keyboard_brightness_menu.c:on_value_changed() " | ||
"called: %f", | ||
gtk_range_get_value(range)); | ||
|
||
// we are writing to brightness API so ignore next brightness service | ||
// event | ||
|
||
block_brightness_service_signals(self, true); | ||
|
||
BrightnessService *bs = brightness_service_get_global(); | ||
brightness_service_set_keyboard(bs, gtk_range_get_value(range)); | ||
|
||
block_brightness_service_signals(self, false); | ||
} | ||
|
||
static void quick_settings_grid_keyboard_brightness_menu_init_layout( | ||
QuickSettingsGridKeyboardBrightnessMenu *self) { | ||
quick_settings_menu_widget_init(&self->menu, false); | ||
gtk_image_set_from_icon_name(self->menu.icon, | ||
"keyboard-brightness-symbolic"); | ||
gtk_label_set_text(self->menu.title, "Keyboard Backlight"); | ||
|
||
BrightnessService *bs = brightness_service_get_global(); | ||
guint32 keyboard_max = brightness_service_get_keyboard_max(bs); | ||
guint32 keyboard_cur = brightness_service_get_keyboard(bs); | ||
|
||
self->brightness_slider = GTK_SCALE(gtk_scale_new_with_range( | ||
GTK_ORIENTATION_HORIZONTAL, 0, keyboard_max, 1.0)); | ||
gtk_range_set_round_digits(GTK_RANGE(self->brightness_slider), 0); | ||
|
||
for (guint32 i = 0; i <= keyboard_max; i++) { | ||
gtk_scale_add_mark(self->brightness_slider, i, GTK_POS_BOTTOM, NULL); | ||
} | ||
|
||
gtk_range_set_value(GTK_RANGE(self->brightness_slider), keyboard_cur); | ||
|
||
// connect signal | ||
g_signal_connect(self->brightness_slider, "value-changed", | ||
G_CALLBACK(on_value_changed), self); | ||
|
||
g_signal_connect(bs, "keyboard_brightness_changed", | ||
G_CALLBACK(on_keyboard_brightness_changed), self); | ||
|
||
gtk_box_append(self->menu.options, GTK_WIDGET(self->brightness_slider)); | ||
} | ||
|
||
static void quick_settings_grid_keyboard_brightness_menu_init( | ||
QuickSettingsGridKeyboardBrightnessMenu *self) { | ||
quick_settings_grid_keyboard_brightness_menu_init_layout(self); | ||
} | ||
|
||
void quick_settings_grid_keyboard_brightness_menu_on_reveal( | ||
QuickSettingsGridButton *button_, gboolean is_revealed) { | ||
QuickSettingsGridKeyboardBrightnessButton *button = | ||
(QuickSettingsGridKeyboardBrightnessButton *)button_; | ||
QuickSettingsGridKeyboardBrightnessMenu *self = button->menu; | ||
g_debug( | ||
"quick_settings_grid_keyboard_brightness_menu.c:on_reveal() called"); | ||
} | ||
|
||
GtkWidget *quick_settings_grid_keyboard_brightness_menu_get_widget( | ||
QuickSettingsGridKeyboardBrightnessMenu *self) { | ||
return GTK_WIDGET(self->menu.container); | ||
} | ||
|
||
GtkScale *quick_settings_grid_keyboard_brightness_menu_get_temp_scale( | ||
QuickSettingsGridKeyboardBrightnessMenu *grid) { | ||
return grid->brightness_slider; | ||
} |
21 changes: 21 additions & 0 deletions
21
...gs_grid/quick_settings_keyboard_brightness/quick_settings_grid_keyboard_brightness_menu.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <NetworkManager.h> | ||
#include <adwaita.h> | ||
|
||
G_BEGIN_DECLS | ||
|
||
struct _QuickSettingsGridKeyboardBrightnessMenu; | ||
#define QUICK_SETTINGS_GRID_KEYBOARD_BRIGHTNESS_MENU_TYPE \ | ||
quick_settings_grid_keyboard_brightness_menu_get_type() | ||
G_DECLARE_FINAL_TYPE(QuickSettingsGridKeyboardBrightnessMenu, | ||
quick_settings_grid_keyboard_brightness_menu, QUICK_SETTINGS, | ||
GRID_KEYBOARD_BRIGHTNESS_MENU, GObject); | ||
|
||
G_END_DECLS | ||
|
||
GtkScale *quick_settings_grid_keyboard_brightness_menu_get_temp_scale( | ||
QuickSettingsGridKeyboardBrightnessMenu *grid); | ||
|
||
GtkWidget *quick_settings_grid_keyboard_brightness_menu_get_widget( | ||
QuickSettingsGridKeyboardBrightnessMenu *grid); |
Oops, something went wrong.