mirror of
https://github.com/labwc/labwc.git
synced 2026-05-19 21:37:33 -04:00
window-title: implement window-title command line argument
When -t or --window-title is supplied, its required argument is treated as a format string where `%o` is replaced by the `wlr-output`'s `name` when we set the window title. This uses glib to split and join the format string because our own `string-helpers` library only has `str_join`. Otherwise using `string-helpers` would have been preferred.
This commit is contained in:
parent
7a53f294a8
commit
df6dde131f
3 changed files with 19 additions and 8 deletions
|
|
@ -315,6 +315,8 @@ struct server {
|
|||
struct sfdo *sfdo;
|
||||
|
||||
pid_t primary_client_pid;
|
||||
|
||||
char *window_title_fmt;
|
||||
};
|
||||
|
||||
/* defined in main.c */
|
||||
|
|
|
|||
11
src/main.c
11
src/main.c
|
|
@ -9,6 +9,7 @@
|
|||
#include "common/font.h"
|
||||
#include "common/macros.h"
|
||||
#include "common/spawn.h"
|
||||
#include "common/string-helpers.h"
|
||||
#include "config/rcxml.h"
|
||||
#include "config/session.h"
|
||||
#include "labwc.h"
|
||||
|
|
@ -37,6 +38,7 @@ static const struct option long_options[] = {
|
|||
{"reconfigure", no_argument, NULL, 'r'},
|
||||
{"startup", required_argument, NULL, 's'},
|
||||
{"session", required_argument, NULL, 'S'},
|
||||
{"window-title", required_argument, NULL, 't'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"verbose", no_argument, NULL, 'V'},
|
||||
{0, 0, 0, 0}
|
||||
|
|
@ -178,7 +180,7 @@ main(int argc, char *argv[])
|
|||
int c;
|
||||
while (1) {
|
||||
int index = 0;
|
||||
c = getopt_long(argc, argv, "c:C:dehmrs:S:vV", long_options, &index);
|
||||
c = getopt_long(argc, argv, "c:C:dehmrs:S:t:vV", long_options, &index);
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -207,6 +209,9 @@ main(int argc, char *argv[])
|
|||
case 'S':
|
||||
primary_client = optarg;
|
||||
break;
|
||||
case 't':
|
||||
server.window_title_fmt = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
print_version();
|
||||
exit(0);
|
||||
|
|
@ -265,6 +270,10 @@ main(int argc, char *argv[])
|
|||
|
||||
increase_nofile_limit();
|
||||
|
||||
if (string_null_or_empty(server.window_title_fmt)) {
|
||||
server.window_title_fmt = "labwc - %o";
|
||||
}
|
||||
|
||||
server_init();
|
||||
server_start();
|
||||
|
||||
|
|
|
|||
14
src/output.c
14
src/output.c
|
|
@ -10,6 +10,7 @@
|
|||
#include "output.h"
|
||||
#include <assert.h>
|
||||
#include <drm_fourcc.h>
|
||||
#include <glib.h>
|
||||
#include <strings.h>
|
||||
#include <wlr/backend/wayland.h>
|
||||
#include <wlr/config.h>
|
||||
|
|
@ -26,6 +27,7 @@
|
|||
#include "common/macros.h"
|
||||
#include "common/mem.h"
|
||||
#include "common/scene-helpers.h"
|
||||
#include "common/string-helpers.h"
|
||||
#include "config/rcxml.h"
|
||||
#include "labwc.h"
|
||||
#include "layers.h"
|
||||
|
|
@ -605,13 +607,11 @@ handle_new_output(struct wl_listener *listener, void *data)
|
|||
}
|
||||
|
||||
if (wlr_output_is_wl(wlr_output)) {
|
||||
char title[64];
|
||||
if (getenv("LABWC_TITLE")) {
|
||||
snprintf(title, sizeof(title), "%s", getenv("LABWC_TITLE"));
|
||||
} else {
|
||||
snprintf(title, sizeof(title), "%s - %s", "labwc", wlr_output->name);
|
||||
}
|
||||
wlr_wl_output_set_title(wlr_output, title);
|
||||
gchar** parts = g_strsplit(server.window_title_fmt, "%o", -1);
|
||||
gchar* formatted_title = g_strjoinv(wlr_output->name, parts);
|
||||
g_strfreev(parts);
|
||||
wlr_wl_output_set_title(wlr_output, formatted_title);
|
||||
g_free(formatted_title);
|
||||
wlr_wl_output_set_app_id(wlr_output, "labwc");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue