se

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

x.h (3602B)


      1 /* See LICENSE for license details. */
      2 
      3 /*
      4 ** This file mainly contains X11 stuff (drawing to the screen, window hints, etc)
      5 ** Most of that part is unchanged from ST (https://st.suckless.org/)
      6 ** the main() function and the main loop are found at the very bottom of this file
      7 ** there are a very few functions here that are interresting for configuratinos.
      8 */
      9 
     10 #ifndef _X_H
     11 #define _X_H
     12 
     13 #include "utf8.h"
     14 
     15 #include <X11/Xlib.h>
     16 #include <X11/keysym.h>
     17 #include <stdio.h>
     18 #include <limits.h>
     19 
     20 void draw_horisontal_line(int y, int x1, int x2);
     21 // TODO: vertical line
     22 // !!! NOTE:
     23 // !!! buffer MUST be malloced and NOT be freed after it is passed
     24 void set_clipboard_copy(char* buffer, int len);
     25 void execute_clipbaord_event();
     26 
     27 enum glyph_attribute {
     28 		ATTR_NULL       = 0,
     29 		ATTR_BOLD       = 1 << 0,
     30 		ATTR_FAINT      = 1 << 1,
     31 		ATTR_ITALIC     = 1 << 2,
     32 		ATTR_UNDERLINE  = 1 << 3,
     33 		ATTR_REVERSE    = 1 << 5,
     34 		ATTR_INVISIBLE  = 1 << 6,
     35 		ATTR_STRUCK     = 1 << 7,
     36 		ATTR_WIDE       = 1 << 9,
     37 		ATTR_WDUMMY     = 1 << 10,
     38 		ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
     39 };
     40 
     41 struct glyph {
     42 		rune_t  u;		// character code
     43 		uint16_t  mode;	// attribute flags
     44 		uint32_t fg;	// foreground
     45 		uint32_t bg;	// background
     46 };
     47 
     48 // Internal representation of the screen
     49 struct screen {
     50 		int row;         // row count
     51 		int col;         // column count
     52 		struct glyph** lines;   // screen letters 2d array
     53 };
     54 
     55 extern struct screen screen;
     56 extern struct glyph global_attr;
     57 
     58 void screen_init(int col, int row);
     59 void screen_resize(int col, int row);
     60 void screen_set_region(int x1, int y1, int x2, int y2, rune_t u);
     61 int screen_set_char(rune_t u, int x, int y);
     62 struct glyph* screen_set_attr(int x, int y);
     63 
     64 void* xmalloc(size_t len);
     65 void* xrealloc(void *p, size_t len);
     66 void die(const char *, ...);
     67 
     68 // the va_args can be used to return; or any other stuff like that
     69 // TODO: optionally crash the program for debugging
     70 #define soft_assert(condition, ...)										\
     71 		do {															\
     72 				if(!(condition)) {										\
     73 						fprintf(stderr, "SOFT ASSERT ERROR: (%s) failed at %s %s():%d\n", #condition, __FILE__, __func__, __LINE__); \
     74 						writef_to_status_bar("SOFT ASSERT ERROR: (%s) failed at %s %s():%d", #condition, __FILE__, __func__, __LINE__); \
     75 						status_bar_bg = error_color;					\
     76 						__VA_ARGS__										\
     77 								}										\
     78 		} while(0)														\
     79 
     80 enum win_mode {
     81 		MODE_VISIBLE     = 1 << 0,
     82 		MODE_FOCUSED     = 1 << 1,
     83 		MODE_APPKEYPAD   = 1 << 2,
     84 		MODE_KBDLOCK     = 1 << 6,
     85 		MODE_HIDE        = 1 << 7,
     86 		MODE_APPCURSOR   = 1 << 8,
     87 		MODE_MOUSESGR    = 1 << 9,
     88 		MODE_BLINK       = 1 << 11,
     89 		MODE_FBLINK      = 1 << 12,
     90 		MODE_BRCKTPASTE  = 1 << 16,
     91 		MODE_NUMLOCK     = 1 << 17,
     92 };
     93 
     94 #define MIN(a, b)		((a) < (b) ? (a) : (b))
     95 #define MAX(a, b)		((a) < (b) ? (b) : (a))
     96 #define LEN(a)			(sizeof(a) / sizeof(a)[0])
     97 #define LIMIT(x, a, b)		(x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
     98 #define BETWEEN(x, a, b)	((a) <= (x) && (x) <= (b))
     99 
    100 ////////////////////////////////////////////////
    101 // X11 and drawing
    102 //
    103 
    104 // X modifiers
    105 #define XK_ANY_MOD    UINT_MAX
    106 #define XK_NO_MOD     0
    107 #define XK_SWITCH_MOD (1<<13|1<<14)
    108 
    109 extern double defaultfontsize;
    110 extern double usedfontsize;
    111 
    112 void xdrawcursor(int, int, int focused);
    113 void xdrawline(int, int, int);
    114 void xfinishdraw(void);
    115 void xloadcols(void);
    116 void xloadfonts(const char *, double);
    117 int xsetcolorname(int, const char *);
    118 void xseticontitle(char *);
    119 void xsetpointermotion(int);
    120 int xstartdraw(void);
    121 void xunloadfonts(void);
    122 void cresize(int, int);
    123 void xhints(void);
    124 int match(unsigned int, unsigned int);
    125 
    126 #endif // _X_H