use gsettings

This commit is contained in:
Damian Ivanov 2020-08-23 17:43:20 +03:00
parent dd7e1e22ee
commit 73e31fa4bd
3 changed files with 88 additions and 24 deletions

View File

@ -40,6 +40,16 @@ if scour.found()
install_data(icon, install_dir: icondir) install_data(icon, install_dir: icondir)
endif endif
gnome.compile_schemas(
build_by_default: true,
depend_files: 'network.cycles.wdisplays.gschema.xml'
)
install_data(
'network.cycles.wdisplays.gschema.xml',
install_dir: join_paths(get_option('datadir'), 'glib-2.0', 'schemas')
)
install_data( install_data(
configure_file(input: 'wdisplays.desktop.in', configure_file(input: 'wdisplays.desktop.in',
output: '@0@.desktop'.format(meson.project_name()), output: '@0@.desktop'.format(meson.project_name()),

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="gsettings-desktop-schemas">
<schema id="network.cycles.wdisplays" path="/network/cycles/wdisplays/">
<key type="b" name="overlay">
<default>true</default>
<description>If an overlay is show on each display.</description>
</key>
<key type="b" name="capture">
<default>false</default>
<description>If the display contents are drawn as preview.</description>
</key>
<key type="b" name="auto-apply">
<default>false</default>
<description>If the display contents are drawn as preview.</description>
</key>
</schema>
</schemalist>

View File

@ -22,6 +22,10 @@ __attribute__((noreturn)) void wd_fatal_error(int status, const char *message) {
#define CANVAS_MARGIN 40 #define CANVAS_MARGIN 40
static const char *APP_PREFIX = "app"; static const char *APP_PREFIX = "app";
GSettings *settings;
GSimpleAction *capture_action;
GSimpleAction *overlay_action;
GSimpleAction *apply_action;
static bool has_changes(const struct wd_state *state) { static bool has_changes(const struct wd_state *state) {
g_autoptr(GList) forms = gtk_container_get_children(GTK_CONTAINER(state->stack)); g_autoptr(GList) forms = gtk_container_get_children(GTK_CONTAINER(state->stack));
@ -857,9 +861,7 @@ static void info_bar_animation_done(GObject *object, GParamSpec *pspec, gpointer
} }
static void auto_apply_selected(GSimpleAction *action, GVariant *param, gpointer data) { static void auto_apply_selected(GSimpleAction *action, GVariant *param, gpointer data) {
struct wd_state *state = data; g_settings_set_boolean(settings, "auto-apply", g_variant_get_boolean(param));
state->autoapply = g_variant_get_boolean(param);
g_simple_action_set_state(action, param);
} }
static gboolean redraw_canvas(GtkWidget *widget, GdkFrameClock *frame_clock, gpointer data) { static gboolean redraw_canvas(GtkWidget *widget, GdkFrameClock *frame_clock, gpointer data) {
@ -873,16 +875,36 @@ static gboolean redraw_canvas(GtkWidget *widget, GdkFrameClock *frame_clock, gpo
} }
static void capture_selected(GSimpleAction *action, GVariant *param, gpointer data) { static void capture_selected(GSimpleAction *action, GVariant *param, gpointer data) {
struct wd_state *state = data; g_settings_set_boolean(settings, "capture", g_variant_get_boolean(param));
state->capture = g_variant_get_boolean(param);
g_simple_action_set_state(action, param);
update_tick_callback(state);
} }
static void overlay_selected(GSimpleAction *action, GVariant *param, gpointer data) { static void overlay_selected(GSimpleAction *action, GVariant *param, gpointer data) {
g_settings_set_boolean(settings, "overlay", g_variant_get_boolean(param));
}
static void settings_changed_slot(GSettings *settings, gchar *key, gpointer data)
{
if (g_strcmp0(key, "capture") == 0) {
struct wd_state *state = data; struct wd_state *state = data;
state->show_overlay = g_variant_get_boolean(param);
g_simple_action_set_state(action, param); if (state->copy_manager == NULL) {
return;
}
state->capture = g_settings_get_boolean(settings, "capture");
GVariant* param = g_variant_new_boolean(state->capture);
g_simple_action_set_state(capture_action, param);
update_tick_callback(state);
}
else if (g_strcmp0(key, "overlay") == 0)
{
struct wd_state *state = data;
if (state->layer_shell == NULL) {
return;
}
state->show_overlay = g_settings_get_boolean(settings, "overlay");
GVariant* param = g_variant_new_boolean(state->show_overlay);
g_simple_action_set_state(overlay_action, param);
struct wd_output *output; struct wd_output *output;
wl_list_for_each(output, &state->outputs, link) { wl_list_for_each(output, &state->outputs, link) {
@ -892,8 +914,15 @@ static void overlay_selected(GSimpleAction *action, GVariant *param, gpointer da
wd_destroy_overlay(output); wd_destroy_overlay(output);
} }
} }
}
else if (g_strcmp0(key, "auto-apply") == 0)
{
struct wd_state *state = data;
state->autoapply = g_settings_get_boolean(settings, "auto-apply");
GVariant* param = g_variant_new_boolean(state->autoapply);
g_simple_action_set_state(apply_action, param);
}
} }
static void window_state_changed(GtkWidget *window, GdkEventWindowState *event, static void window_state_changed(GtkWidget *window, GdkEventWindowState *event,
gpointer data) { gpointer data) {
struct wd_state *state = data; struct wd_state *state = data;
@ -920,6 +949,11 @@ static void activate(GtkApplication* app, gpointer user_data) {
} }
struct wd_state *state = wd_state_create(); struct wd_state *state = wd_state_create();
settings = g_settings_new("network.cycles.wdisplays");
state->capture = g_settings_get_boolean(settings, "capture");
state->show_overlay = g_settings_get_boolean(settings, "overlay");
state->autoapply = g_settings_get_boolean(settings, "auto-apply");
state->zoom = DEFAULT_ZOOM; state->zoom = DEFAULT_ZOOM;
state->canvas_tick = -1; state->canvas_tick = -1;
state->apply_idle = -1; state->apply_idle = -1;
@ -1019,17 +1053,17 @@ static void activate(GtkApplication* app, gpointer user_data) {
g_signal_connect(action, "activate", G_CALLBACK(zoom_in), state); g_signal_connect(action, "activate", G_CALLBACK(zoom_in), state);
g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(action)); g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(action));
action = g_simple_action_new_stateful("auto-apply", NULL, apply_action = g_simple_action_new_stateful("auto-apply", NULL,
g_variant_new_boolean(state->autoapply)); g_variant_new_boolean(state->autoapply));
g_signal_connect(action, "change-state", G_CALLBACK(auto_apply_selected), state); g_signal_connect(apply_action, "change-state", G_CALLBACK(auto_apply_selected), state);
g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(action)); g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(apply_action));
GSimpleAction *capture_action = g_simple_action_new_stateful("capture-screens", NULL, capture_action = g_simple_action_new_stateful("capture-screens", NULL,
g_variant_new_boolean(state->capture)); g_variant_new_boolean(state->capture));
g_signal_connect(capture_action, "change-state", G_CALLBACK(capture_selected), state); g_signal_connect(capture_action, "change-state", G_CALLBACK(capture_selected), state);
g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(capture_action)); g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(capture_action));
GSimpleAction *overlay_action = g_simple_action_new_stateful("show-overlay", NULL, overlay_action = g_simple_action_new_stateful("show-overlay", NULL,
g_variant_new_boolean(state->show_overlay)); g_variant_new_boolean(state->show_overlay));
g_signal_connect(overlay_action, "change-state", G_CALLBACK(overlay_selected), state); g_signal_connect(overlay_action, "change-state", G_CALLBACK(overlay_selected), state);
g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(overlay_action)); g_action_map_add_action(G_ACTION_MAP(main_actions), G_ACTION(overlay_action));
@ -1054,11 +1088,13 @@ static void activate(GtkApplication* app, gpointer user_data) {
if (state->xdg_output_manager == NULL) { if (state->xdg_output_manager == NULL) {
wd_fatal_error(1, "Compositor doesn't support xdg-output-unstable-v1"); wd_fatal_error(1, "Compositor doesn't support xdg-output-unstable-v1");
} }
if (state->copy_manager == NULL) { if (state->copy_manager == NULL) {
state->capture = FALSE; state->capture = FALSE;
g_simple_action_set_state(capture_action, g_variant_new_boolean(state->capture)); g_simple_action_set_state(capture_action, g_variant_new_boolean(state->capture));
g_simple_action_set_enabled(capture_action, FALSE); g_simple_action_set_enabled(capture_action, FALSE);
} }
if (state->layer_shell == NULL) { if (state->layer_shell == NULL) {
state->show_overlay = FALSE; state->show_overlay = FALSE;
g_simple_action_set_state(overlay_action, g_variant_new_boolean(state->show_overlay)); g_simple_action_set_state(overlay_action, g_variant_new_boolean(state->show_overlay));
@ -1078,6 +1114,7 @@ static void activate(GtkApplication* app, gpointer user_data) {
gtk_widget_show_all(window); gtk_widget_show_all(window);
g_object_unref(builder); g_object_unref(builder);
update_tick_callback(state); update_tick_callback(state);
g_signal_connect(settings, "changed", G_CALLBACK(settings_changed_slot), state);
} }
// END GLOBAL CALLBACKS // END GLOBAL CALLBACKS