diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-07-05 18:12:14 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-07-05 18:12:14 -0400 |
commit | 78c08fb0a281cbe74c56f0a2ea4b9370b9372661 (patch) | |
tree | 3fc34f67deb2988a1dcd1bf06f0798ada07333b8 | |
parent | Merge pull request #2185 from swaywm/update-wlroots-1076 (diff) | |
download | sway-78c08fb0a281cbe74c56f0a2ea4b9370b9372661.tar.gz sway-78c08fb0a281cbe74c56f0a2ea4b9370b9372661.tar.zst sway-78c08fb0a281cbe74c56f0a2ea4b9370b9372661.zip |
Implement mode --pango_markup
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | include/sway/ipc-server.h | 2 | ||||
-rw-r--r-- | sway/commands/mode.c | 19 | ||||
-rw-r--r-- | sway/ipc-server.c | 4 | ||||
-rw-r--r-- | sway/sway.5.scd | 4 | ||||
-rw-r--r-- | swaybar/render.c | 5 |
6 files changed, 27 insertions, 8 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index e75b0664..ac668c24 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -50,6 +50,7 @@ struct sway_mode { | |||
50 | char *name; | 50 | char *name; |
51 | list_t *keysym_bindings; | 51 | list_t *keysym_bindings; |
52 | list_t *keycode_bindings; | 52 | list_t *keycode_bindings; |
53 | bool pango; | ||
53 | }; | 54 | }; |
54 | 55 | ||
55 | struct input_config_mapped_from_region { | 56 | struct input_config_mapped_from_region { |
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index 026b5554..6469f097 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h | |||
@@ -15,6 +15,6 @@ void ipc_event_workspace(struct sway_container *old, | |||
15 | struct sway_container *new, const char *change); | 15 | struct sway_container *new, const char *change); |
16 | void ipc_event_window(struct sway_container *window, const char *change); | 16 | void ipc_event_window(struct sway_container *window, const char *change); |
17 | void ipc_event_barconfig_update(struct bar_config *bar); | 17 | void ipc_event_barconfig_update(struct bar_config *bar); |
18 | void ipc_event_mode(const char *mode); | 18 | void ipc_event_mode(const char *mode, bool pango); |
19 | 19 | ||
20 | #endif | 20 | #endif |
diff --git a/sway/commands/mode.c b/sway/commands/mode.c index 00331ccc..d2c14468 100644 --- a/sway/commands/mode.c +++ b/sway/commands/mode.c | |||
@@ -26,7 +26,17 @@ struct cmd_results *cmd_mode(int argc, char **argv) { | |||
26 | "mode", "Can only be used in config file."); | 26 | "mode", "Can only be used in config file."); |
27 | } | 27 | } |
28 | 28 | ||
29 | const char *mode_name = argv[0]; | 29 | bool pango = strcmp(*argv, "--pango_markup") == 0; |
30 | if (pango) { | ||
31 | argc--; argv++; | ||
32 | if (argc == 0) { | ||
33 | return cmd_results_new(CMD_FAILURE, "mode", | ||
34 | "Mode name is missing"); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | char *mode_name = *argv; | ||
39 | strip_quotes(mode_name); | ||
30 | struct sway_mode *mode = NULL; | 40 | struct sway_mode *mode = NULL; |
31 | // Find mode | 41 | // Find mode |
32 | for (int i = 0; i < config->modes->length; ++i) { | 42 | for (int i = 0; i < config->modes->length; ++i) { |
@@ -46,6 +56,7 @@ struct cmd_results *cmd_mode(int argc, char **argv) { | |||
46 | mode->name = strdup(mode_name); | 56 | mode->name = strdup(mode_name); |
47 | mode->keysym_bindings = create_list(); | 57 | mode->keysym_bindings = create_list(); |
48 | mode->keycode_bindings = create_list(); | 58 | mode->keycode_bindings = create_list(); |
59 | mode->pango = pango; | ||
49 | list_add(config->modes, mode); | 60 | list_add(config->modes, mode); |
50 | } | 61 | } |
51 | if (!mode) { | 62 | if (!mode) { |
@@ -54,13 +65,15 @@ struct cmd_results *cmd_mode(int argc, char **argv) { | |||
54 | return error; | 65 | return error; |
55 | } | 66 | } |
56 | if ((config->reading && argc > 1) || (!config->reading && argc == 1)) { | 67 | if ((config->reading && argc > 1) || (!config->reading && argc == 1)) { |
57 | wlr_log(L_DEBUG, "Switching to mode `%s'",mode->name); | 68 | wlr_log(L_DEBUG, "Switching to mode `%s' (pango=%d)", |
69 | mode->name, mode->pango); | ||
58 | } | 70 | } |
59 | // Set current mode | 71 | // Set current mode |
60 | config->current_mode = mode; | 72 | config->current_mode = mode; |
61 | if (argc == 1) { | 73 | if (argc == 1) { |
62 | // trigger IPC mode event | 74 | // trigger IPC mode event |
63 | ipc_event_mode(config->current_mode->name); | 75 | ipc_event_mode(config->current_mode->name, |
76 | config->current_mode->pango); | ||
64 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 77 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
65 | } | 78 | } |
66 | 79 | ||
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index abc2d7cb..8cfd9f26 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -332,13 +332,15 @@ void ipc_event_barconfig_update(struct bar_config *bar) { | |||
332 | json_object_put(json); | 332 | json_object_put(json); |
333 | } | 333 | } |
334 | 334 | ||
335 | void ipc_event_mode(const char *mode) { | 335 | void ipc_event_mode(const char *mode, bool pango) { |
336 | if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { | 336 | if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { |
337 | return; | 337 | return; |
338 | } | 338 | } |
339 | wlr_log(L_DEBUG, "Sending mode::%s event", mode); | 339 | wlr_log(L_DEBUG, "Sending mode::%s event", mode); |
340 | json_object *obj = json_object_new_object(); | 340 | json_object *obj = json_object_new_object(); |
341 | json_object_object_add(obj, "change", json_object_new_string(mode)); | 341 | json_object_object_add(obj, "change", json_object_new_string(mode)); |
342 | json_object_object_add(obj, "pango_markup", | ||
343 | json_object_new_boolean(pango)); | ||
342 | 344 | ||
343 | const char *json_string = json_object_to_json_string(obj); | 345 | const char *json_string = json_object_to_json_string(obj); |
344 | ipc_send_event(json_string, IPC_EVENT_MODE); | 346 | ipc_send_event(json_string, IPC_EVENT_MODE); |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 5ce6bf06..7c553d3f 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -413,10 +413,12 @@ The default colors are: | |||
413 | *mode* <mode> | 413 | *mode* <mode> |
414 | Switches to the specified mode. The default mode _default_. | 414 | Switches to the specified mode. The default mode _default_. |
415 | 415 | ||
416 | *mode* <mode> *{* <commands...> *}* | 416 | *mode* [--pango\_markup] <mode> *{* <commands...> *}* |
417 | _commands..._ after *{* will be added to the specified mode. A newline is | 417 | _commands..._ after *{* will be added to the specified mode. A newline is |
418 | required between *{* and the first command, and *}* must be alone on a | 418 | required between *{* and the first command, and *}* must be alone on a |
419 | line. Only *bindsym* and *bindcode* commands are permitted in mode blocks. | 419 | line. Only *bindsym* and *bindcode* commands are permitted in mode blocks. |
420 | If _--pango\_markup_ is given, then _mode_ will be interpreted as pango | ||
421 | markup. | ||
420 | 422 | ||
421 | *mouse\_warping* output|none | 423 | *mouse\_warping* output|none |
422 | If _output_ is specified, the mouse will be moved to new outputs as you | 424 | If _output_ is specified, the mouse will be moved to new outputs as you |
diff --git a/swaybar/render.c b/swaybar/render.c index 327a6f5f..efd3fdeb 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -298,7 +298,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
298 | 298 | ||
299 | int text_width, text_height; | 299 | int text_width, text_height; |
300 | get_text_size(cairo, config->font, &text_width, &text_height, | 300 | get_text_size(cairo, config->font, &text_width, &text_height, |
301 | output->scale, config->pango_markup, "%s", mode); | 301 | output->scale, config->mode_pango_markup, |
302 | "%s", mode); | ||
302 | 303 | ||
303 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; | 304 | int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; |
304 | int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; | 305 | int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; |
@@ -329,7 +330,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, | |||
329 | double text_y = height / 2.0 - text_height / 2.0; | 330 | double text_y = height / 2.0 - text_height / 2.0; |
330 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); | 331 | cairo_set_source_u32(cairo, config->colors.binding_mode.text); |
331 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); | 332 | cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); |
332 | pango_printf(cairo, config->font, output->scale, config->pango_markup, | 333 | pango_printf(cairo, config->font, output->scale, config->mode_pango_markup, |
333 | "%s", mode); | 334 | "%s", mode); |
334 | return surface_height; | 335 | return surface_height; |
335 | } | 336 | } |