2012-02-12 04:54:34 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
|
|
|
* Compositing and Window Management Library
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMPOSITING_H
|
|
|
|
#define COMPOSITING_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "list.h"
|
|
|
|
#include "graphics.h"
|
2012-10-15 06:53:16 +04:00
|
|
|
#include "kbd.h"
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
/* Connection */
|
|
|
|
typedef struct {
|
|
|
|
/* Control flow structures */
|
|
|
|
volatile uint8_t lock; /* Spinlock byte */
|
|
|
|
|
|
|
|
/* LOCK REQUIRED REGION */
|
|
|
|
volatile uint8_t client_done; /* Client has finished work */
|
|
|
|
volatile uint8_t server_done; /* Server has finished work */
|
|
|
|
|
|
|
|
/* The actual data passed back and forth */
|
|
|
|
pid_t client_pid; /* Actively communicating client process */
|
|
|
|
uintptr_t event_pipe; /* Client event pipe (ie, mouse, keyboard) */
|
|
|
|
uintptr_t command_pipe; /* Client command pipe (ie, resize) */
|
|
|
|
/* END LOCK REQUIRED REGION */
|
|
|
|
|
|
|
|
/* Data about the system */
|
|
|
|
pid_t server_pid; /* The wins -- for signals */
|
|
|
|
uint16_t server_width; /* Screen resolution, width */
|
|
|
|
uint16_t server_height; /* Screen resolution, height */
|
|
|
|
uint8_t server_depth; /* Native screen depth (in bits) */
|
|
|
|
|
|
|
|
uint32_t magic;
|
|
|
|
} wins_server_global_t;
|
|
|
|
|
|
|
|
|
|
|
|
/* Commands and Events */
|
|
|
|
typedef struct {
|
2012-02-21 09:31:00 +04:00
|
|
|
uint32_t magic;
|
2012-02-12 04:54:34 +04:00
|
|
|
uint8_t command_type; /* Command or event specifier */
|
|
|
|
size_t packet_size; /* Size of the *remaining* packet data */
|
|
|
|
} wins_packet_t;
|
|
|
|
|
|
|
|
#define WINS_PACKET(p) ((char *)((uintptr_t)p + sizeof(wins_packet_t)))
|
|
|
|
|
|
|
|
#define WINS_SERVER_IDENTIFIER "sys.compositor"
|
|
|
|
#define WINS_MAGIC 0xDECADE99
|
|
|
|
|
|
|
|
|
|
|
|
/* Commands */
|
|
|
|
#define WC_NEWWINDOW 0x00 /* New Window */
|
|
|
|
#define WC_RESIZE 0x01 /* Resize and move an existing window */
|
|
|
|
#define WC_DESTROY 0x02 /* Destroy an existing window */
|
|
|
|
#define WC_DAMAGE 0x03 /* Damage window (redraw region) */
|
2012-03-02 07:13:52 +04:00
|
|
|
#define WC_REDRAW 0x04 /* Damage window (redraw region) */
|
2012-03-08 08:31:24 +04:00
|
|
|
#define WC_REORDER 0x05 /* Set the Z-index for a window (request) */
|
2012-09-14 09:12:47 +04:00
|
|
|
#define WC_SET_ALPHA 0x06 /* Enable RGBA for compositing */
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
/* Events */
|
|
|
|
#define WE_KEYDOWN 0x10 /* A key has been pressed down */
|
|
|
|
#define WE_KEYUP 0x11 /* RESERVED: Key up [UNUSED] */
|
|
|
|
#define WE_MOUSEMOVE 0x20 /* The mouse has moved (to the given coordinates) */
|
|
|
|
#define WE_MOUSEENTER 0x21 /* The mouse has entered your window (at the given coordinates) */
|
|
|
|
#define WE_MOUSELEAVE 0x22 /* The mouse has left your window (at the given coordinates) */
|
|
|
|
#define WE_MOUSECLICK 0x23 /* A mouse button has been pressed that was not previously pressed */
|
|
|
|
#define WE_MOUSEUP 0x24 /* A mouse button has been released */
|
|
|
|
#define WE_NEWWINDOW 0x30 /* A new window has been created */
|
|
|
|
#define WE_RESIZED 0x31 /* Your window has been resized or moved */
|
2012-03-14 02:44:19 +04:00
|
|
|
#define WE_DESTROYED 0x32 /* Window has been removed */
|
2012-03-02 07:13:52 +04:00
|
|
|
#define WE_REDRAWN 0x34
|
2012-11-20 09:24:21 +04:00
|
|
|
#define WE_FOCUSCHG 0x35
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
#define WE_GROUP_MASK 0xF0
|
|
|
|
#define WE_KEY_EVT 0x10 /* Some sort of keyboard event */
|
|
|
|
#define WE_MOUSE_EVT 0x20 /* Some sort of mouse event */
|
|
|
|
#define WE_WINDOW_EVT 0x30 /* Some sort of window event */
|
|
|
|
|
|
|
|
typedef uint16_t wid_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
wid_t wid; /* or none for new window */
|
2012-02-14 05:46:00 +04:00
|
|
|
int16_t left; /* X coordinate */
|
|
|
|
int16_t top; /* Y coordinate */
|
2012-02-12 04:54:34 +04:00
|
|
|
uint16_t width; /* Width of window or region */
|
|
|
|
uint16_t height; /* Height of window or region */
|
|
|
|
uint8_t command; /* The command (duplicated) */
|
|
|
|
} w_window_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
wid_t wid;
|
|
|
|
uint16_t key;
|
2012-10-15 06:53:16 +04:00
|
|
|
uint8_t ret;
|
|
|
|
key_event_t event;
|
2012-02-12 04:54:34 +04:00
|
|
|
uint8_t command;
|
|
|
|
} w_keyboard_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
wid_t wid;
|
2012-04-17 23:25:03 +04:00
|
|
|
int32_t old_x;
|
|
|
|
int32_t old_y;
|
|
|
|
int32_t new_x;
|
|
|
|
int32_t new_y;
|
2012-02-12 04:54:34 +04:00
|
|
|
uint8_t buttons;
|
|
|
|
uint8_t command;
|
|
|
|
} w_mouse_t;
|
|
|
|
|
|
|
|
#define MOUSE_BUTTON_LEFT 0x01
|
|
|
|
#define MOUSE_BUTTON_RIGHT 0x02
|
|
|
|
#define MOUSE_BUTTON_MIDDLE 0x04
|
|
|
|
|
|
|
|
|
|
|
|
#define SHMKEY(buf,sz,win) snprintf(buf, sz, "%s.%d.%d.%d", WINS_SERVER_IDENTIFIER, win->owner->pid, win->wid, win->bufid);
|
2012-02-13 05:30:36 +04:00
|
|
|
#define SHMKEY_(buf,sz,win) snprintf(buf, sz, "%s.%d.%d.%d", WINS_SERVER_IDENTIFIER, getpid(), win->wid, win->bufid);
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* Windows */
|
|
|
|
typedef struct process_windows process_windows_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
wid_t wid; /* Window identifier */
|
|
|
|
process_windows_t * owner; /* Owning process (back ptr) */
|
|
|
|
|
|
|
|
uint16_t width; /* Buffer width in pixels */
|
|
|
|
uint16_t height; /* Buffer height in pixels */
|
|
|
|
|
|
|
|
/* UNUSED IN CLIENT */
|
|
|
|
int32_t x; /* X coordinate of upper-left corner */
|
|
|
|
int32_t y; /* Y coordinate of upper-left corner */
|
|
|
|
uint16_t z; /* Stack order */
|
2012-09-14 09:12:47 +04:00
|
|
|
uint8_t use_alpha;
|
2012-02-12 04:54:34 +04:00
|
|
|
/* END UNUSED IN CLIENT */
|
2012-11-20 09:24:21 +04:00
|
|
|
uint8_t focused;
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
uint8_t * buffer; /* Window buffer */
|
|
|
|
uint16_t bufid; /* We occasionally replace the buffer; each is uniquely-indexed */
|
|
|
|
} window_t;
|
|
|
|
|
|
|
|
struct process_windows {
|
|
|
|
uint32_t pid;
|
|
|
|
|
|
|
|
int event_pipe; /* Pipe to send events through */
|
2012-04-13 08:21:38 +04:00
|
|
|
FILE * event_pipe_file;
|
2012-02-12 04:54:34 +04:00
|
|
|
int command_pipe; /* Pipe on which we receive commands */
|
2012-03-21 01:23:24 +04:00
|
|
|
FILE * command_pipe_file;
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
list_t * windows;
|
|
|
|
};
|
|
|
|
|
2012-03-08 08:40:58 +04:00
|
|
|
volatile wins_server_global_t * wins_globals;
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
/* Client Windowing */
|
|
|
|
|
|
|
|
int setup_windowing ();
|
|
|
|
void teardown_windowing ();
|
|
|
|
|
2012-02-14 05:46:00 +04:00
|
|
|
window_t * window_create (int16_t left, int16_t top, uint16_t width, uint16_t height);
|
|
|
|
void window_resize (window_t * window, int16_t left, int16_t top, uint16_t width, uint16_t height);
|
|
|
|
void window_redraw (window_t * window, int16_t left, int16_t top, uint16_t width, uint16_t height);
|
2012-02-12 04:54:34 +04:00
|
|
|
void window_redraw_full (window_t * window);
|
2012-03-02 07:13:52 +04:00
|
|
|
void window_redraw_wait (window_t * window);
|
2012-02-12 04:54:34 +04:00
|
|
|
void window_destroy (window_t * window);
|
2012-03-08 08:31:24 +04:00
|
|
|
void window_reorder (window_t * window, uint16_t new_zed);
|
2012-09-14 09:12:47 +04:00
|
|
|
void window_enable_alpha (window_t * window);
|
2012-10-12 10:55:53 +04:00
|
|
|
void window_disable_alpha (window_t * window);
|
2012-02-12 04:54:34 +04:00
|
|
|
|
|
|
|
w_keyboard_t * poll_keyboard();
|
2012-12-10 11:07:04 +04:00
|
|
|
w_keyboard_t * poll_keyboard_async();
|
2012-02-12 04:54:34 +04:00
|
|
|
w_mouse_t * poll_mouse();
|
|
|
|
|
|
|
|
#define TO_WINDOW_OFFSET(x,y) (((x) - window->x) + ((y) - window->y) * window->width)
|
|
|
|
#define DIRECT_OFFSET(x,y) ((x) + (y) * window->width)
|
|
|
|
|
Context-based graphics library.
All graphics library commands now take a gfx_context_t pointer, which
points to a simple datastructure describing a rendering context (width,
height, depth, total size, front buffer, backbuffer; where backbuffer =
front buffer when not in double-buffering mode, thus we always render to
backbuffer except on a flip). This may have caused a minor speed
reduction, but I don't really care as it's far more important that we
support multiple graphics contexts.
TODO:
- Shared Memory Fonts library (there are a couple of apps that use these
so-called "shmem fonts" on their own; we need a dedicated library for
them)
- Break off "TTK" GUI toolkit into its own library. Since it's just a
callback-based button framework, this shouldn't be too hard right now.
Also, with the previous tick, I'll be able to put labels on controls
and start using text in more places.
2012-04-17 22:21:34 +04:00
|
|
|
gfx_context_t * init_graphics_window(window_t * window);
|
|
|
|
gfx_context_t * init_graphics_window_double_buffer(window_t * window);
|
2012-10-14 00:02:58 +04:00
|
|
|
void reinit_graphics_window(gfx_context_t * out, window_t * window);
|
2012-02-20 08:35:20 +04:00
|
|
|
|
2012-04-13 07:42:24 +04:00
|
|
|
void win_use_threaded_handler();
|
2012-04-13 10:21:01 +04:00
|
|
|
void (*mouse_action_callback)(w_mouse_t *);
|
2012-02-20 08:35:20 +04:00
|
|
|
|
2012-10-14 00:02:58 +04:00
|
|
|
void (*resize_window_callback)(window_t *);
|
|
|
|
|
2012-11-20 09:24:21 +04:00
|
|
|
void (*focus_changed_callback)(window_t *);
|
|
|
|
|
2012-02-12 04:54:34 +04:00
|
|
|
#endif
|