diff options
Diffstat (limited to 'sway/border.c')
-rw-r--r-- | sway/border.c | 138 |
1 files changed, 102 insertions, 36 deletions
diff --git a/sway/border.c b/sway/border.c index a6ed4238..ada5af2a 100644 --- a/sway/border.c +++ b/sway/border.c | |||
@@ -91,7 +91,7 @@ int get_font_text_height(const char *font) { | |||
91 | return height; | 91 | return height; |
92 | } | 92 | } |
93 | 93 | ||
94 | static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *colors) { | 94 | static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *colors, bool top) { |
95 | struct wlc_geometry *b = &view->border_geometry; | 95 | struct wlc_geometry *b = &view->border_geometry; |
96 | struct wlc_geometry *v = &view->actual_geometry; | 96 | struct wlc_geometry *v = &view->actual_geometry; |
97 | 97 | ||
@@ -118,7 +118,7 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col | |||
118 | 118 | ||
119 | // top border | 119 | // top border |
120 | int top_border = v->origin.y - b->origin.y; | 120 | int top_border = v->origin.y - b->origin.y; |
121 | if (top_border > 0) { | 121 | if (top && top_border > 0) { |
122 | render_sharp_line(cr, | 122 | render_sharp_line(cr, |
123 | colors->child_border, | 123 | colors->child_border, |
124 | 0, 0, | 124 | 0, 0, |
@@ -138,38 +138,69 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col | |||
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
141 | static void render_with_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) { | 141 | static void render_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) { |
142 | struct wlc_geometry *tb = &view->title_bar_geometry; | 142 | struct wlc_geometry *tb = &view->title_bar_geometry; |
143 | struct wlc_geometry *b = &view->border_geometry; | 143 | struct wlc_geometry *b = &view->border_geometry; |
144 | int title_y = MIN(view->actual_geometry.origin.y - (int)tb->size.h, 0); | 144 | int title_y = MIN(view->actual_geometry.origin.y - (int)tb->size.h, 0); |
145 | 145 | ||
146 | // borders | 146 | // borders |
147 | render_borders(view, cr, colors); | 147 | /* render_borders(view, cr, colors); */ |
148 | 148 | ||
149 | int x = tb->origin.x - b->origin.x; | ||
150 | int y = tb->origin.y - b->origin.y; | ||
151 | |||
152 | /* // title bar background */ | ||
153 | /* cairo_set_source_u32(cr, colors->child_border); */ | ||
154 | /* cairo_rectangle(cr, x, y, tb->size.w, tb->size.h); */ | ||
155 | /* cairo_fill(cr); */ | ||
149 | // title bar background | 156 | // title bar background |
150 | cairo_set_source_u32(cr, colors->background); | 157 | cairo_set_source_u32(cr, colors->background); |
151 | cairo_rectangle(cr, 0, title_y, tb->size.w, tb->size.h); | 158 | cairo_rectangle(cr, 0, title_y, tb->size.w, tb->size.h); |
152 | cairo_fill(cr); | 159 | cairo_fill(cr); |
153 | 160 | ||
154 | // header top line | 161 | // header top line |
162 | /* render_sharp_line(cr, colors->border, x, y, tb->size.w, 1); */ | ||
155 | render_sharp_line(cr, colors->border, 0, title_y, tb->size.w, 1); | 163 | render_sharp_line(cr, colors->border, 0, title_y, tb->size.w, 1); |
156 | 164 | ||
157 | // text | 165 | // text |
158 | if (view->name) { | 166 | if (view->name) { |
159 | int width, height; | 167 | int width, height; |
160 | get_text_size(cr, config->font, &width, &height, false, "%s", view->name); | 168 | get_text_size(cr, config->font, &width, &height, false, "%s", view->name); |
161 | int x = MIN(view->actual_geometry.origin.x, view->border_thickness); | 169 | int x_text = MIN(view->actual_geometry.origin.x, view->border_thickness); |
162 | int y = MIN(view->actual_geometry.origin.y - height - 2, 2); | 170 | int y_text = MIN(view->actual_geometry.origin.y - height - 2, 2); |
163 | cairo_move_to(cr, x, y); | 171 | cairo_move_to(cr, x_text, y_text); |
164 | cairo_set_source_u32(cr, colors->text); | 172 | cairo_set_source_u32(cr, colors->text); |
165 | pango_printf(cr, config->font, false, "%s", view->name); | 173 | pango_printf(cr, config->font, false, "%s", view->name); |
166 | } | 174 | } |
167 | 175 | ||
168 | // header bottom line | 176 | // titlebars has a border all around for tabbed layouts |
169 | render_sharp_line(cr, colors->border, | 177 | if (view->parent->layout == L_TABBED) { |
170 | view->actual_geometry.origin.x - b->origin.x, | 178 | // header bottom line |
171 | title_y + tb->size.h - 1, | 179 | render_sharp_line(cr, colors->border, x, y + tb->size.h - 1, |
172 | view->actual_geometry.size.w, 1); | 180 | tb->size.w, 1); |
181 | |||
182 | // left border | ||
183 | render_sharp_line(cr, colors->border, x, y, 1, tb->size.h); | ||
184 | |||
185 | // right border | ||
186 | render_sharp_line(cr, colors->border, x + tb->size.w - 1, y, | ||
187 | 1, tb->size.h); | ||
188 | |||
189 | return; | ||
190 | } | ||
191 | |||
192 | if ((uint32_t)(view->actual_geometry.origin.y - tb->origin.y) == tb->size.h) { | ||
193 | // header bottom line | ||
194 | render_sharp_line(cr, colors->border, | ||
195 | x + view->actual_geometry.origin.x - b->origin.x, | ||
196 | y + tb->size.h - 1, | ||
197 | view->actual_geometry.size.w, 1); | ||
198 | } else { | ||
199 | // header bottom line | ||
200 | render_sharp_line(cr, colors->border, x, | ||
201 | title_y + tb->size.h - 1, | ||
202 | tb->size.w, 1); | ||
203 | } | ||
173 | } | 204 | } |
174 | 205 | ||
175 | void map_update_view_border(swayc_t *view, void *data) { | 206 | void map_update_view_border(swayc_t *view, void *data) { |
@@ -179,6 +210,10 @@ void map_update_view_border(swayc_t *view, void *data) { | |||
179 | } | 210 | } |
180 | 211 | ||
181 | void update_view_border(swayc_t *view) { | 212 | void update_view_border(swayc_t *view) { |
213 | if (!view->visible) { | ||
214 | return; | ||
215 | } | ||
216 | |||
182 | cairo_t *cr = NULL; | 217 | cairo_t *cr = NULL; |
183 | cairo_surface_t *surface = NULL; | 218 | cairo_surface_t *surface = NULL; |
184 | 219 | ||
@@ -187,6 +222,7 @@ void update_view_border(swayc_t *view) { | |||
187 | view->border = NULL; | 222 | view->border = NULL; |
188 | } | 223 | } |
189 | 224 | ||
225 | // get focused and focused_intactive views | ||
190 | swayc_t *focused = get_focused_view(&root_container); | 226 | swayc_t *focused = get_focused_view(&root_container); |
191 | swayc_t *container = swayc_parent_by_type(view, C_CONTAINER); | 227 | swayc_t *container = swayc_parent_by_type(view, C_CONTAINER); |
192 | swayc_t *focused_inactive = NULL; | 228 | swayc_t *focused_inactive = NULL; |
@@ -199,40 +235,70 @@ void update_view_border(swayc_t *view) { | |||
199 | } | 235 | } |
200 | } | 236 | } |
201 | 237 | ||
202 | switch (view->border_type) { | 238 | swayc_t *p = view->parent; |
203 | case B_NONE: | ||
204 | break; | ||
205 | case B_PIXEL: | ||
206 | cr = create_border_buffer(view, view->border_geometry, &surface); | ||
207 | if (!cr) { | ||
208 | break; | ||
209 | } | ||
210 | 239 | ||
240 | if (p->layout == L_TABBED || p->layout == L_STACKED) { | ||
241 | cr = create_border_buffer(view, view->border_geometry, &surface); | ||
211 | if (focused == view) { | 242 | if (focused == view) { |
212 | render_borders(view, cr, &config->border_colors.focused); | 243 | render_borders(view, cr, &config->border_colors.focused, false); |
213 | } else if (focused_inactive == view) { | 244 | } else if (focused_inactive == view) { |
214 | render_borders(view, cr, &config->border_colors.focused_inactive); | 245 | render_borders(view, cr, &config->border_colors.focused_inactive, false); |
215 | } else { | 246 | } else { |
216 | render_borders(view, cr, &config->border_colors.unfocused); | 247 | render_borders(view, cr, &config->border_colors.unfocused, false); |
217 | } | 248 | } |
218 | 249 | ||
219 | break; | 250 | int i; |
220 | case B_NORMAL: | 251 | for (i = 0; i < p->children->length; ++i) { |
221 | cr = create_border_buffer(view, view->border_geometry, &surface); | 252 | swayc_t *child = p->children->items[i]; |
222 | if (!cr) { | ||
223 | break; | ||
224 | } | ||
225 | 253 | ||
226 | if (focused == view) { | 254 | if (focused == child) { |
227 | render_with_title_bar(view, cr, &config->border_colors.focused); | 255 | render_title_bar(child, cr, &config->border_colors.focused); |
228 | } else if (focused_inactive == view) { | 256 | } else if (focused_inactive == child) { |
229 | render_with_title_bar(view, cr, &config->border_colors.focused_inactive); | 257 | render_title_bar(child, cr, &config->border_colors.focused_inactive); |
230 | } else { | 258 | } else { |
231 | render_with_title_bar(view, cr, &config->border_colors.unfocused); | 259 | render_title_bar(child, cr, &config->border_colors.unfocused); |
260 | } | ||
232 | } | 261 | } |
262 | } else { | ||
263 | switch (view->border_type) { | ||
264 | case B_NONE: | ||
265 | break; | ||
266 | case B_PIXEL: | ||
267 | cr = create_border_buffer(view, view->border_geometry, &surface); | ||
268 | if (!cr) { | ||
269 | break; | ||
270 | } | ||
271 | |||
272 | if (focused == view) { | ||
273 | render_borders(view, cr, &config->border_colors.focused, true); | ||
274 | } else if (focused_inactive == view) { | ||
275 | render_borders(view, cr, &config->border_colors.focused_inactive, true); | ||
276 | } else { | ||
277 | render_borders(view, cr, &config->border_colors.unfocused, true); | ||
278 | } | ||
233 | 279 | ||
234 | break; | 280 | break; |
281 | case B_NORMAL: | ||
282 | cr = create_border_buffer(view, view->border_geometry, &surface); | ||
283 | if (!cr) { | ||
284 | break; | ||
285 | } | ||
286 | |||
287 | if (focused == view) { | ||
288 | render_borders(view, cr, &config->border_colors.focused, false); | ||
289 | render_title_bar(view, cr, &config->border_colors.focused); | ||
290 | } else if (focused_inactive == view) { | ||
291 | render_borders(view, cr, &config->border_colors.focused_inactive, false); | ||
292 | render_title_bar(view, cr, &config->border_colors.focused_inactive); | ||
293 | } else { | ||
294 | render_borders(view, cr, &config->border_colors.unfocused, false); | ||
295 | render_title_bar(view, cr, &config->border_colors.unfocused); | ||
296 | } | ||
297 | |||
298 | break; | ||
299 | } | ||
235 | } | 300 | } |
301 | |||
236 | if (surface) { | 302 | if (surface) { |
237 | cairo_surface_flush(surface); | 303 | cairo_surface_flush(surface); |
238 | cairo_surface_destroy(surface); | 304 | cairo_surface_destroy(surface); |