10 #define VIDMODE_SCALED_WINDOW 3
13 #define TOOLTIP_MARGIN 2
14 #define BC_INFINITY 65536
16 #include "bcfilebox.inc"
17 #include "arraylist.h"
18 #include "bcbitmap.inc"
19 #include "bcbutton.inc"
20 #include "bccapture.inc"
21 #include "bcdragwindow.inc"
22 #include "bcclipboard.inc"
23 #include "bclistbox.inc"
24 #include "bcmenubar.inc"
25 #include "bcmeter.inc"
27 #include "bcpixmap.inc"
28 #include "bcpopup.inc"
29 #include "bcpopupmenu.inc"
31 #include "bcprogress.inc"
32 #include "bcrepeater.inc"
33 #include "bcresources.inc"
34 #include "bcscrollbar.inc"
35 #include "bcslider.inc"
36 #include "bcsubwindow.inc"
37 #include "bctextbox.inc"
38 #include "bctitle.inc"
39 #include "bctoggle.inc"
40 #include "bctumble.inc"
41 #include "bcwindow.inc"
42 #include "bcwindowbase.inc"
43 #include "bcwindowevents.inc"
44 #include "condition.inc"
45 #include "defaults.inc"
54 #include <X11/Xatom.h>
56 #include <X11/Xft/Xft.h>
59 #include <X11/Xutil.h>
60 #include <X11/keysym.h>
61 #include <X11/cursorfont.h>
62 #ifdef HAVE_LIBXXF86VM
63 #include <X11/extensions/xf86vmode.h>
70 typedef void* GLXContext
;
76 BC_ResizeCall(int w
, int h
);
81 // Windows, subwindows, popupwindows inherit from this
86 virtual ~BC_WindowBase();
88 friend class BC_Bitmap
;
89 friend class BC_Button
;
90 friend class BC_GenericButton
;
91 friend class BC_Capture
;
92 friend class BC_Clipboard
;
93 friend class BC_DragWindow
;
94 friend class BC_FileBox
;
95 friend class BC_FullScreen
;
96 friend class BC_ListBox
;
98 friend class BC_MenuBar
;
99 friend class BC_MenuItem
;
100 friend class BC_MenuPopup
;
101 friend class BC_Meter
;
103 friend class BC_Pixmap
;
104 friend class BC_Popup
;
105 friend class BC_PopupMenu
;
107 friend class BC_ProgressBar
;
108 friend class BC_Repeater
;
109 friend class BC_Resources
;
110 friend class BC_ScrollBar
;
111 friend class BC_Slider
;
112 friend class BC_SubWindow
;
113 friend class BC_TextBox
;
114 friend class BC_Title
;
115 friend class BC_Toggle
;
116 friend class BC_Tumbler
;
117 friend class BC_Window
;
118 friend class BC_WindowEvents
;
122 // Terminal event dispatchers
123 virtual int close_event();
124 virtual int resize_event(int w
, int h
);
125 virtual int repeat_event(int64_t duration
) { return 0; };
126 virtual int focus_in_event() { return 0; };
127 virtual int focus_out_event() { return 0; };
128 virtual int button_press_event() { return 0; };
129 virtual int button_release_event() { return 0; };
130 virtual int cursor_motion_event() { return 0; };
131 virtual int cursor_leave_event();
132 virtual int cursor_enter_event();
133 virtual int keypress_event() { return 0; };
134 virtual int translation_event() { return 0; };
135 virtual int drag_start_event() { return 0; };
136 virtual int drag_motion_event() { return 0; };
137 virtual int drag_stop_event() { return 0; };
138 virtual int uses_text() { return 0; };
139 // Only if opengl is enabled
140 virtual int expose_event() { return 0; };
142 // Check if a hardware accelerated colormodel is available and reserve it
143 int accel_available(int color_model
);
144 // Get color model adjusted for byte order and pixel size
145 int get_color_model();
146 // return the colormap pixel of the color for all bit depths
147 int get_color(int64_t color
);
148 // return the currently selected color
150 int show_window(int flush
= 1);
151 int hide_window(int flush
= 1);
153 void enable_opengl();
154 void disable_opengl();
156 void unlock_opengl();
159 int flash(int x
, int y
, int w
, int h
, int flush
= 1);
160 int flash(int flush
= 1);
163 // Lock out other threads
164 int lock_window(char *location
= 0);
166 int get_window_lock();
168 BC_MenuBar
* add_menubar(BC_MenuBar
*menu_bar
);
169 BC_WindowBase
* add_subwindow(BC_WindowBase
*subwindow
);
170 BC_WindowBase
* add_tool(BC_WindowBase
*subwindow
);
172 static BC_Resources
* get_resources();
178 int get_root_w(int ignore_dualhead
= 0, int lock_display
= 0);
179 int get_root_h(int lock_display
);
180 // Get current position
181 int get_abs_cursor_x(int lock_window
);
182 int get_abs_cursor_y(int lock_window
);
183 int get_relative_cursor_x();
184 int get_relative_cursor_y();
185 // Return 1 if cursor is over an unobscured part of this window.
186 // An argument is provided for excluding a drag popup
187 int get_cursor_over_window();
188 // For traversing windows... return 1 if this or any subwindow is win
189 int match_window(Window win
);
191 int get_button_down();
192 int get_buttonpress();
196 // Get cursor position of last event
199 // Cursor position of drag start
202 int relative_cursor_x(BC_WindowBase
*pov
);
203 int relative_cursor_y(BC_WindowBase
*pov
);
207 int get_double_click();
208 // Bottom right corner
212 BC_Pixmap
* get_bg_pixmap();
213 int get_text_ascent(int font
);
214 int get_text_descent(int font
);
215 int get_text_height(int font
, char *text
= 0);
216 int get_text_width(int font
, char *text
, int length
= -1);
217 BC_Clipboard
* get_clipboard();
218 void set_dragging(int value
);
221 BC_WindowBase
* get_top_level();
222 BC_WindowBase
* get_parent();
223 // Event happened in this window
226 // Deactivate everything and activate this subwindow
227 virtual int activate();
228 // Deactivate this subwindow
229 virtual int deactivate();
230 void set_active_subwindow(BC_WindowBase
*subwindow
);
231 // Get value of toggle value when dragging a selection
232 int get_toggle_value();
233 // Get if toggle is being dragged
234 int get_toggle_drag();
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 // Change the window title. The title is translated internally.
356 void set_title(char *text
);
361 void set_done(int return_value
);
362 // Get a bitmap to draw on the window with
363 BC_Bitmap
* new_bitmap(int w
, int h
, int color_model
= -1);
364 // Draw a bitmap on the window
365 void draw_bitmap(BC_Bitmap
*bitmap
,
375 BC_Pixmap
*pixmap
= 0);
376 void draw_pixel(int x
, int y
, BC_Pixmap
*pixmap
= 0);
377 // Draw a pixmap on the window
378 void draw_pixmap(BC_Pixmap
*pixmap
,
386 // Draw a vframe on the window
387 void draw_vframe(VFrame
*frame
,
396 BC_Pixmap
*pixmap
= 0);
397 void draw_border(char *text
, int x
, int y
, int w
, int h
);
398 // Draw a region of the background
399 void draw_top_background(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
, BC_Pixmap
*pixmap
= 0);
400 void draw_top_tiles(BC_WindowBase
*parent_window
, int x
, int y
, int w
, int h
);
401 void draw_background(int x
, int y
, int w
, int h
);
402 void draw_tiles(BC_Pixmap
*tile
,
409 void slide_left(int distance
);
410 void slide_right(int distance
);
411 void slide_up(int distance
);
412 void slide_down(int distance
);
414 int cycle_textboxes(int amount
);
416 int raise_window(int do_flush
= 1);
417 int set_tooltips(int tooltips_enabled
);
418 int resize_window(int w
, int h
);
419 int reposition_window(int x
, int y
, int w
= -1, int h
= -1);
420 // Cause a repeat event to be dispatched every duration.
421 // duration is milliseconds
422 int set_repeat(int64_t duration
);
423 // Stop a repeat event from being dispatched.
424 int unset_repeat(int64_t duration
);
425 int set_tooltip(char *text
);
426 int show_tooltip(int w
= -1, int h
= -1);
428 int set_icon(VFrame
*data
);
429 int load_defaults(Defaults
*defaults
);
430 int save_defaults(Defaults
*defaults
);
432 #ifdef HAVE_LIBXXF86VM
433 // Mode switch methods.
434 void closest_vm(int *vm
, int *width
, int *height
);
435 void scale_vm(int vm
);
444 virtual int create_window(BC_WindowBase
*parent_window
,
458 BC_Pixmap
*bg_pixmap
,
461 static Display
* init_display(char *display_name
);
462 virtual int initialize();
466 int init_window_shape();
467 static int evaluate_color_model(int client_byte_order
, int server_byte_order
, int depth
);
468 int create_private_colors();
469 int create_color(int color
);
470 int create_shared_colors();
471 // Get width of a single line. Used by get_text_width
472 int get_single_text_width(int font
, char *text
, int length
);
473 int allocate_color_table();
476 int get_color_rgb8(int color
);
477 int64_t get_color_rgb16(int color
);
478 int64_t get_color_bgr16(int color
);
479 int64_t get_color_bgr24(int color
);
480 XFontStruct
* get_font_struct(int font
);
482 XftFont
* get_xft_struct(int font
);
484 Cursor
get_cursor_struct(int cursor
);
485 XFontSet
get_fontset(int font
);
486 XFontSet
get_curr_fontset(void);
487 void set_fontset(int font
);
488 int dispatch_event();
490 int get_key_masks(XEvent
*event
);
492 int trigger_tooltip();
493 int untrigger_tooltip();
495 int arm_repeat(int64_t duration
);
496 // delete all repeater opjects for a close
497 int unset_all_repeaters();
499 // Block and get event from common events.
501 // Return number of events in table.
502 int get_event_count();
503 // Put event in common events.
504 void put_event(XEvent
*event
);
506 // Recursive event dispatchers
507 int dispatch_resize_event(int w
, int h
);
508 int dispatch_focus_in();
509 int dispatch_focus_out();
510 int dispatch_motion_event();
511 int dispatch_keypress_event();
512 int dispatch_repeat_event(int64_t duration
);
513 int dispatch_repeat_event_master(int64_t duration
);
514 int dispatch_button_press();
515 int dispatch_button_release();
516 int dispatch_cursor_leave();
517 int dispatch_cursor_enter();
518 int dispatch_translation_event();
519 int dispatch_drag_start();
520 int dispatch_drag_motion();
521 int dispatch_drag_stop();
522 int dispatch_expose_event();
524 // Get the port ID for a color model or return -1 for failure
525 int grab_port_id(BC_WindowBase
*window
, int color_model
);
527 int find_next_textbox(BC_WindowBase
**first_textbox
, BC_WindowBase
**next_textbox
, int &result
);
528 int find_prev_textbox(BC_WindowBase
**last_textbox
, BC_WindowBase
**prev_textbox
, int &result
);
532 void translate_coordinates(Window src_w
,
539 // Top level window above this window
540 BC_WindowBase
* top_level
;
541 // Window just above this window
542 BC_WindowBase
* parent_window
;
543 // list of window bases in this window
544 BC_SubWindowList
* subwindows
;
545 // Position of window
548 int light1
, light2
, medium
, dark1
, dark2
, bg_color
;
549 // Type of window defined above
551 // Pointer to the active menubar in the window.
552 BC_MenuBar
* active_menubar
;
553 // pointer to the active popup menu in the window
554 BC_PopupMenu
* active_popup_menu
;
555 // pointer to the active subwindow
556 BC_WindowBase
* active_subwindow
;
560 int hidden
, private_color
, bits_per_pixel
, color_model
;
561 int server_byte_order
, client_byte_order
;
562 // number of colors in color table
564 // last color found in table
565 int current_color_value
, current_color_pixel
;
566 // table for every color allocated
567 int color_table
[256][2];
568 // Turn on optimization
570 // Event handler completion
572 // Return value of event handler
574 // Motion event compression
575 int motion_events
, last_motion_x
, last_motion_y
;
576 // window of buffered motion
577 Window last_motion_win
;
578 // Resize event compression
579 int resize_events
, last_resize_w
, last_resize_h
;
580 int translation_events
, last_translate_x
, last_translate_y
;
582 // Since the window manager automatically translates the window at boot,
583 // use the first translation event to get correction factors
584 int translation_count
;
585 int x_correction
, y_correction
;
587 int ctrl_mask
, shift_mask
, alt_mask
;
588 // Cursor motion information
589 int cursor_x
, cursor_y
;
590 // Button status information
591 int button_down
, button_number
;
592 // When button was pressed and whether it qualifies as a double click
593 uint64_t button_time1
, button_time2
;
595 // Which button is down
599 // During a selection drag involving toggles, set the same value for each toggle
602 // Whether the window has the focus
605 static BC_Resources resources
;
606 // Array of repeaters for multiple repeating objects.
607 ArrayList
<BC_Repeater
*> repeaters
;
608 // int64_t next_repeat_id;
609 // Text for tooltip if one exists
610 char tooltip_text
[BCTEXTLEN
];
611 // If the current window's tooltip is visible
613 // Repeat ID of tooltip
614 // int64_t tooltip_id;
615 // Popup window for tooltip
616 BC_Popup
*tooltip_popup
;
617 // If this subwindow has already shown a tooltip since the last EnterNotify
619 // If the tooltip shouldn't be hidden
620 int persistant_tooltip
;
625 XFontSet largefontset
, mediumfontset
, smallfontset
, curr_fontset
;
629 XFontStruct
*largefont
, *mediumfont
, *smallfont
;
632 // XftDraw *xft_drawable;
633 // XftFont *largefont_xft, *mediumfont_xft, *smallfont_xft;
634 // Must be void so users don't need to include the wrong libpng version.
636 void *largefont_xft
, *mediumfont_xft
, *smallfont_xft
;
639 int64_t current_color
;
640 // Coordinate of drag start
642 // Boundaries the cursor must pass to start a drag
643 int drag_x1
, drag_x2
, drag_y1
, drag_y2
;
644 // Dragging is specific to the subwindow
646 // Don't delete the background pixmap
647 int shared_bg_pixmap
;
648 char title
[BCTEXTLEN
];
650 // X Window parameters
653 // windows previous events happened in
654 Window event_win
, drag_win
;
657 // Display for all synchronous operations
659 // Display to send events on
660 Display
*event_display
;
664 GLXContext gl_context
;
666 static Mutex opengl_lock
;
669 // Depth given by the X Server
679 Cursor vseparate_cursor
;
680 Cursor hseparate_cursor
;
685 Cursor upright_arrow_cursor
;
686 Cursor upleft_resize_cursor
;
687 Cursor upright_resize_cursor
;
688 Cursor downleft_resize_cursor
;
689 Cursor downright_resize_cursor
;
692 ArrayList
<BC_ResizeCall
*> resize_history
;
693 // Background tile if tiled
694 BC_Pixmap
*bg_pixmap
;
696 BC_Popup
*icon_window
;
697 BC_Pixmap
*icon_pixmap
;
699 BC_Bitmap
*temp_bitmap
;
701 BC_Clipboard
*clipboard
;
702 #ifdef HAVE_LIBXXF86VM
703 // Mode switch information.
705 XF86VidModeModeInfo orig_modeline
;
708 // Common events coming from X server and repeater.
709 ArrayList
<XEvent
*> common_events
;
710 // Locks for common events
712 // 1) event_condition
715 Condition
*event_condition
;
716 BC_WindowEvents
*event_thread
;