ltk

Socket-based GUI for X11 (WIP)
git clone git://lumidify.org/ltk.git (fast, but not encrypted)
git clone https://lumidify.org/git/ltk.git (encrypted, but very slow)
Log | Files | Refs | README | LICENSE

ltk.h (4464B)


      1 /*
      2  * Copyright (c) 2016-2023 lumidify <nobody@lumidify.org>
      3  *
      4  * Permission to use, copy, modify, and/or distribute this software for any
      5  * purpose with or without fee is hereby granted, provided that the above
      6  * copyright notice and this permission notice appear in all copies.
      7  *
      8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15  */
     16 
     17 #ifndef _LTK_H_
     18 #define _LTK_H_
     19 
     20 #include <stdint.h>
     21 #include <stdlib.h>
     22 #include "proto_types.h"
     23 
     24 typedef struct {
     25 	char *text;
     26 	size_t len;
     27 	int contains_nul;
     28 } ltk_cmd_token;
     29 
     30 typedef enum {
     31 	LTK_EVENT_RESIZE = 1 << 0,
     32 	LTK_EVENT_BUTTON = 1 << 1,
     33 	LTK_EVENT_KEY = 1 << 2,
     34 	LTK_EVENT_MENU = 1 << 3
     35 } ltk_userevent_type;
     36 
     37 /*
     38   Historical note concerning ltk_window: This code was originally copied
     39   from my previous attempt at creating a GUI library, which was meant to
     40   be a regular C library and support multiple windows. Since this version
     41   of LTK doesn't support multiple windows (well, the calling script can
     42   just run more instances of ltkd if needed), having an ltk_window struct
     43   passed around is kind of unnecessary. I'm too lazy to change that now,
     44   though, so it's just going to stay that way.
     45 */
     46 
     47 /* FIXME: fix this ugliness; remove circular dependencies */
     48 typedef struct ltk_window ltk_window;
     49 typedef struct ltk_text_context ltk_text_context;
     50 typedef struct ltk_surface ltk_surface;
     51 typedef struct ltk_window_theme ltk_window_theme;
     52 
     53 #include "widget.h"
     54 #include "surface_cache.h"
     55 #include "clipboard.h"
     56 #include "event.h"
     57 
     58 struct ltk_window {
     59 	ltk_renderdata *renderdata;
     60 	ltk_surface_cache *surface_cache;
     61 	ltk_text_context *text_context;
     62 	ltk_clipboard *clipboard;
     63 	ltk_surface *surface;
     64 	ltk_widget *root_widget;
     65 	ltk_widget *hover_widget;
     66 	ltk_widget *active_widget;
     67 	ltk_widget *pressed_widget;
     68 	void (*other_event) (struct ltk_window *, ltk_event *event);
     69 
     70 	/* PID of external command called e.g. by text widget to edit text.
     71 	   ON exit, cmd_caller->vtable->cmd_return is called with the text
     72 	   the external command wrote to a file. */
     73 	int cmd_pid;
     74 	char *cmd_tmpfile;
     75 	char *cmd_caller;
     76 
     77 	ltk_rect rect;
     78 	ltk_window_theme *theme;
     79 	ltk_rect dirty_rect;
     80 	size_t cur_kbd;
     81 	/* FIXME: generic array */
     82 	ltk_widget **popups;
     83 	size_t popups_num;
     84 	size_t popups_alloc;
     85 	/* This is a hack so ltk_window_unregister_all_popups can
     86 	   call hide for all popup widgets even if the hide function
     87 	   already calls ltk_window_unregister_popup */
     88 	char popups_locked;
     89 };
     90 
     91 #include "color.h"
     92 
     93 struct ltk_window_theme {
     94 	int border_width;
     95 	int font_size;
     96 	char *font;
     97 	ltk_color fg;
     98 	ltk_color bg;
     99 };
    100 
    101 int ltk_window_call_cmd(ltk_window *window, ltk_widget *caller, const char *cmd, size_t cmdlen, const char *text, size_t textlen);
    102 void ltk_window_invalidate_rect(ltk_window *window, ltk_rect rect);
    103 void ltk_queue_event(ltk_window *window, ltk_userevent_type type, const char *id, const char *data);
    104 void ltk_window_set_hover_widget(ltk_window *window, ltk_widget *widget, ltk_motion_event *event);
    105 void ltk_window_set_active_widget(ltk_window *window, ltk_widget *widget);
    106 void ltk_window_set_pressed_widget(ltk_window *window, ltk_widget *widget, int release);
    107 void ltk_quit(ltk_window *window);
    108 
    109 void ltk_unregister_timer(int timer_id);
    110 int ltk_register_timer(long first, long repeat, void (*callback)(void *), void *data);
    111 void ltk_window_register_popup(ltk_window *window, ltk_widget *popup);
    112 void ltk_window_unregister_popup(ltk_window *window, ltk_widget *popup);
    113 void ltk_window_unregister_all_popups(ltk_window *window);
    114 int ltk_handle_lock_client(ltk_window *window, int client);
    115 int ltk_queue_specific_event(ltk_widget *widget, const char *type, uint32_t mask, const char *data);
    116 int ltk_queue_sock_write(int client, const char *str, int len);
    117 int ltk_queue_sock_write_fmt(int client, const char *fmt, ...);
    118 
    119 ltk_point ltk_widget_pos_to_global(ltk_widget *widget, int x, int y);
    120 ltk_point ltk_global_to_widget_pos(ltk_widget *widget, int x, int y);
    121 void ltk_window_invalidate_widget_rect(ltk_window *window, ltk_widget *widget);
    122 
    123 #endif