Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Weston server decoration to look better in WSLg #129

Draft
wants to merge 1 commit into
base: working
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions clients/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,18 +1613,12 @@ window_destroy(struct window *window)
}

static struct widget *
widget_find_widget(struct widget *widget, int32_t x, int32_t y)
widget_find_widget(struct widget *widget, int32_t x, int32_t y, bool get_parent)
{
struct widget *child, *target;
int alloc_x, alloc_y, width, height;
double scale;

wl_list_for_each(child, &widget->child_list, link) {
target = widget_find_widget(child, x, y);
if (target)
return target;
}

alloc_x = widget->allocation.x;
alloc_y = widget->allocation.y;
width = widget->allocation.width;
Expand All @@ -1641,6 +1635,15 @@ widget_find_widget(struct widget *widget, int32_t x, int32_t y)
height = widget->viewport_dest_height;
}

wl_list_for_each(child, &widget->child_list, link) {
target = widget_find_widget(child, x, y, get_parent);
if (target && get_parent) {
return widget;
} else if(target) {
return target;
}
}

if (alloc_x <= x && x < alloc_x + width &&
alloc_y <= y && y < alloc_y + height) {
return widget;
Expand All @@ -1650,13 +1653,13 @@ widget_find_widget(struct widget *widget, int32_t x, int32_t y)
}

static struct widget *
window_find_widget(struct window *window, int32_t x, int32_t y)
window_find_widget(struct window *window, int32_t x, int32_t y, bool get_parent)
{
struct surface *surface;
struct widget *widget;

wl_list_for_each(surface, &window->subsurface_list, link) {
widget = widget_find_widget(surface->widget, x, y);
widget = widget_find_widget(surface->widget, x, y, get_parent);
if (widget)
return widget;
}
Expand Down Expand Up @@ -2711,7 +2714,7 @@ input_ungrab(struct input *input)
input->grab = NULL;
if (input->pointer_focus) {
widget = window_find_widget(input->pointer_focus,
input->sx, input->sy);
input->sx, input->sy, false);
input_set_focus_widget(input, widget, input->sx, input->sy);
}
}
Expand Down Expand Up @@ -2777,8 +2780,19 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
input->sx = sx;
input->sy = sy;

widget = window_find_widget(window, sx, sy);
widget = window_find_widget(window, sx, sy, false);
input_set_focus_widget(input, widget, sx, sy);
widget = window_find_widget(window, sx, sy, true);

if (widget) {
if (widget->motion_handler) {
if(widget->motion_handler(input->focus_widget,
input, time, sx, sy,
widget->user_data) != CURSOR_LEFT_PTR) {
input_set_focus_widget(input, widget, sx, sy);
}
}
}
}

static void
Expand All @@ -2798,7 +2812,7 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
struct input *input = data;
struct window *window = input->pointer_focus;
struct widget *widget;
int cursor;
int cursor, parent_cursor;
float sx = wl_fixed_to_double(sx_w);
float sy = wl_fixed_to_double(sy_w);

Expand All @@ -2820,7 +2834,7 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
return;

if (!(input->grab && input->grab_button)) {
widget = window_find_widget(window, sx, sy);
widget = window_find_widget(window, sx, sy, false);
input_set_focus_widget(input, widget, sx, sy);
}

Expand All @@ -2838,6 +2852,21 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
} else
cursor = CURSOR_LEFT_PTR;


widget = window_find_widget(window, sx, sy, true);

if (widget) {
if (widget->motion_handler) {
parent_cursor = widget->motion_handler(input->focus_widget,
input, time, sx, sy,
widget->user_data);
if(parent_cursor != CURSOR_LEFT_PTR) {
input_set_focus_widget(input, widget, sx, sy);
cursor = parent_cursor;
}
}
}

input_set_pointer_image(input, cursor);
}

