9 #define VIDMODE_SCALED_WINDOW 3
12 #define TOOLTIP_MARGIN 2
13 #define BC_INFINITY 65536
15 #include "bcfilebox.inc"
16 #include "arraylist.h"
17 #include "bcbitmap.inc"
18 #include "bcbutton.inc"
19 #include "bccapture.inc"
20 #include "bcdragwindow.inc"
21 #include "bcclipboard.inc"
22 #include "bclistbox.inc"
23 #include "bcmenubar.inc"
24 #include "bcmeter.inc"
26 #include "bcpixmap.inc"
27 #include "bcpopup.inc"
28 #include "bcpopupmenu.inc"
30 #include "bcprogress.inc"
31 #include "bcrepeater.inc"
32 #include "bcresources.inc"
33 #include "bcscrollbar.inc"
34 #include "bcslider.inc"
35 #include "bcsubwindow.inc"
36 #include "bctextbox.inc"
37 #include "bctitle.inc"
38 #include "bctoggle.inc"
39 #include "bctumble.inc"
40 #include "bcwindow.inc"
41 #include "bcwindowbase.inc"
42 #include "defaults.inc"
51 #include <X11/Xatom.h>
53 #include <X11/Xutil.h>
54 #include <X11/keysym.h>
55 #include <X11/cursorfont.h>
56 #ifdef HAVE_LIBXXF86VM
57 #include <X11/extensions/xf86vmode.h>
64 typedef void* GLXContext
;
70 BC_ResizeCall(int w
, int h
);
77 BC_WindowTree(Display
* display
, BC_WindowTree
*parent_tree
, Window root_win
);
80 void dump(int indent
, Window caller_win
= 0);
81 BC_WindowTree
* get_node(Window win
);
82 ArrayList
<BC_WindowTree
*> windows
;
86 BC_WindowTree
*parent_tree
;
90 // Windows, subwindows, popupwindows inherit from this
95 virtual ~BC_WindowBase();
97 friend class BC_Bitmap
;
98 friend class BC_Button
;
99 friend class BC_GenericButton
;
100 friend class BC_Capture
;
101 friend class BC_Clipboard
;
102 friend class BC_DragWindow
;
103 friend class BC_FileBox
;
104 friend class BC_FullScreen
;
105 friend class BC_ListBox
;
106 friend class BC_Menu
;
107 friend class BC_MenuBar
;
108 friend class BC_MenuItem
;
109 friend class BC_MenuPopup
;
110 friend class BC_Meter
;
112 friend class BC_Pixmap
;
113 friend class BC_Popup
;
114 friend class BC_PopupMenu
;
116 friend class BC_ProgressBar
;
117 friend class BC_Repeater
;
118 friend class BC_Resources
;
119 friend class BC_ScrollBar
;
120 friend class BC_Slider
;
121 friend class BC_SubWindow
;
122 friend class BC_TextBox
;
123 friend class BC_Title
;
124 friend class BC_Toggle
;
125 friend class BC_Tumbler
;
126 friend class BC_Window
;
131 // Terminal event dispatchers
132 virtual int close_event();
133 virtual int resize_event(int w
, int h
);
134 virtual int cursor_motion_event() { return 0; };
135 virtual int repeat_event(int64_t duration
) { return 0; };
136 virtual int button_press_event() { return 0; };
137 virtual int button_release_event() { return 0; };
138 virtual int cursor_leave_event();
139 virtual int cursor_enter_event();
140 virtual int keypress_event() { return 0; };
141 virtual int translation_event() { return 0; };
142 virtual int drag_start_event() { return 0; };
143 virtual int drag_motion_event() { return 0; };
144 virtual int drag_stop_event() { return 0; };
145 virtual int uses_text() { return 0; };
146 // Only if opengl is enabled
147 virtual int expose_event() { return 0; };
149 // Check if a hardware accelerated colormodel is available and reserve it
150 int accel_available(int color_model
);
151 // Get color model adjusted for byte order and pixel size
152 int get_color_model();
153 // return the colormap pixel of the color for all bit depths
154 int get_color(int64_t color
);
155 // return the currently selected color
160 void enable_opengl();
161 void disable_opengl();
163 void unlock_opengl();
166 int flash(int x
= -1, int y
= -1, int w
= -1, int h
= -1);
169 // Lock out other threads
172 int get_window_lock();
174 BC_MenuBar
* add_menubar(BC_MenuBar
*menu_bar
);
175 BC_WindowBase
* add_subwindow(BC_WindowBase
*subwindow
);
176 BC_WindowBase
* add_tool(BC_WindowBase
*subwindow
);
178 static BC_Resources
* get_resources();
184 int get_root_w(int ignore_dualhead
= 0);
186 // Get current position
187 int get_abs_cursor_x();
188 int get_abs_cursor_y();
189 int get_relative_cursor_x();
190 int get_relative_cursor_y();
191 // Return 1 if cursor is over an unobscured part of this window.
192 // An argument is provided for excluding a drag popup
193 int get_cursor_over_window();
194 int get_button_down();
195 int get_buttonpress();
198 // Get cursor position of last event
201 // Cursor position of drag start
204 int relative_cursor_x(BC_WindowBase
*pov
);
205 int relative_cursor_y(BC_WindowBase
*pov
);
209 int get_double_click();
210 // Bottom right corner
214 BC_Pixmap
* get_bg_pixmap();
215 int get_text_ascent(int font
);
216 int get_text_descent(int font
);
217 int get_text_height(int font
, char *text
= 0);
218 int get_text_width(int font
, char *text
, int length
= -1);
219 BC_Clipboard
* get_clipboard();
220 void set_dragging(int value
);
223 BC_WindowBase
* get_top_level();
224 BC_WindowBase
* get_parent();
225 // Event happened in this window
228 // Deactivate everything and activate this subwindow
229 virtual int activate();
230 // Deactivate this subwindow
231 virtual int deactivate();
232 void set_active_subwindow(BC_WindowBase
*subwindow
);
233 // Get value of toggle value when dragging a selection
234 int get_toggle_value();
237 // Set the gc to the color
238 void set_color(int64_t color
);
240 void set_font(int font
);
241 void set_cursor(int cursor
);
242 void set_x_cursor(int cursor
);
246 void copy_area(int x1
, int y1
, int x2
, int y2
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
247 void clear_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
248 void draw_box(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
249 void draw_circle(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
250 void draw_disc(int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
251 void draw_text(int x
, int y
, char *text
, int length
= -1, BC_Pixmap
*pixmap
= 0);
252 void draw_center_text(int x
, int y
, char *text
, int length
= -1);
253 void draw_line(int x1
, int y1
, int x2
, int y2
, BC_Pixmap
*pixmap
= 0);
254 void draw_polygon(ArrayList
<int> *x
, ArrayList
<int> *y
, BC_Pixmap
*pixmap
= 0);
255 void draw_rectangle(int x
, int y
, int w
, int h
);
256 void draw_3segment(int x
,
260 BC_Pixmap
*left_image
,
261 BC_Pixmap
*mid_image
,
262 BC_Pixmap
*right_image
,
263 BC_Pixmap
*pixmap
= 0);
264 void draw_3segment(int x
,
271 BC_Pixmap
*pixmap
= 0);
272 // For drawing a changing level
273 void draw_3segmenth(long x
,
280 void draw_3segmenth(long x
,
287 void draw_3segmentv(long x
,
294 void draw_3segmentv(long x
,
301 // For drawing a single level
302 void draw_3segmenth(int x
,
306 BC_Pixmap
*pixmap
= 0);
307 void draw_3segmenth(long x
,
312 void draw_3segmentv(long x
,
317 void draw_3segmentv(long x
,
322 void draw_9segment(long x
,
328 void draw_3d_box(int x
,
337 BC_Pixmap
*pixmap
= 0);
338 void draw_3d_border(int x
, int y
, int w
, int h
,
339 int light1
, int light2
, int shadow1
, int shadow2
);
340 void draw_colored_box(int x
, int y
, int w
, int h
, int down
, int highlighted
);
341 void draw_check(int x
, int y
);
342 void draw_triangle_down_flat(int x
, int y
, int w
, int h
);
343 void draw_triangle_up(int x
, int y
, int w
, int h
,
344 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
345 void draw_triangle_down(int x
, int y
, int w
, int h
,
346 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
347 void draw_triangle_left(int x
, int y
, int w
, int h
,
348 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
349 void draw_triangle_right(int x
, int y
, int w
, int h
,
350 int light1
, int light2
, int middle
, int shadow1
, int shadow2
);
351 // Set the gc to opaque
354 void set_background(VFrame
*bitmap
);
355 void set_title(char *text
);
360 void set_done(int return_value
);
361 // Get a bitmap to draw on the window with
362 BC_Bitmap
* new_bitmap(int w
, int h
, int color_model
= -1);
363 // Draw a bitmap on the window
364 void draw_bitmap(BC_Bitmap
*bitmap
,
374 BC_Pixmap
*pixmap
= 0);
375 void draw_pixel(int x
, int y
, BC_Pixmap
*pixmap
= 0);
376 // Draw a pixmap on the window
377 void draw_pixmap(BC_Pixmap
*pixmap
,
385 // Draw a vframe on the window
386 void draw_vframe(VFrame
*frame
,
395 BC_Pixmap
*pixmap
= 0);
396 void draw_border(char *text
, int x
, int y
, int w
, int h
);
397 // Draw a region of the background
398 void draw_top_background(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
399 void draw_top_tiles(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
);
400 void draw_background(int x
, int y
, int w
, int h
);
401 void draw_tiles(BC_Pixmap
*tile
,
408 void slide_left(int distance
);
409 void slide_right(int distance
);
410 void slide_up(int distance
);
411 void slide_down(int distance
);
413 int cycle_textboxes(int amount
);
416 int set_tooltips(int tooltips_enabled
);
417 int resize_window(int w
, int h
);
418 int reposition_window(int x
, int y
, int w
= -1, int h
= -1);
419 // int64_t get_repeat_id();
420 int set_repeat(int64_t duration
);
421 int unset_repeat(int64_t id
);
422 int set_tooltip(char *text
);
423 int show_tooltip(int w
= -1, int h
= -1);
425 int set_icon(VFrame
*data
);
426 int load_defaults(Defaults
*defaults
);
427 int save_defaults(Defaults
*defaults
);
429 #ifdef HAVE_LIBXXF86VM
430 // Mode switch methods.
431 void closest_vm(int *vm
, int *width
, int *height
);
432 void scale_vm(int vm
);
441 virtual int create_window(BC_WindowBase
*parent_window
,
455 BC_Pixmap
*bg_pixmap
);
457 static Display
* init_display(char *display_name
);
458 virtual int initialize();
462 int init_window_shape();
463 static int evaluate_color_model(int client_byte_order
, int server_byte_order
, int depth
);
464 int create_private_colors();
465 int create_color(int color
);
466 int create_shared_colors();
467 int get_single_text_width(int font
, char *text
, int length
);
468 int allocate_color_table();
471 int get_color_rgb8(int color
);
472 int64_t get_color_rgb16(int color
);
473 int64_t get_color_bgr16(int color
);
474 int64_t get_color_bgr24(int color
);
475 XFontStruct
* get_font_struct(int font
);
476 Cursor
get_cursor_struct(int cursor
);
477 XFontSet
get_fontset(int font
);
478 XFontSet
get_curr_fontset(void);
479 void set_fontset(int font
);
480 int dispatch_event();
482 int get_key_masks(XEvent
&event
);
484 int trigger_tooltip();
485 int untrigger_tooltip();
487 int arm_repeat(int64_t duration
);
488 // delete all repeater opjects for a close
489 int unset_all_repeaters();
491 // Recursive event dispatchers
492 int dispatch_resize_event(int w
, int h
);
493 int dispatch_motion_event();
494 int dispatch_keypress_event();
495 int dispatch_repeat_event(int64_t duration
);
496 int dispatch_repeat_event_master(int64_t duration
);
497 int dispatch_button_press();
498 int dispatch_button_release();
499 int dispatch_cursor_leave();
500 int dispatch_cursor_enter();
501 int dispatch_translation_event();
502 int dispatch_drag_start();
503 int dispatch_drag_motion();
504 int dispatch_drag_stop();
505 int dispatch_expose_event();
507 // Get the port ID for a color model or return -1 for failure
508 int grab_port_id(BC_WindowBase
*window
, int color_model
);
510 int find_next_textbox(BC_WindowBase
**first_textbox
, BC_WindowBase
**next_textbox
, int &result
);
511 int find_prev_textbox(BC_WindowBase
**last_textbox
, BC_WindowBase
**prev_textbox
, int &result
);
515 void translate_coordinates(Window src_w
,
522 // Top level window above this window
523 BC_WindowBase
* top_level
;
524 // Window just above this window
525 BC_WindowBase
* parent_window
;
526 // list of window bases in this window
527 BC_SubWindowList
* subwindows
;
528 // Position of window
531 int light1
, light2
, medium
, dark1
, dark2
, bg_color
;
532 // Type of window defined above
534 // Pointer to the active menubar in the window.
535 BC_MenuBar
* active_menubar
;
536 // pointer to the active popup menu in the window
537 BC_PopupMenu
* active_popup_menu
;
538 // pointer to the active subwindow
539 BC_WindowBase
* active_subwindow
;
543 int hidden
, private_color
, bits_per_pixel
, color_model
;
544 int server_byte_order
, client_byte_order
;
545 // number of colors in color table
547 // last color found in table
548 int current_color_value
, current_color_pixel
;
549 // table for every color allocated
550 int color_table
[256][2];
551 // Turn on optimization
553 // Event handler completion
555 // Return value of event handler
557 // Motion event compression
558 int motion_events
, last_motion_x
, last_motion_y
;
559 // window of buffered motion
560 Window last_motion_win
;
561 // Resize event compression
562 int resize_events
, last_resize_w
, last_resize_h
;
563 int translation_events
, last_translate_x
, last_translate_y
;
565 // Since the window manager automatically translates the window at boot,
566 // use the first translation event to get correction factors
567 int translation_count
;
568 int x_correction
, y_correction
;
570 int ctrl_mask
, shift_mask
, alt_mask
;
571 // Cursor motion information
572 int cursor_x
, cursor_y
;
573 // Button status information
574 int button_down
, button_number
;
575 // When button was pressed and whether it qualifies as a double click
576 uint64_t button_time1
, button_time2
;
578 // Which button is down
582 // During a selection drag involving toggles, set the same value for each toggle
585 static BC_Resources resources
;
586 // Array of repeaters for multiple repeating objects.
587 ArrayList
<BC_Repeater
*> repeaters
;
588 // int64_t next_repeat_id;
589 // Text for tooltip if one exists
590 char tooltip_text
[BCTEXTLEN
];
591 // If the current window's tooltip is visible
593 // Repeat ID of tooltip
594 // int64_t tooltip_id;
595 // Popup window for tooltip
596 BC_Popup
*tooltip_popup
;
597 // If this subwindow has already shown a tooltip since the last EnterNotify
599 // If the tooltip shouldn't be hidden
600 int persistant_tooltip
;
602 XFontSet largefontset
, mediumfontset
, smallfontset
, curr_fontset
;
603 int64_t current_color
;
604 // Coordinate of drag start
606 // Boundaries the cursor must pass to start a drag
607 int drag_x1
, drag_x2
, drag_y1
, drag_y2
;
608 // Dragging is specific to the subwindow
610 // Don't delete the background pixmap
611 int shared_bg_pixmap
;
612 char title
[BCTEXTLEN
];
614 // Window tree for dragging operations
615 static BC_WindowTree
*window_tree
;
617 // X Window parameters
620 // windows previous events happened in
621 Window event_win
, drag_win
;
628 GLXContext gl_context
;
630 static Mutex opengl_lock
;
633 // Depth given by the X Server
639 XFontStruct
*largefont
, *mediumfont
, *smallfont
;
644 Cursor vseparate_cursor
;
645 Cursor hseparate_cursor
;
650 Cursor upright_arrow_cursor
;
651 Cursor upleft_resize_cursor
;
652 Cursor upright_resize_cursor
;
653 Cursor downleft_resize_cursor
;
654 Cursor downright_resize_cursor
;
657 ArrayList
<BC_ResizeCall
*> resize_history
;
658 // Background tile if tiled
659 BC_Pixmap
*bg_pixmap
;
661 BC_Popup
*icon_window
;
662 BC_Pixmap
*icon_pixmap
;
664 BC_Bitmap
*temp_bitmap
;
666 BC_Clipboard
*clipboard
;
668 // Cancel button, to be called on close window, if != NULL
669 BC_CancelButton
*cancel_button
;
671 #ifdef HAVE_LIBXXF86VM
672 // Mode switch information.
674 XF86VidModeModeInfo orig_modeline
;