1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 19 июн. 2017 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef UI_TK_LSPDISPLAY_H_ 23 #define UI_TK_LSPDISPLAY_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 class LSPWidget; 30 class LSPSlotSet; 31 class LSPTheme; 32 33 /** Main display 34 * 35 */ 36 class LSPDisplay 37 { 38 protected: 39 typedef struct item_t 40 { 41 LSPWidget *widget; 42 char *id; 43 } item_t; 44 45 protected: 46 cvector<item_t> sWidgets; 47 cvector<LSPWidget> vGarbage; 48 cvector<char> vAtoms; 49 LSPSlotSet sSlots; 50 LSPTheme sTheme; 51 IDictionary *pDictionary; 52 IDisplay *pDisplay; 53 54 protected: 55 void do_destroy(); 56 57 protected: 58 static status_t main_task_handler(ws::timestamp_t time, void *arg); 59 60 //--------------------------------------------------------------------------------- 61 // Construction and destruction 62 public: 63 /** Constructor 64 * 65 */ 66 explicit LSPDisplay(); 67 68 /** Destructor 69 * 70 */ 71 virtual ~LSPDisplay(); 72 73 /** Initialize display 74 * 75 * @param argc number of additional arguments 76 * @param argv list of additional arguments 77 * @return status of operation 78 */ 79 status_t init(int argc, const char **argv); 80 81 /** Initialize display 82 * 83 * @param dpy underlying display object 84 * @param argc number of additional arguments 85 * @param argv list of additional arguments 86 * @return status of operation 87 */ 88 status_t init(ws::IDisplay *dpy, int argc, const char **argv); 89 90 /** Destroy display 91 * 92 */ 93 void destroy(); 94 95 //--------------------------------------------------------------------------------- 96 // Manipulation 97 public: 98 /** Execute main loop function 99 * 100 * @return status of operation 101 */ 102 status_t main(); 103 104 /** Execute one main loop iteration 105 * 106 * @return status of operation 107 */ 108 status_t main_iteration(); 109 110 /** Interrupt main loop function 111 * 112 */ 113 void quit_main(); 114 115 /** 116 * Synchronize display 117 */ 118 void sync(); 119 120 /** Register widget, it will be automatically destroyed 121 * 122 * @param widget widget to queue 123 * @param id widget identifier 124 * @return status of operation 125 */ 126 status_t add(LSPWidget *widget, const char *id = NULL); 127 128 /** Add widget and return pointer to write to 129 * 130 * @param id widget identifier 131 * @return pointer or NULL 132 */ 133 LSPWidget **add(const char *id); 134 135 /** Get widget by it's identifier 136 * 137 * @param id widget identifier 138 * @return pointer to widget 139 */ 140 LSPWidget *get(const char *id); 141 142 /** Deregister widget by it's identifier 143 * 144 * @param id widget identifier 145 * @return pointer to widget or NULL 146 */ 147 LSPWidget *remove(const char *id); 148 149 /** Deregister widget by it's pointer 150 * 151 * @param widget widget to remove from queue 152 * @return status of operation 153 */ 154 bool remove(LSPWidget *widget); 155 156 /** Check that widget exists 157 * 158 * @param id widget pointer 159 * @return true on success 160 */ 161 bool exists(LSPWidget *widget); 162 163 /** Check that widget exists 164 * 165 * @param id widget identifier 166 * @return true on success 167 */ exists(const char * id)168 inline bool exists(const char *id) { return get(id) != NULL; } 169 170 //--------------------------------------------------------------------------------- 171 // Properties 172 public: 173 /** Get slots 174 * 175 * @return slots 176 */ slots()177 inline LSPSlotSet *slots() { return &sSlots; } 178 179 /** Get slot 180 * 181 * @param id slot identifier 182 * @return pointer to slot or NULL 183 */ slot(ui_slot_t id)184 inline LSPSlot *slot(ui_slot_t id) { return sSlots.slot(id); } 185 186 /** Return native display handle 187 * 188 * @return native display handle 189 */ display()190 inline IDisplay *display() { return pDisplay; } 191 192 /** 193 * Get the dictionary that contains localization data 194 * @return dictionary object 195 */ dictionary()196 inline IDictionary *dictionary() { return pDictionary; } 197 198 /** Get current display theme 199 * 200 * @return current display theme 201 */ theme()202 inline LSPTheme *theme() { return &sTheme; } 203 204 /** 205 * Get atom identifier by name 206 * @param name atom name 207 * @return atom identifier or negative error code 208 */ 209 ui_atom_t atom_id(const char *name); 210 211 /** 212 * Get atom name by identifier 213 * @param name atom name or NULL 214 * @return atom identifier 215 */ 216 const char *atom_name(ui_atom_t id); 217 218 /** 219 * Get clipboard data 220 * @param id clipboard identifier 221 * @param sink data sink 222 * @return status of operation 223 */ 224 status_t get_clipboard(size_t id, IDataSink *sink); 225 226 /** 227 * Set clipboard data 228 * @param id clipboard identifier 229 * @param src data source 230 * @return status of operation 231 */ 232 status_t set_clipboard(size_t id, IDataSource *src); 233 234 /** 235 * Reject drag event 236 * @return status of operation 237 */ 238 status_t reject_drag(); 239 240 /** 241 * Accept drag request 242 * @param sink the sink that will handle data transfer 243 * @param action drag action 244 * @param internal true if we want to receive notifications inside of the drag rectangle 245 * @param r parameters of the drag rectangle, can be NULL 246 * @return status of operation 247 */ 248 status_t accept_drag(IDataSink *sink, drag_t action, bool internal, const realize_t *r); 249 250 /** 251 * Get NULL-terminated list of provided MIME types for a drag 252 * @return NULL-terminated list of strings 253 */ 254 const char * const *get_drag_mime_types(); 255 256 /** Get screen size 257 * 258 * @param screen screen identifier 259 * @param w screen width 260 * @param h screen height 261 * @return status of operation 262 */ screen_size(size_t screen,ssize_t * w,ssize_t * h)263 inline status_t screen_size(size_t screen, ssize_t *w, ssize_t *h) { return pDisplay->screen_size(screen, w, h); } 264 265 /** Create surface 266 * 267 * @param width surface width 268 * @param height surface height 269 * @return pointer to created surface or NULL 270 */ 271 ISurface *create_surface(size_t width, size_t height); 272 273 /** 274 * Queue widget for removal. Because all widget operations are done in the 275 * main event loop, it's unsafe to destroy widget immediately in callback 276 * handlers. This method allows to put the widget to the garbage queue that 277 * will be recycled at the end of the event loop iteration. 278 * 279 * @param widget widget to be queued for destroy 280 * @return status of operation 281 */ 282 status_t queue_destroy(LSPWidget *widget); 283 }; 284 } 285 286 } /* namespace lsp */ 287 288 #endif /* UI_TK_LSPDISPLAY_H_ */ 289