Expand Down Expand Up @@ -3320,7 +3349,7 @@ touch_handle_down(void *data, struct wl_touch *wl_touch,
else
widget = window_find_widget(input->touch_focus,
wl_fixed_to_double(x_w),
wl_fixed_to_double(y_w));
wl_fixed_to_double(y_w), false);
if (widget) {
struct touch_point *tp = xmalloc(sizeof *tp);
if (tp) {
Expand Down
Binary file modified data/sign_close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/sign_maximize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/sign_minimize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions shared/cairo-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ theme_create(void)
if (t == NULL)
return NULL;

t->margin = 32;
t->width = 6;
t->titlebar_height = 27;
t->margin = 20;
t->width = 0;
t->titlebar_height = 28;
t->frame_radius = 3;
t->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
cr = cairo_create(t->shadow);
Expand Down
47 changes: 20 additions & 27 deletions shared/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ frame_button_cancel(struct frame_button *button)
}

static void
frame_button_repaint(struct frame_button *button, cairo_t *cr)
frame_button_repaint(struct frame_button *button, cairo_t *cr, uint32_t flags)
{
int x, y;

Expand All @@ -224,24 +224,30 @@ frame_button_repaint(struct frame_button *button, cairo_t *cr)
cairo_save(cr);

if (button->flags & FRAME_BUTTON_DECORATED) {
cairo_set_line_width(cr, 1);
cairo_set_line_width(cr, 0);

cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
cairo_rectangle(cr, x, y, 25, 16);
cairo_rectangle(cr, x, y, 42, 28);

cairo_stroke_preserve(cr);

if (button->press_count) {
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
} else if (button->hover_count) {
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
} else if (button->hover_count) {
if(button->status_effect == FRAME_STATUS_CLOSE) {
cairo_set_source_rgb(cr, 0.768, 0.184, 0.109);
} else {
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
}
} else {
cairo_set_source_rgb(cr, 0.88, 0.88, 0.88);
if (flags & THEME_FRAME_ACTIVE) {
cairo_set_source_rgb(cr, 0.941, 0.953, 0.976);
} else {
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
}
}

cairo_fill (cr);

x += 4;
}

cairo_set_source_surface(cr, button->icon, x, y);
Expand Down Expand Up @@ -357,17 +363,6 @@ frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons,
icon,
FRAME_STATUS_MENU,
FRAME_BUTTON_CLICK_DOWN);
} else {
char *name = file_name_with_datadir("icon_window.png");

if (!name)
goto free_frame;

button = frame_button_create(frame,
name,
FRAME_STATUS_MENU,
FRAME_BUTTON_CLICK_DOWN);
free(name);
}
if (!button)
goto free_frame;
Expand Down Expand Up @@ -585,27 +580,25 @@ frame_refresh_geometry(struct frame *frame)
x_l = t->width + frame->shadow_margin;
y = t->width + frame->shadow_margin;
wl_list_for_each(button, &frame->buttons, link) {
const int button_padding = 4;
const int button_padding = 0;
w = cairo_image_surface_get_width(button->icon);
h = cairo_image_surface_get_height(button->icon);

if (button->flags & FRAME_BUTTON_DECORATED)
w += 10;

if (button->flags & FRAME_BUTTON_ALIGN_RIGHT) {
x_r -= w;

button->allocation.x = x_r;
button->allocation.y = y;
button->allocation.width = w + 1;
button->allocation.height = h + 1;
button->allocation.width = w;
button->allocation.height = h;

x_r -= button_padding;
} else {
button->allocation.x = x_l;
button->allocation.y = y;
button->allocation.width = w + 1;
button->allocation.height = h + 1;
button->allocation.width = w;
button->allocation.height = h;

x_l += w;
x_l += button_padding;
Expand Down Expand Up @@ -1028,7 +1021,7 @@ frame_repaint(struct frame *frame, cairo_t *cr)
cairo_restore(cr);

wl_list_for_each(button, &frame->buttons, link)
frame_button_repaint(button, cr);
frame_button_repaint(button, cr, flags);

frame_status_clear(frame, FRAME_STATUS_REPAINT);
}