bar: add bar->output_name(), returns the name of the output we’re on

This commit is contained in:
Daniel Eklöf 2021-08-02 19:29:52 +02:00
parent 96a35e5304
commit 74016d7d33
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 29 additions and 0 deletions

View file

@ -14,4 +14,5 @@ struct backend {
void (*commit)(const struct bar *bar); void (*commit)(const struct bar *bar);
void (*refresh)(const struct bar *bar); void (*refresh)(const struct bar *bar);
void (*set_cursor)(struct bar *bar, const char *cursor); void (*set_cursor)(struct bar *bar, const char *cursor);
const char *(*output_name)(const struct bar *bar);
}; };

View file

@ -162,6 +162,13 @@ set_cursor(struct bar *bar, const char *cursor)
b->backend.iface->set_cursor(bar, cursor); b->backend.iface->set_cursor(bar, cursor);
} }
static const char *
output_name(const struct bar *bar)
{
const struct private *b = bar->private;
return b->backend.iface->output_name(bar);
}
static void static void
on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn, on_mouse(struct bar *_bar, enum mouse_event event, enum mouse_button btn,
int x, int y) int x, int y)
@ -456,6 +463,7 @@ bar_new(const struct bar_config *config)
bar->destroy = &destroy; bar->destroy = &destroy;
bar->refresh = &refresh; bar->refresh = &refresh;
bar->set_cursor = &set_cursor; bar->set_cursor = &set_cursor;
bar->output_name = &output_name;
for (size_t i = 0; i < priv->left.count; i++) for (size_t i = 0; i < priv->left.count; i++)
priv->left.mods[i]->bar = bar; priv->left.mods[i]->bar = bar;

View file

@ -12,6 +12,8 @@ struct bar {
void (*refresh)(const struct bar *bar); void (*refresh)(const struct bar *bar);
void (*set_cursor)(struct bar *bar, const char *cursor); void (*set_cursor)(struct bar *bar, const char *cursor);
const char *(*output_name)(const struct bar *bar);
}; };
enum bar_location { BAR_TOP, BAR_BOTTOM }; enum bar_location { BAR_TOP, BAR_BOTTOM };

View file

@ -1308,6 +1308,15 @@ set_cursor(struct bar *_bar, const char *cursor)
update_cursor_surface(backend, seat); update_cursor_surface(backend, seat);
} }
static const char *
output_name(const struct bar *_bar)
{
const struct private *bar = _bar->private;
const struct wayland_backend *backend = bar->backend.data;
return backend->monitor != NULL ? backend->monitor->name : NULL;
}
const struct backend wayland_backend_iface = { const struct backend wayland_backend_iface = {
.setup = &setup, .setup = &setup,
.cleanup = &cleanup, .cleanup = &cleanup,
@ -1315,4 +1324,5 @@ const struct backend wayland_backend_iface = {
.commit = &commit, .commit = &commit,
.refresh = &refresh, .refresh = &refresh,
.set_cursor = &set_cursor, .set_cursor = &set_cursor,
.output_name = &output_name,
}; };

View file

@ -462,6 +462,13 @@ set_cursor(struct bar *_bar, const char *cursor)
backend->conn, backend->win, XCB_CW_CURSOR, &backend->cursor); backend->conn, backend->win, XCB_CW_CURSOR, &backend->cursor);
} }
static const char *
output_name(const struct bar *_bar)
{
/* Not implemented */
return NULL;
}
const struct backend xcb_backend_iface = { const struct backend xcb_backend_iface = {
.setup = &setup, .setup = &setup,
.cleanup = &cleanup, .cleanup = &cleanup,
@ -469,4 +476,5 @@ const struct backend xcb_backend_iface = {
.commit = &commit, .commit = &commit,
.refresh = &refresh, .refresh = &refresh,
.set_cursor = &set_cursor, .set_cursor = &set_cursor,
.output_name = &output_name,
}; };