fixup! Add display server.

This commit is contained in:
Jonas 'Sortie' Termansen 2023-06-20 01:13:29 +02:00
parent 9afe0e6946
commit caa156a59e
6 changed files with 38 additions and 10 deletions

View File

@ -30,6 +30,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <timespec.h>
#include <display-protocol.h>
@ -346,6 +348,7 @@ void display_composit(struct display* display, struct framebuffer fb)
switch ( display->mouse_state )
{
case MOUSE_STATE_NONE: break;
case MOUSE_STATE_IGNORE: break;
case MOUSE_STATE_BUTTON_PRESS: break;
case MOUSE_STATE_TITLE_MOVE: break;
case MOUSE_STATE_RESIZE_BOTTOM: cursor_text = ""; break;
@ -693,7 +696,8 @@ void display_mouse_event(struct display* display, uint8_t byte)
window_render_frame(window);
}
else if ( display->mouse_state == MOUSE_STATE_BUTTON_PRESS &&
window->button_states[n] == BUTTON_STATE_PRESSED )
window->button_states[n] == BUTTON_STATE_PRESSED &&
!(bytes[0] & MOUSE_BUTTON_LEFT) )
{
window->button_states[n] = BUTTON_STATE_NORMAL;
window_render_frame(window);
@ -715,20 +719,40 @@ void display_mouse_event(struct display* display, uint8_t byte)
else if ( window->button_states[n] != BUTTON_STATE_NORMAL )
{
window->button_states[n] = BUTTON_STATE_NORMAL;
display->mouse_state = MOUSE_STATE_NONE;
if ( display->mouse_state != MOUSE_STATE_NONE )
display->mouse_state = MOUSE_STATE_IGNORE;
window_render_frame(window);
}
}
struct timespec double_click = timespec_make(0, 500000000);
if ( bytes[0] & MOUSE_BUTTON_LEFT )
{
if ( display->mouse_state == MOUSE_STATE_NONE )
if ( (display->mouse_state == MOUSE_STATE_NONE) )
{
// TODO: Stay in state until mouse release.
if ( display->key_lalt || mouse_on_title )
if ( display->key_lalt )
display->mouse_state = MOUSE_STATE_TITLE_MOVE;
else if ( mouse_on_title && window_pointer_x < buttons_x )
{
if ( window_pointer_x < buttons_x || !mouse_on_title )
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct timespec elapsed =
timespec_sub(now, window->title_click_time);
if ( 0 <= window->title_click_time.tv_sec &&
timespec_le(elapsed, double_click) )
{
display->mouse_state = MOUSE_STATE_IGNORE;
window_toggle_maximized(window);
}
else
{
// TODO: Reset this if clicked anywhere else or if the
// active window changes.
window->title_click_time = now;
display->mouse_state = MOUSE_STATE_TITLE_MOVE;
}
}
else if ( window_pointer_x < 0 && window_pointer_y < 0 )
display->mouse_state = MOUSE_STATE_RESIZE_TOP_LEFT;
@ -769,6 +793,7 @@ void display_mouse_event(struct display* display, uint8_t byte)
switch ( display->mouse_state )
{
case MOUSE_STATE_NONE: break;
case MOUSE_STATE_IGNORE: break;
case MOUSE_STATE_BUTTON_PRESS: break;
case MOUSE_STATE_TITLE_MOVE:
if ( clipped_edge )
@ -847,9 +872,7 @@ void display_mouse_event(struct display* display, uint8_t byte)
// TODO: Leave mouse state if the top window is switched.
}
else
{
display->mouse_state = MOUSE_STATE_NONE;
}
}
void display_on_resolution_change(struct display* display, size_t width,

View File

@ -81,6 +81,8 @@ Clicking on a window brings it to the foreground.
.It
Dragging the window title bar moves the window.
.It
Double clicking on the window title bar maximizes (or restores) the window.
.It
Clicking on the rectangle icon in the title bar maximizes (or restores) the
window.
.It

View File

@ -32,6 +32,7 @@
enum mouse_state
{
MOUSE_STATE_NONE,
MOUSE_STATE_IGNORE,
MOUSE_STATE_BUTTON_PRESS,
MOUSE_STATE_TITLE_MOVE,
MOUSE_STATE_RESIZE_BOTTOM,

View File

@ -23,6 +23,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <timespec.h>
#include <display-protocol.h>
@ -289,7 +290,7 @@ void window_initialize(struct window* window,
window->created = true;
window->connection = connection;
window->display = display;
window->title = NULL;
window->title_click_time = timespec_make(-1, 0);
window->window_id = window_id;
display_add_window(window->display, window);
window->top = next_window_position;
@ -304,7 +305,7 @@ void window_initialize(struct window* window,
void window_quit(struct window* window)
{
struct event_keyboard event;
struct event_quit event;
event.window_id = window->window_id;
struct display_packet_header header;

View File

@ -64,6 +64,7 @@ struct window
struct window* above_window;
struct window* below_window;
struct framebuffer buffer;
struct timespec title_click_time;
char* title;
ssize_t left;
ssize_t top;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015, 2016, 2017 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2015, 2016, 2017, 2023 Jonas 'Sortie' Termansen.
* Copyright (c) 2023 Juhani 'nortti' Krekelä.
*
* Permission to use, copy, modify, and distribute this software for any