Backspace sends DEL instead of ^H.
[spft.git] / TermWindow.h
blobee6aa96590d2a549dc12e494214b9ea3a68695b5
1 #ifndef TermWindow_h
2 #define TermWindow_h
4 // This would just be called "Window", but that conflicts with XWindow's type
5 // of the same name.
7 #include "Style.h"
8 #include "FontSet.h"
9 #include <X11/Xlib.h>
10 #include <X11/Xft/Xft.h>
11 #include <string>
12 #include <time.h>
13 #include <stdint.h>
15 class Terminal;
16 class History;
17 class Line;
20 class TermWindow {
21 public:
22 TermWindow();
23 ~TermWindow();
25 bool is_done();
26 void tick();
27 void draw();
28 void resized(unsigned int new_width, unsigned int new_height);
29 void set_title(const char* title);
31 protected:
32 bool closed;
33 Terminal* terminal;
34 History* history;
35 Display* display;
36 int screen;
37 Window window;
38 XSetWindowAttributes attributes;
39 GC gc;
40 Drawable pixmap;
41 XftDraw* xft_draw;
42 FontSet* regular_font = nullptr;
43 FontSet* line_drawing_font = nullptr;
44 FontSet* monospace_font = nullptr;
45 unsigned int width, height;
46 double font_size_override = 0;
47 bool use_monospace_font = false;
49 int64_t top_line;
51 struct SelectionPoint {
52 int64_t line;
53 int column;
55 SelectionPoint()
56 : line(-1), column(0) {}
57 SelectionPoint(int64_t line_in, int column_in)
58 : line(line_in), column(column_in) {}
59 bool operator<(SelectionPoint& other) {
60 return
61 line < other.line ||
62 (line == other.line && column < other.column);
64 bool operator>=(SelectionPoint& other) {
65 return !(*this < other);
68 SelectionPoint selection_start, selection_end;
69 bool has_selection() { return selection_start.line >= 0; }
70 enum {
71 NotSelecting, SelectingForward, SelectingBackward,
73 int selecting_state;
74 enum {
75 SelectingByChar, SelectingByWord, SelectingByLine,
77 int selecting_by;
78 struct timespec last_click_time;
79 std::string selected_text;
80 void clear_selection() {
81 selection_start.line = selection_end.line = -1;
84 Atom wm_delete_window_atom;
85 Atom wm_name_atom;
86 Atom target_atom;
88 struct KeyMapping {
89 KeySym keySym;
90 unsigned int mask;
91 const char* str;
93 enum {
94 AnyModKey = UINT_MAX,
96 bool check_special_key(
97 KeySym key_sym, unsigned int state,
98 const KeyMapping* key_mappings, int num_key_mappings);
100 XftFont* xft_font_for(const Style& style) {
101 return
102 (use_monospace_font ? monospace_font :
103 ((style.line_drawing ? line_drawing_font : regular_font)))->xft_font_for(style);
106 void setup_fonts();
107 void cleanup_fonts();
108 void screen_size_changed();
109 void key_down(XKeyEvent* event);
110 void mouse_button_down(XButtonEvent* event);
111 void mouse_moved(XMotionEvent* event);
112 void mouse_button_up(XButtonEvent* event);
113 void selection_requested(XSelectionRequestEvent* event);
114 void property_changed(XEvent* event);
115 void received_selection(XEvent* event);
116 int displayed_lines() { return (height - 2 * settings.border) / regular_font->height(); }
117 void scroll_to_bottom() { top_line = -1; }
118 void decorate_run(Style style, int x, int width, int y);
120 void paste();
122 int column_for_pixel(int64_t which_line, int x);
123 int64_t calc_effective_top_line();
124 SelectionPoint start_of_word(SelectionPoint point);
125 SelectionPoint end_of_word(SelectionPoint point);
127 // Elastic tabs.
128 void recalc_elastic_columns(int64_t initial_line);
129 void update_elastic_columns_for(Line* line);
133 #endif // !TermWindow_h