mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 17:31:28 +00:00
progress on panel protocol
This commit is contained in:
parent
b7fe2a95ca
commit
aea0d45c9d
|
@ -27,6 +27,9 @@ struct panel_config {
|
||||||
struct wl_client *client;
|
struct wl_client *client;
|
||||||
// wlc handle for this panel's surface, not set until panel is created
|
// wlc handle for this panel's surface, not set until panel is created
|
||||||
wlc_handle handle;
|
wlc_handle handle;
|
||||||
|
|
||||||
|
enum desktop_shell_hide_modes hide_mode;
|
||||||
|
enum desktop_shell_hide_state hide;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct desktop_shell_state {
|
struct desktop_shell_state {
|
||||||
|
|
|
@ -117,6 +117,32 @@
|
||||||
<arg name="position" type="uint"/>
|
<arg name="position" type="uint"/>
|
||||||
</request>
|
</request>
|
||||||
|
|
||||||
|
<!-- Bar Hiding additions -->
|
||||||
|
<enum name="hide_modes">
|
||||||
|
<entry name="hide" value="0"/>
|
||||||
|
<entry name="show" value="1"/>
|
||||||
|
</enum>
|
||||||
|
|
||||||
|
<enum name="hide_state">
|
||||||
|
<entry name="hide" value="0"/>
|
||||||
|
<entry name="show" value="1"/>
|
||||||
|
</enum>
|
||||||
|
<request name="set_panel_hide_mode" since="3">
|
||||||
|
<description summary="set panel hide mode">
|
||||||
|
Tell the shell whether or not panel is in hide mode
|
||||||
|
i.e. whether to allocate a fixed amount of space
|
||||||
|
for the panel (hide mode false) or not (hide mode true)
|
||||||
|
</description>
|
||||||
|
<arg name="mode" type="uint"/>
|
||||||
|
</request>
|
||||||
|
|
||||||
|
<request name="set_panel_hide" since="3">
|
||||||
|
<description summary="set if panel is currently hidden">
|
||||||
|
Tell the shell whether or not panel is currently hidden
|
||||||
|
</description>
|
||||||
|
<arg name="mode" type="uint"/>
|
||||||
|
</request>
|
||||||
|
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
<interface name="screensaver" version="1">
|
<interface name="screensaver" version="1">
|
||||||
|
|
|
@ -133,6 +133,34 @@ static void set_panel(struct wl_client *client, struct wl_resource *resource,
|
||||||
wlc_output_schedule_render(config->output);
|
wlc_output_schedule_render(config->output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void set_panel_hide_mode(struct wl_client *client, struct wl_resource *resource,
|
||||||
|
uint32_t mode) {
|
||||||
|
struct panel_config *config = find_or_create_panel_config(resource);
|
||||||
|
config->hide_mode = mode;
|
||||||
|
if (mode == 0) {
|
||||||
|
wlc_view_set_mask(wlc_handle_from_wl_surface_resource(config->wl_surface_res), false);
|
||||||
|
} else {
|
||||||
|
wlc_view_set_mask(wlc_handle_from_wl_surface_resource(config->wl_surface_res), true);
|
||||||
|
}
|
||||||
|
arrange_windows(&root_container, -1, -1);
|
||||||
|
wlc_output_schedule_render(config->output);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_panel_hide(struct wl_client *client, struct wl_resource *resource,
|
||||||
|
uint32_t hide) {
|
||||||
|
sway_log(L_ERROR, "Attempting to find panel %p", resource);
|
||||||
|
struct panel_config *config = find_or_create_panel_config(resource);
|
||||||
|
config->hide = hide;
|
||||||
|
if (hide == 0) {
|
||||||
|
sway_log(L_ERROR, "Hiding panel %p", resource);
|
||||||
|
wlc_view_set_mask(wlc_handle_from_wl_surface_resource(config->wl_surface_res), false);
|
||||||
|
} else if (hide == 1) {
|
||||||
|
sway_log(L_ERROR, "Showing panel %p", resource);
|
||||||
|
wlc_view_set_mask(wlc_handle_from_wl_surface_resource(config->wl_surface_res), true);
|
||||||
|
}
|
||||||
|
wlc_output_schedule_render(config->output);
|
||||||
|
}
|
||||||
|
|
||||||
static void desktop_set_lock_surface(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface) {
|
static void desktop_set_lock_surface(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface) {
|
||||||
sway_log(L_ERROR, "desktop_set_lock_surface is not currently supported");
|
sway_log(L_ERROR, "desktop_set_lock_surface is not currently supported");
|
||||||
}
|
}
|
||||||
|
@ -169,7 +197,9 @@ static struct desktop_shell_interface desktop_shell_implementation = {
|
||||||
.unlock = desktop_unlock,
|
.unlock = desktop_unlock,
|
||||||
.set_grab_surface = set_grab_surface,
|
.set_grab_surface = set_grab_surface,
|
||||||
.desktop_ready = desktop_ready,
|
.desktop_ready = desktop_ready,
|
||||||
.set_panel_position = set_panel_position
|
.set_panel_position = set_panel_position,
|
||||||
|
.set_panel_hide_mode = set_panel_hide_mode,
|
||||||
|
.set_panel_hide = set_panel_hide
|
||||||
};
|
};
|
||||||
|
|
||||||
static void desktop_shell_bind(struct wl_client *client, void *data,
|
static void desktop_shell_bind(struct wl_client *client, void *data,
|
||||||
|
|
|
@ -1006,19 +1006,21 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
if (config->output == output->handle) {
|
if (config->output == output->handle) {
|
||||||
struct wlc_size size = *wlc_surface_get_size(config->surface);
|
struct wlc_size size = *wlc_surface_get_size(config->surface);
|
||||||
sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, config->panel_position);
|
sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, config->panel_position);
|
||||||
switch (config->panel_position) {
|
if (config->hide_mode == DESKTOP_SHELL_HIDE_MODES_SHOW) {
|
||||||
case DESKTOP_SHELL_PANEL_POSITION_TOP:
|
switch (config->panel_position) {
|
||||||
y += size.h; height -= size.h;
|
case DESKTOP_SHELL_PANEL_POSITION_TOP:
|
||||||
break;
|
y += size.h; height -= size.h;
|
||||||
case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
|
break;
|
||||||
height -= size.h;
|
case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
|
||||||
break;
|
height -= size.h;
|
||||||
case DESKTOP_SHELL_PANEL_POSITION_LEFT:
|
break;
|
||||||
x += size.w; width -= size.w;
|
case DESKTOP_SHELL_PANEL_POSITION_LEFT:
|
||||||
break;
|
x += size.w; width -= size.w;
|
||||||
case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
|
break;
|
||||||
width -= size.w;
|
case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
|
||||||
break;
|
width -= size.w;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,15 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
|
||||||
output->output, bar_output->window->surface);
|
output->output, bar_output->window->surface);
|
||||||
desktop_shell_set_panel_position(bar_output->registry->desktop_shell,
|
desktop_shell_set_panel_position(bar_output->registry->desktop_shell,
|
||||||
bar->config->position);
|
bar->config->position);
|
||||||
|
switch (bar->config->display_mode) {
|
||||||
|
case MODE_HIDE:
|
||||||
|
case MODE_INVISIBLE:
|
||||||
|
desktop_shell_set_panel_hide_mode(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_MODES_HIDE);
|
||||||
|
break;
|
||||||
|
case MODE_DOCK:
|
||||||
|
desktop_shell_set_panel_hide_mode(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_MODES_SHOW);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
window_make_shell(bar_output->window);
|
window_make_shell(bar_output->window);
|
||||||
|
|
||||||
|
|
|
@ -383,27 +383,42 @@ bool handle_ipc_event(struct bar *bar) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IPC_EVENT_MODIFIER: {
|
case IPC_EVENT_MODIFIER: {
|
||||||
json_object *result = json_tokener_parse(resp->payload);
|
if (bar->config->display_mode == MODE_HIDE) {
|
||||||
if (!result) {
|
json_object *result = json_tokener_parse(resp->payload);
|
||||||
free_ipc_response(resp);
|
if (!result) {
|
||||||
sway_log(L_ERROR, "failed to parse payload as json");
|
free_ipc_response(resp);
|
||||||
return false;
|
sway_log(L_ERROR, "failed to parse payload as json");
|
||||||
}
|
return false;
|
||||||
json_object *json_change;
|
}
|
||||||
if (json_object_object_get_ex(result, "change", &json_change)) {
|
json_object *json_change;
|
||||||
const char *change = json_object_get_string(json_change);
|
if (json_object_object_get_ex(result, "change", &json_change)) {
|
||||||
if (strcmp(change, "pressed") == 0) {
|
const char *change = json_object_get_string(json_change);
|
||||||
bar->config->hidden_state = BAR_SHOW;
|
if (strcmp(change, "pressed") == 0) {
|
||||||
} else { //must be "released"
|
bar->config->hidden_state = BAR_SHOW;
|
||||||
bar->config->hidden_state = BAR_HIDDEN;
|
sway_log(L_ERROR, "Showing bar on %d outputs", bar->outputs->length);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < bar->outputs->length; ++i) {
|
||||||
|
struct output *bar_output = bar->outputs->items[i];
|
||||||
|
sway_log(L_ERROR, "showing bar on input %d, with registry %p", i, bar_output->registry);
|
||||||
|
desktop_shell_set_panel_hide(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_STATE_SHOW);
|
||||||
|
}
|
||||||
|
} else { //must be "released"
|
||||||
|
bar->config->hidden_state = BAR_HIDDEN;
|
||||||
|
sway_log(L_ERROR, "Hiding bar");
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < bar->outputs->length; ++i) {
|
||||||
|
struct output *bar_output = bar->outputs->items[i];
|
||||||
|
desktop_shell_set_panel_hide(bar_output->registry->desktop_shell, DESKTOP_SHELL_HIDE_STATE_HIDE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sway_log(L_ERROR, "failed to parse response");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
json_object_put(result);
|
||||||
sway_log(L_ERROR, "failed to parse response");
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object_put(result);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
free_ipc_response(resp);
|
free_ipc_response(resp);
|
||||||
|
|
109
swaybar/render.c
109
swaybar/render.c
|
@ -286,67 +286,58 @@ void render(struct output *output, struct config *config, struct status_line *li
|
||||||
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
|
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
|
||||||
cairo_paint(cairo);
|
cairo_paint(cairo);
|
||||||
cairo_restore(cairo);
|
cairo_restore(cairo);
|
||||||
// Could also be done by always rendering then conditionally clearing and drawing alpha
|
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||||
// That may be preferable down the line
|
|
||||||
if (!(config->display_mode == MODE_HIDE) || config->hidden_state == BAR_SHOW) {
|
|
||||||
|
|
||||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
// Background
|
||||||
|
if (is_focused) {
|
||||||
// Background
|
cairo_set_source_u32(cairo, config->colors.focused_background);
|
||||||
if (is_focused) {
|
|
||||||
cairo_set_source_u32(cairo, config->colors.focused_background);
|
|
||||||
} else {
|
|
||||||
cairo_set_source_u32(cairo, config->colors.background);
|
|
||||||
}
|
|
||||||
cairo_paint(cairo);
|
|
||||||
|
|
||||||
// Command output
|
|
||||||
if (is_focused) {
|
|
||||||
cairo_set_source_u32(cairo, config->colors.focused_statusline);
|
|
||||||
} else {
|
|
||||||
cairo_set_source_u32(cairo, config->colors.statusline);
|
|
||||||
}
|
|
||||||
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
if (line->protocol == TEXT) {
|
|
||||||
get_text_size(window->cairo, window->font, &width, &height,
|
|
||||||
window->scale, config->pango_markup, "%s", line->text_line);
|
|
||||||
cairo_move_to(cairo, (window->width * window->scale)
|
|
||||||
- margin - width, margin);
|
|
||||||
pango_printf(window->cairo, window->font, window->scale,
|
|
||||||
config->pango_markup, "%s", line->text_line);
|
|
||||||
} else if (line->protocol == I3BAR && line->block_line) {
|
|
||||||
double pos = (window->width * window->scale) - 0.5;
|
|
||||||
bool edge = true;
|
|
||||||
for (i = line->block_line->length - 1; i >= 0; --i) {
|
|
||||||
struct status_block *block = line->block_line->items[i];
|
|
||||||
if (block->full_text && block->full_text[0]) {
|
|
||||||
render_block(window, config, block, &pos, edge, is_focused);
|
|
||||||
edge = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cairo_set_line_width(cairo, 1.0);
|
|
||||||
double x = 0.5;
|
|
||||||
|
|
||||||
// Workspaces
|
|
||||||
if (config->workspace_buttons) {
|
|
||||||
for (i = 0; i < output->workspaces->length; ++i) {
|
|
||||||
struct workspace *ws = output->workspaces->items[i];
|
|
||||||
render_workspace_button(window, config, ws, &x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// binding mode indicator
|
|
||||||
if (config->mode && config->binding_mode_indicator) {
|
|
||||||
render_binding_mode_indicator(window, config, x);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
cairo_set_source_u32(cairo, config->colors.background);
|
||||||
cairo_set_source_u32(cairo, 0x00000000);
|
}
|
||||||
cairo_paint(cairo);
|
cairo_paint(cairo);
|
||||||
|
|
||||||
|
// Command output
|
||||||
|
if (is_focused) {
|
||||||
|
cairo_set_source_u32(cairo, config->colors.focused_statusline);
|
||||||
|
} else {
|
||||||
|
cairo_set_source_u32(cairo, config->colors.statusline);
|
||||||
|
}
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
|
||||||
|
if (line->protocol == TEXT) {
|
||||||
|
get_text_size(window->cairo, window->font, &width, &height,
|
||||||
|
window->scale, config->pango_markup, "%s", line->text_line);
|
||||||
|
cairo_move_to(cairo, (window->width * window->scale)
|
||||||
|
- margin - width, margin);
|
||||||
|
pango_printf(window->cairo, window->font, window->scale,
|
||||||
|
config->pango_markup, "%s", line->text_line);
|
||||||
|
} else if (line->protocol == I3BAR && line->block_line) {
|
||||||
|
double pos = (window->width * window->scale) - 0.5;
|
||||||
|
bool edge = true;
|
||||||
|
for (i = line->block_line->length - 1; i >= 0; --i) {
|
||||||
|
struct status_block *block = line->block_line->items[i];
|
||||||
|
if (block->full_text && block->full_text[0]) {
|
||||||
|
render_block(window, config, block, &pos, edge, is_focused);
|
||||||
|
edge = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_set_line_width(cairo, 1.0);
|
||||||
|
double x = 0.5;
|
||||||
|
|
||||||
|
// Workspaces
|
||||||
|
if (config->workspace_buttons) {
|
||||||
|
for (i = 0; i < output->workspaces->length; ++i) {
|
||||||
|
struct workspace *ws = output->workspaces->items[i];
|
||||||
|
render_workspace_button(window, config, ws, &x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// binding mode indicator
|
||||||
|
if (config->mode && config->binding_mode_indicator) {
|
||||||
|
render_binding_mode_indicator(window, config, x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue