fixup! Add display server.

This commit is contained in:
Jonas 'Sortie' Termansen 2023-06-21 21:59:06 +02:00
parent caa156a59e
commit f5ef1e734b
3 changed files with 39 additions and 55 deletions

View File

@ -669,12 +669,16 @@ void display_mouse_event(struct display* display, uint8_t byte)
return;
}
size_t border_width = window_border_width(window);
size_t button_width = FONT_WIDTH * 2;
ssize_t buttons_x = window->width - border_width
- button_width * 3 + 1;
size_t tt_height = FONT_HEIGHT;
size_t tt_pos_y = (TITLE_HEIGHT - FONT_HEIGHT) / 2 + 2;
bool maximized = window->window_state != WINDOW_STATE_REGULAR;
int b2 = 2;
int t0 = TITLE_HEIGHT;
size_t border_width = maximized ? 0 : b2 + 1;
size_t button_area_height = maximized ? t0 : t0 - (b2 + 1);
size_t button_area_width = button_area_height;
size_t button_area_top = maximized ? 0 : b2;
ssize_t buttons_x = window->width - border_width - button_area_width*3 + 1;
bool mouse_on_title = 0 <= window_pointer_x &&
window_pointer_x < (ssize_t) window->width &&
@ -683,10 +687,13 @@ void display_mouse_event(struct display* display, uint8_t byte)
for ( size_t n = 0; n < 3; n++ )
{
if ( (ssize_t) tt_pos_y <= window_pointer_y &&
window_pointer_y <= (ssize_t) (tt_height + tt_pos_y) &&
(ssize_t) (button_width * n) <= window_pointer_x - buttons_x &&
window_pointer_x - buttons_x < (ssize_t) (button_width * (n + 1)) )
ssize_t bottom = button_area_top + button_area_height;
ssize_t left = button_area_width * n;
ssize_t right = button_area_width * (n + 1);
if ( (ssize_t) button_area_top <= window_pointer_y &&
window_pointer_y <= bottom &&
left <= window_pointer_x - buttons_x &&
window_pointer_x - buttons_x < right )
{
if ( display->mouse_state == MOUSE_STATE_NONE &&
(bytes[0] & MOUSE_BUTTON_LEFT) )

View File

@ -78,7 +78,7 @@ void window_render_frame(struct window* window)
for ( size_t x = start_x; x <= end_x; x++ )
{
uint32_t color;
if ( maximized && y <= start_y + t0 )
if ( maximized && y < start_y + t0 )
color = glass_color;
else if ( maximized )
continue;
@ -89,7 +89,7 @@ void window_render_frame(struct window* window)
y == start_y + b1 || y == end_y - b1 )
color = make_color_a(0, 0, 0, 64);
else if ( x == start_x + b2 || x == end_x - b2 ||
y == start_y + b2 ||+ y == end_y - b2 )
y == start_y + b2 || y == end_y - b2 )
color = make_color(240, 240, 250);
else if ( x < start_x + (b3-1) || x > end_x - (b3-1) ||
y < start_y + (t0-1) || y > end_y - (b3-1) )
@ -109,25 +109,17 @@ void window_render_frame(struct window* window)
size_t tt_pos_y = (TITLE_HEIGHT - FONT_HEIGHT) / 2 + 2;
uint32_t tt_color = title_color;
size_t border_width = window_border_width(window);
size_t button_width = FONT_WIDTH * 2;
size_t button_height = FONT_HEIGHT;
ssize_t buttons_x = window->width - border_width - button_width * 3 + 1;
struct framebuffer buttons_fb =
framebuffer_crop(window->buffer, buttons_x,
tt_pos_y, button_width * 3, tt_height);
size_t border_width = maximized ? 0 : b2 + 1;
size_t button_area_height = maximized ? t0 : t0 - (b2 + 1);
size_t button_area_width = button_area_height;
size_t button_area_top = maximized ? 0 : b2;
size_t button_size = FONT_WIDTH - 1;
#if 0
for (size_t x = 0; x < button_width; x++)
for (size_t y = 0; y < button_height; y++)
framebuffer_set_pixel(buttons_fb, button_width * 0 + x, y, 0xFF8080FF);
for (size_t x = 0; x < button_width; x++)
for (size_t y = 0; y < button_height; y++)
framebuffer_set_pixel(buttons_fb, button_width * 1 + x, y, 0xFFFF8080);
for (size_t x = 0; x < button_width; x++)
for (size_t y = 0; y < button_height; y++)
framebuffer_set_pixel(buttons_fb, button_width * 2 + x, y, 0xFF8080FF);
#endif
size_t button_top = (button_area_height - button_size + 1) / 2;
size_t button_left = (button_area_width - button_size + 1) / 2;
ssize_t buttons_x = window->width - border_width - button_area_width*3 + 1;
struct framebuffer buttons_fb =
framebuffer_crop(window->buffer, buttons_x, button_area_top,
button_area_width * 3, button_area_height);
for ( size_t n = 0; n < 3; n++ )
{
uint32_t color = glass_color;
@ -137,16 +129,16 @@ void window_render_frame(struct window* window)
case BUTTON_STATE_HOVER: color = button_hover_glass; break;
case BUTTON_STATE_PRESSED: color = button_press_glass; break;
}
size_t bx = button_width * n;
size_t bx = button_area_width * n;
size_t by = 0;
for ( size_t y = 0; y < tt_height; y++ )
for ( size_t x = 0; x < button_width; x++ )
for ( size_t y = 0; y < button_area_height; y++ )
for ( size_t x = 0; x < button_area_width; x++ )
framebuffer_set_pixel(buttons_fb, bx + x, by + y, color);
}
for ( size_t i = 0; i < button_size; i++ )
{
size_t bx = button_width * 0 + (button_width - button_size) / 2;
size_t by = (button_height - button_size) / 2;
size_t bx = button_area_width * 0 + button_left;
size_t by = button_top;
framebuffer_set_pixel(buttons_fb, bx + i,
by + button_size - 1, tt_color);
framebuffer_set_pixel(buttons_fb, bx + i,
@ -154,8 +146,8 @@ void window_render_frame(struct window* window)
}
for ( size_t i = 0; i < button_size; i++ )
{
size_t bx = button_width * 1 + (button_width - button_size) / 2;
size_t by = (button_height - button_size) / 2;
size_t bx = button_area_width * 1 + button_left;
size_t by = button_top;
framebuffer_set_pixel(buttons_fb, bx + i,
by, tt_color);
framebuffer_set_pixel(buttons_fb, bx + i,
@ -176,8 +168,8 @@ void window_render_frame(struct window* window)
}
for ( size_t i = 0; i < button_size; i++ )
{
size_t bx = button_width * 2 + (button_width - button_size) / 2;
size_t by = (button_height - button_size) / 2;
size_t bx = button_area_width * 2 + button_left;
size_t by = button_top;
framebuffer_set_pixel(buttons_fb, bx + i,
by + i, tt_color);
framebuffer_set_pixel(buttons_fb, bx + i,
@ -193,16 +185,8 @@ void window_render_frame(struct window* window)
ssize_t q_width = 200;
q = q < q_width ? q : q_width;
q = 0 < q ? q : 0;
ssize_t center_over = window->width - (button_width * 3 * q / q_width);
ssize_t center_over = window->width - (button_area_width * 3 * q / q_width);
ssize_t tt_pos_x = (center_over - tt_width) / 2;
#if 0
for (int y = 0; y < 10; y++)
{
framebuffer_set_pixel(window->buffer, window->width / 2, y, 0xFFFF0000);
framebuffer_set_pixel(window->buffer, (window->width - button_width * 3) / 2, y, 0xFFFF0000);
framebuffer_set_pixel(window->buffer, center_over/2, y, 0xFFFF00FF);
}
#endif
if ( tt_pos_x < (ssize_t)border_width )
{
tt_pos_x = border_width;
@ -559,9 +543,3 @@ void window_notify_client_resize(struct window* window)
connection_schedule_transmit(window->connection, &header, sizeof(header));
connection_schedule_transmit(window->connection, &event, sizeof(event));
}
size_t window_border_width(const struct window* window)
{
bool maximized = window->window_state != WINDOW_STATE_REGULAR;
return maximized ? BORDER_WIDTH / 2 : BORDER_WIDTH;
}

View File

@ -114,6 +114,5 @@ void window_tile_bottom(struct window* window);
void window_tile_bottom_left(struct window* window);
void window_tile_bottom_right(struct window* window);
void window_notify_client_resize(struct window* window);
size_t window_border_width(const struct window* window);
#endif