aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/border.c13
-rw-r--r--sway/commands.c80
-rw-r--r--sway/layout.c44
3 files changed, 122 insertions, 15 deletions
diff --git a/sway/border.c b/sway/border.c
index acabc8e0..6343ddd0 100644
--- a/sway/border.c
+++ b/sway/border.c
@@ -139,23 +139,26 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col
static void render_with_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) {
struct wlc_geometry *tb = &view->title_bar_geometry;
struct wlc_geometry *b = &view->border_geometry;
+ int title_y = MIN(view->actual_geometry.origin.y - (int)tb->size.h, 0);
// borders
render_borders(view, cr, colors);
// title bar background
- cairo_set_source_u32(cr, colors->child_border);
- cairo_rectangle(cr, 0, 0, tb->size.w, tb->size.h);
+ cairo_set_source_u32(cr, colors->background);
+ cairo_rectangle(cr, 0, title_y, tb->size.w, tb->size.h);
cairo_fill(cr);
// header top line
- render_sharp_line(cr, colors->border, 0, 0, tb->size.w, 1);
+ render_sharp_line(cr, colors->border, 0, title_y, tb->size.w, 1);
// text
if (view->name) {
int width, height;
get_text_size(cr, config->font, &width, &height, "%s", view->name);
- cairo_move_to(cr, view->border_thickness, 2);
+ int x = MIN(view->actual_geometry.origin.x, view->border_thickness);
+ int y = MIN(view->actual_geometry.origin.y - height - 2, 2);
+ cairo_move_to(cr, x, y);
cairo_set_source_u32(cr, colors->text);
pango_printf(cr, config->font, "%s", view->name);
}
@@ -163,7 +166,7 @@ static void render_with_title_bar(swayc_t *view, cairo_t *cr, struct border_colo
// header bottom line
render_sharp_line(cr, colors->border,
view->actual_geometry.origin.x - b->origin.x,
- tb->size.h - 1,
+ title_y + tb->size.h - 1,
view->actual_geometry.size.w, 1);
}
diff --git a/sway/commands.c b/sway/commands.c
index c1009f85..b7c1a344 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -45,6 +45,12 @@ static sway_cmd cmd_bar;
static sway_cmd cmd_bindcode;
static sway_cmd cmd_bindsym;
static sway_cmd cmd_border;
+static sway_cmd cmd_client_focused;
+static sway_cmd cmd_client_focused_inactive;
+static sway_cmd cmd_client_unfocused;
+static sway_cmd cmd_client_urgent;
+static sway_cmd cmd_client_placeholder;
+static sway_cmd cmd_client_background;
static sway_cmd cmd_debuglog;
static sway_cmd cmd_exec;
static sway_cmd cmd_exec_always;
@@ -113,6 +119,8 @@ static sway_cmd bar_colors_cmd_separator;
static sway_cmd bar_colors_cmd_statusline;
static sway_cmd bar_colors_cmd_urgent_workspace;
+static struct cmd_results *add_color(const char*, char*, const char*);
+
swayc_t *sp_view;
int sp_index = 0;
@@ -408,6 +416,71 @@ static struct cmd_results *cmd_border(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
+static struct cmd_results *parse_border_color(struct border_colors *border_colors, const char *cmd_name, int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if (argc != 5) {
+ return cmd_results_new(CMD_INVALID, cmd_name, "Requires exact 5 color values");
+ }
+
+ uint32_t colors[5];
+ int i;
+ for (i = 0; i < 5; i++) {
+ char buffer[10];
+ error = add_color(cmd_name, buffer, argv[i]);
+ if (error) {
+ return error;
+ }
+ colors[i] = strtoul(buffer+1, NULL, 16);
+ }
+
+ border_colors->border = colors[0];
+ border_colors->background = colors[1];
+ border_colors->text = colors[2];
+ border_colors->indicator = colors[3];
+ border_colors->child_border = colors[4];
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+static struct cmd_results *cmd_client_focused(int argc, char **argv) {
+ return parse_border_color(&config->border_colors.focused, "client.focused", argc, argv);
+}
+
+static struct cmd_results *cmd_client_focused_inactive(int argc, char **argv) {
+ return parse_border_color(&config->border_colors.focused_inactive, "client.focused_inactive", argc, argv);
+}
+
+static struct cmd_results *cmd_client_unfocused(int argc, char **argv) {
+ return parse_border_color(&config->border_colors.unfocused, "client.unfocused", argc, argv);
+}
+
+static struct cmd_results *cmd_client_urgent(int argc, char **argv) {
+ return parse_border_color(&config->border_colors.urgent, "client.urgent", argc, argv);
+}
+
+static struct cmd_results *cmd_client_placeholder(int argc, char **argv) {
+ return parse_border_color(&config->border_colors.placeholder, "client.placeholder", argc, argv);
+}
+
+static struct cmd_results *cmd_client_background(int argc, char **argv) {
+ char buffer[10];
+ struct cmd_results *error = NULL;
+ uint32_t background;
+
+ if (argc != 1) {
+ return cmd_results_new(CMD_INVALID, "client.background", "Expect exact 1 value");
+ }
+
+ error = add_color("client.background", buffer, argv[0]);
+ if (error) {
+ return error;
+ }
+
+ background = strtoul(buffer+1, NULL, 16);
+ config->border_colors.background = background;
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
static struct cmd_results *cmd_exec_always(int argc, char **argv) {
struct cmd_results *error = NULL;
if (!config->active) return cmd_results_new(CMD_DEFER, NULL, NULL);
@@ -2211,6 +2284,12 @@ static struct cmd_handler handlers[] = {
{ "bindcode", cmd_bindcode },
{ "bindsym", cmd_bindsym },
{ "border", cmd_border },
+ { "client.background", cmd_client_background },
+ { "client.focused", cmd_client_focused },
+ { "client.focused_inactive", cmd_client_focused_inactive },
+ { "client.placeholder", cmd_client_placeholder },
+ { "client.unfocused", cmd_client_unfocused },
+ { "client.urgent", cmd_client_urgent },
{ "debuglog", cmd_debuglog },
{ "default_orientation", cmd_orientation },
{ "exec", cmd_exec },
@@ -2821,7 +2900,6 @@ static struct cmd_results *add_color(const char *name, char *buffer, const char
buffer[7] = 'f';
buffer[8] = 'f';
}
- sway_log(L_DEBUG, "Setting %s color %s for bar: %s", name, buffer, config->current_bar->id);
return NULL;
}
diff --git a/sway/layout.c b/sway/layout.c
index b1139b1b..344ca647 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -374,25 +374,50 @@ void move_workspace_to(swayc_t* workspace, swayc_t* destination) {
update_visibility(src_op);
}
+static void adjust_border_geometry(swayc_t *c, struct wlc_geometry *g,
+ const struct wlc_size *res, int left, int right, int top, int bottom) {
+
+ g->size.w += left + right;
+ if (g->origin.x - left < 0) {
+ g->size.w += g->origin.x - left;
+ }
+ else if (g->origin.x + g->size.w - right > res->w) {
+ g->size.w = res->w - g->origin.x + right;
+ }
+
+ g->size.h += top + bottom;
+ if (g->origin.y - top < 0) {
+ g->size.h += g->origin.y - top;
+ }
+ else if (g->origin.y + g->size.h - top > res->h) {
+ g->size.h = res->h - g->origin.y + top;
+ }
+
+ g->origin.x = MIN(MAX( g->origin.x - left, 0), res->w);
+ g->origin.y = MIN(MAX( g->origin.y - top, 0), res->h);
+
+}
+
static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geometry) {
struct wlc_geometry g = *geometry;
c->actual_geometry = g;
+
+ swayc_t *output = swayc_parent_by_type(c, C_OUTPUT);
+ const struct wlc_size *res = wlc_output_get_resolution(output->handle);
switch (c->border_type) {
case B_NONE:
break;
case B_PIXEL:
- g.origin.x -= c->border_thickness;
- g.origin.y -= c->border_thickness;
- g.size.w += (c->border_thickness * 2);
- g.size.h += (c->border_thickness * 2);
+ adjust_border_geometry(c, &g, res, c->border_thickness,
+ c->border_thickness, c->border_thickness, c->border_thickness);
break;
case B_NORMAL:
- g.origin.x -= c->border_thickness;
- uint32_t title_bar_height = config->font_height + 4; // borders + padding
- g.origin.y -= title_bar_height;
- g.size.w += (c->border_thickness * 2);
- g.size.h += (c->border_thickness + title_bar_height);
+ {
+ int title_bar_height = config->font_height + 4; // borders + padding
+
+ adjust_border_geometry(c, &g, res, c->border_thickness,
+ c->border_thickness, title_bar_height, c->border_thickness);
struct wlc_geometry title_bar = {
.origin = {
@@ -407,6 +432,7 @@ static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geo
c->title_bar_geometry = title_bar;
break;
}
+ }
c->border_geometry = g;
*geometry = c->actual_geometry;