mirror of
https://github.com/labwc/labwc.git
synced 2026-02-21 01:40:26 -05:00
action: simplify action_prompt_command()
This commit is contained in:
parent
2f96664670
commit
5f981226c2
4 changed files with 46 additions and 123 deletions
48
src/action.c
48
src/action.c
|
|
@ -10,7 +10,6 @@
|
|||
#include <wlr/types/wlr_scene.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "action-prompt-codes.h"
|
||||
#include "action-prompt-command.h"
|
||||
#include "common/buf.h"
|
||||
#include "common/macros.h"
|
||||
#include "common/list.h"
|
||||
|
|
@ -30,6 +29,7 @@
|
|||
#include "regions.h"
|
||||
#include "ssd.h"
|
||||
#include "theme.h"
|
||||
#include "translate.h"
|
||||
#include "view.h"
|
||||
#include "workspaces.h"
|
||||
|
||||
|
|
@ -831,11 +831,55 @@ handle_view_destroy(struct wl_listener *listener, void *data)
|
|||
prompt->view = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
print_prompt_command(struct buf *buf, const char *format,
|
||||
struct action *action, struct theme *theme)
|
||||
{
|
||||
assert(format);
|
||||
|
||||
for (const char *p = format; *p; p++) {
|
||||
/*
|
||||
* If we're not on a conversion specifier (like %m) then just
|
||||
* keep adding it to the buffer
|
||||
*/
|
||||
if (*p != '%') {
|
||||
buf_add_char(buf, *p);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Process the %* conversion specifier */
|
||||
++p;
|
||||
|
||||
switch (*p) {
|
||||
case 'm':
|
||||
buf_add(buf, action_get_str(action,
|
||||
"message.prompt", "Choose wisely"));
|
||||
break;
|
||||
case 'n':
|
||||
buf_add(buf, _("No"));
|
||||
break;
|
||||
case 'y':
|
||||
buf_add(buf, _("Yes"));
|
||||
break;
|
||||
case 'b':
|
||||
buf_add_hex_color(buf, theme->osd_bg_color);
|
||||
break;
|
||||
case 't':
|
||||
buf_add_hex_color(buf, theme->osd_label_text_color);
|
||||
break;
|
||||
default:
|
||||
wlr_log(WLR_ERROR,
|
||||
"invalid prompt command conversion specifier '%c'", *p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
action_prompt_create(struct view *view, struct server *server, struct action *action)
|
||||
{
|
||||
struct buf command = BUF_INIT;
|
||||
action_prompt_command(&command, rc.prompt_command, action, rc.theme);
|
||||
print_prompt_command(&command, rc.prompt_command, action, rc.theme);
|
||||
|
||||
wlr_log(WLR_INFO, "prompt command: '%s'", command.data);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue