4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "bcclipboard.h"
24 #include "bcdisplay.h"
25 #include "bcdisplayinfo.h"
26 #include "bcmenubar.h"
29 #include "bcpopupmenu.h"
30 #include "bcrepeater.h"
31 #include "bcresources.h"
32 #include "bcsignals.h"
33 #include "bcsubwindow.h"
34 #include "bcsynchronous.h"
36 #include "bcwindowbase.h"
37 #include "bcwindowevents.h"
38 #include "bccmodels.h"
40 #include "condition.h"
49 #include "workarounds.h"
59 #include <X11/extensions/Xinerama.h>
60 #include <X11/extensions/Xvlib.h>
61 #include <X11/extensions/shape.h>
62 #include <X11/XF86keysym.h>
63 #include <X11/Sunkeysym.h>
65 BC_ResizeCall::BC_ResizeCall(int w, int h)
77 int BC_WindowBase::shm_completion_event = -1;
81 BC_Resources BC_WindowBase::resources;
83 Window XGroupLeader = 0;
85 Mutex BC_KeyboardHandlerLock::keyboard_listener_mutex("keyboard_listener",0);
86 ArrayList<BC_KeyboardHandler*> BC_KeyboardHandler::listeners;
88 BC_WindowBase::BC_WindowBase()
90 //printf("BC_WindowBase::BC_WindowBase 1\n");
91 BC_WindowBase::initialize();
94 BC_WindowBase::~BC_WindowBase()
97 BC_Display::lock_display("BC_WindowBase::~BC_WindowBase");
99 if(window_type == MAIN_WINDOW)
100 lock_window("BC_WindowBase::~BC_WindowBase");
103 #ifdef HAVE_LIBXXF86VM
104 if(window_type == VIDMODE_SCALED_WINDOW && vm_switched) {
111 if(window_type != MAIN_WINDOW)
114 XSelectInput(top_level->display, this->win, 0);
115 XSync(top_level->display,0);
116 #ifndef SINGLE_THREAD
117 top_level->dequeue_events(win);
119 // drop active window refs to this
120 if(top_level->active_menubar == this) top_level->active_menubar = 0;
121 if(top_level->active_popup_menu == this) top_level->active_popup_menu = 0;
122 if(top_level->active_subwindow == this) top_level->active_subwindow = 0;
123 // drop motion window refs to this
124 if(top_level->motion_events && top_level->last_motion_win == this->win)
125 top_level->motion_events = 0;
127 // Remove pointer from parent window to this
128 parent_window->subwindows->remove(this);
131 if(grab_active) grab_active->active_grab = 0;
132 if(icon_window) delete icon_window;
133 if(window_type == POPUP_WINDOW)
134 parent_window->remove_popup(this);
136 // Delete the subwindows
139 while(subwindows->total)
141 // Subwindow removes its own pointer
142 delete subwindows->values[0];
149 //printf("delete glx=%08x, win=%08x %s\n", (unsigned)glx_win, (unsigned)win, title);
151 if( get_resources()->get_synchronous() && glx_win != 0 ) {
152 get_resources()->get_synchronous()->delete_window(this);
155 XDestroyWindow(top_level->display, win);
157 if(bg_pixmap && !shared_bg_pixmap) delete bg_pixmap;
158 if(icon_pixmap) delete icon_pixmap;
159 if(temp_bitmap) delete temp_bitmap;
160 top_level->active_bitmaps.remove_buffers(this);
161 if(_7segment_pixmaps)
163 for(int i = 0; i < TOTAL_7SEGMENT; i++)
164 delete _7segment_pixmaps[i];
166 delete [] _7segment_pixmaps;
171 if(window_type == MAIN_WINDOW)
173 XFreeGC(display, gc);
174 static XFontStruct *BC_WindowBase::*xfont[] = {
175 &BC_WindowBase::smallfont,
176 &BC_WindowBase::mediumfont,
177 &BC_WindowBase::largefont,
178 &BC_WindowBase::bigfont,
179 &BC_WindowBase::clockfont,
181 for( int i=sizeof(xfont)/sizeof(xfont[0]); --i>=0; )
182 XFreeFont(display, this->*xfont[i]);
185 // prevents a bug when Xft closes with unrefd fonts
186 FcPattern *defaults = FcPatternCreate();
187 FcPatternAddInteger(defaults, "maxunreffonts", 0);
188 XftDefaultSet(display, defaults);
190 static void *BC_WindowBase::*xft_font[] = {
191 &BC_WindowBase::smallfont_xft,
192 &BC_WindowBase::mediumfont_xft,
193 &BC_WindowBase::largefont_xft,
194 &BC_WindowBase::bigfont_xft,
195 &BC_WindowBase::bold_smallfont_xft,
196 &BC_WindowBase::bold_mediumfont_xft,
197 &BC_WindowBase::bold_largefont_xft,
198 &BC_WindowBase::clockfont_xft,
200 for( int i=sizeof(xft_font)/sizeof(xft_font[0]); --i>=0; ) {
201 XftFont *xft = (XftFont *)(this->*xft_font[i]);
202 if( xft ) xftFontClose (display, xft);
210 XFree(xinerama_info);
211 xinerama_screens = 0;
213 if( xvideo_port_id >= 0 )
214 XvUngrabPort(display, xvideo_port_id, CurrentTime);
217 // Must be last reference to display.
218 // _XftDisplayInfo needs a lock.
219 get_resources()->create_window_lock->lock("BC_WindowBase::~BC_WindowBase");
220 XCloseDisplay(display);
221 get_resources()->create_window_lock->unlock();
223 // clipboard uses a different display connection
224 clipboard->stop_clipboard();
228 resize_history.remove_all_objects();
230 #ifndef SINGLE_THREAD
231 common_events.remove_all_objects();
233 delete event_condition;
236 top_level->window_lock = 0;
237 BC_Display::unlock_display();
242 if( glx_fbcfgs_window ) XFree(glx_fbcfgs_window);
243 if( glx_fbcfgs_pbuffer) XFree(glx_fbcfgs_pbuffer);
244 if( glx_fbcfgs_pixmap ) XFree(glx_fbcfgs_pixmap);
247 UNSET_ALL_LOCKS(this)
250 int BC_WindowBase::initialize()
255 display_lock_owner = 0;
260 resend_event_window = 0;
272 xinerama_screens = 0;
277 translation_events = 0;
278 ctrl_mask = shift_mask = alt_mask = 0;
279 cursor_x = cursor_y = button_number = 0;
293 active_popup_menu = 0;
294 active_subwindow = 0;
298 _7segment_pixmaps = 0;
301 // next_repeat_id = 0;
303 current_font = MEDIUMFONT;
304 current_color = BLACK;
305 current_cursor = ARROW_CURSOR;
308 shared_bg_pixmap = 0;
311 window_type = MAIN_WINDOW;
312 translation_count = 0;
313 x_correction = y_correction = 0;
322 #ifdef HAVE_LIBXXF86VM
340 bold_smallfont_xft = 0;
341 bold_mediumfont_xft = 0;
342 bold_largefont_xft = 0;
344 completion_lock = new Condition(0, "BC_WindowBase::completion_lock");
346 // Need these right away since put_event is called before run_window sometimes.
347 event_lock = new Mutex("BC_WindowBase::event_lock");
348 event_condition = new Condition(0, "BC_WindowBase::event_condition");
349 init_lock = new Condition(0, "BC_WindowBase::init_lock");
352 cursor_timer = new Timer;
355 glx_fbcfgs_window = 0; n_fbcfgs_window = 0;
356 glx_fbcfgs_pbuffer = 0; n_fbcfgs_pbuffer = 0;
357 glx_fbcfgs_pixmap = 0; n_fbcfgs_pixmap = 0;
371 #define DEFAULT_EVENT_MASKS EnterWindowMask | \
374 ButtonReleaseMask | \
375 PointerMotionMask | \
379 int BC_WindowBase::create_window(BC_WindowBase *parent_window, const char *title,
380 int x, int y, int w, int h, int minw, int minh, int allow_resize,
381 int private_color, int hide, int bg_color, const char *display_name,
382 int window_type, BC_Pixmap *bg_pixmap, int group_it)
384 XSetWindowAttributes attr;
386 XSizeHints size_hints;
389 #ifdef HAVE_LIBXXF86VM
393 id = get_resources()->get_id();
394 if(parent_window) top_level = parent_window->top_level;
395 if( top_level ) lock_window("BC_WindowBase::create_window");
396 get_resources()->create_window_lock->lock("BC_WindowBase::create_window");
398 #ifdef HAVE_LIBXXF86VM
399 if(window_type == VIDMODE_SCALED_WINDOW)
400 closest_vm(&vm,&w,&h);
407 this->bg_color = bg_color;
408 this->window_type = window_type;
410 this->private_color = private_color;
411 this->parent_window = parent_window;
412 this->bg_pixmap = bg_pixmap;
413 this->allow_resize = allow_resize;
415 strcpy(this->display_name, display_name);
417 this->display_name[0] = 0;
420 if(bg_pixmap) shared_bg_pixmap = 1;
422 subwindows = new BC_SubWindowList;
424 if(window_type == MAIN_WINDOW)
427 parent_window = this;
431 display = BC_Display::get_display(display_name);
432 BC_Display::lock_display("BC_WindowBase::create_window");
433 // BC_Display::display_global->new_window(this);
436 // get the display connection
438 // This function must be the first Xlib
439 // function a multi-threaded program calls
441 display = init_display(display_name);
442 if( shm_completion_event < 0 ) shm_completion_event =
443 ShmCompletion + XShmGetEventBase(display);
445 lock_window("BC_WindowBase::create_window 1");
447 screen = DefaultScreen(display);
448 rootwin = RootWindow(display, screen);
449 // window placement boundaries
450 if( !xinerama_screens && XineramaIsActive(display) )
451 xinerama_info = XineramaQueryScreens(display, &xinerama_screens);
452 root_w = get_root_w(0);
453 root_h = get_root_h(0);
456 vis = get_glx_visual(display);
459 vis = DefaultVisual(display, screen);
461 default_depth = DefaultDepth(display, screen);
463 client_byte_order = (*(const u_int32_t*)"a ") & 0x00000001;
464 server_byte_order = (XImageByteOrder(display) == MSBFirst) ? 0 : 1;
467 // This must be done before fonts to know if antialiasing is available.
470 if(resources.use_shm < 0) resources.initialize_display(this);
471 x_correction = BC_DisplayInfo::get_left_border();
472 y_correction = BC_DisplayInfo::get_top_border();
474 // clamp window placement
475 if(this->x + this->w + x_correction > root_w)
476 this->x = root_w - this->w - x_correction;
477 if(this->y + this->h + y_correction > root_h)
478 this->y = root_h - this->h - y_correction;
479 if(this->x < 0) this->x = 0;
480 if(this->y < 0) this->y = 0;
482 if(this->bg_color == -1)
483 this->bg_color = resources.get_bg_color();
485 // printf("bcwindowbase 1 %s\n", title);
486 // if(window_type == MAIN_WINDOW) sleep(1);
487 // printf("bcwindowbase 10\n");
493 mask = CWEventMask | CWBackPixel | CWColormap | CWCursor;
495 attr.event_mask = DEFAULT_EVENT_MASKS |
496 StructureNotifyMask |
500 attr.background_pixel = get_color(this->bg_color);
501 attr.colormap = cmap;
502 attr.cursor = get_cursor_struct(ARROW_CURSOR);
504 win = XCreateWindow(display, rootwin,
505 this->x, this->y, this->w, this->h, 0,
506 top_level->default_depth, InputOutput,
508 XGetNormalHints(display, win, &size_hints);
510 size_hints.flags = PSize | PMinSize | PMaxSize;
511 size_hints.width = this->w;
512 size_hints.height = this->h;
513 size_hints.min_width = allow_resize ? minw : this->w;
514 size_hints.max_width = allow_resize ? 32767 : this->w;
515 size_hints.min_height = allow_resize ? minh : this->h;
516 size_hints.max_height = allow_resize ? 32767 : this->h;
517 if(x > -BC_INFINITY && x < BC_INFINITY)
519 size_hints.flags |= PPosition;
520 size_hints.x = this->x;
521 size_hints.y = this->y;
523 XSetWMProperties(display, win, 0, 0, 0, 0, &size_hints, 0, 0);
526 #ifndef SINGLE_THREAD
527 clipboard = new BC_Clipboard(this);
528 clipboard->start_clipboard();
534 Atom ClientLeaderXAtom;
535 if (XGroupLeader == 0)
537 const char *instance_name = "cinelerra";
538 const char *class_name = "Cinelerra";
539 XClassHint *class_hints = XAllocClassHint();
540 class_hints->res_name = (char*)instance_name;
541 class_hints->res_class = (char*)class_name;
542 XSetClassHint(top_level->display, win, class_hints);
544 ClientLeaderXAtom = XInternAtom(display, "WM_CLIENT_LEADER", True);
545 XChangeProperty(display, win, ClientLeaderXAtom, XA_WINDOW, 32,
546 PropModeReplace, (unsigned char *)&XGroupLeader, true);
549 set_icon(get_resources()->default_icon);
552 #ifdef HAVE_LIBXXF86VM
553 if(window_type == VIDMODE_SCALED_WINDOW && vm != -1)
560 #ifdef HAVE_LIBXXF86VM
561 if(window_type == POPUP_WINDOW || window_type == VIDMODE_SCALED_WINDOW)
563 if(window_type == POPUP_WINDOW)
566 mask = CWEventMask | CWBackPixel | CWColormap |
567 CWOverrideRedirect | CWSaveUnder | CWCursor;
569 attr.event_mask = DEFAULT_EVENT_MASKS |
573 if(this->bg_color == -1)
574 this->bg_color = resources.get_bg_color();
575 attr.background_pixel = top_level->get_color(bg_color);
576 attr.colormap = top_level->cmap;
577 if(top_level->is_hourglass)
578 attr.cursor = top_level->get_cursor_struct(HOURGLASS_CURSOR);
580 attr.cursor = top_level->get_cursor_struct(ARROW_CURSOR);
581 attr.override_redirect = True;
582 attr.save_under = True;
584 win = XCreateWindow(top_level->display,
585 top_level->rootwin, this->x, this->y, this->w, this->h, 0,
586 top_level->default_depth, InputOutput, top_level->vis, mask,
588 top_level->add_popup(this);
591 if(window_type == SUB_WINDOW)
593 mask = CWEventMask | CWBackPixel | CWCursor;
594 attr.event_mask = DEFAULT_EVENT_MASKS;
595 attr.background_pixel = top_level->get_color(this->bg_color);
596 if(top_level->is_hourglass)
597 attr.cursor = top_level->get_cursor_struct(HOURGLASS_CURSOR);
599 attr.cursor = top_level->get_cursor_struct(ARROW_CURSOR);
600 win = XCreateWindow(top_level->display,
601 parent_window->win, this->x, this->y, this->w, this->h, 0,
602 top_level->default_depth, InputOutput, top_level->vis, mask,
605 if(!hidden) XMapWindow(top_level->display, win);
608 // Create pixmap for all windows
609 pixmap = new BC_Pixmap(this, this->w, this->h);
611 // Set up options for main window
612 if(window_type == MAIN_WINDOW)
614 if(get_resources()->bg_image && !bg_pixmap && bg_color < 0)
616 this->bg_pixmap = new BC_Pixmap(this,
617 get_resources()->bg_image,
621 if(!hidden) show_window();
625 draw_background(0, 0, this->w, this->h);
627 flash(-1, -1, -1, -1, 0);
629 // Set up options for popup window
630 #ifdef HAVE_LIBXXF86VM
631 if(window_type == POPUP_WINDOW || window_type == VIDMODE_SCALED_WINDOW)
633 if(window_type == POPUP_WINDOW)
637 if(!hidden) show_window();
639 get_resources()->create_window_lock->unlock();
645 Display* BC_WindowBase::init_display(const char *display_name)
649 if(display_name && display_name[0] == 0) display_name = NULL;
650 if((display = XOpenDisplay(display_name)) == NULL) {
651 printf("BC_WindowBase::init_display: cannot connect to X server %s\n",
653 if(getenv("DISPLAY") == NULL) {
654 printf(_("'DISPLAY' environment variable not set.\n"));
658 // Try again with default display.
659 if((display = XOpenDisplay(0)) == NULL) {
660 printf("BC_WindowBase::init_display: cannot connect to default X server.\n");
666 static int xsynch = -1;
668 const char *cp = getenv("CIN_XSYNCH");
669 xsynch = !cp ? 0 : atoi(cp);
672 XSynchronize(display, True);
677 Display* BC_WindowBase::get_display()
679 return top_level->display;
682 int BC_WindowBase::get_screen()
684 return top_level->screen;
687 int BC_WindowBase::run_window()
693 // Events may have been sent before run_window so can't initialize them here.
696 set_repeat(get_resources()->tooltip_delay);
697 BC_Display::display_global->new_window(this);
699 // If the first window created, run the display loop in this thread.
700 if(BC_Display::display_global->is_first(this))
702 BC_Display::unlock_display();
703 BC_Display::display_global->loop();
707 BC_Display::unlock_display();
708 completion_lock->lock("BC_WindowBase::run_window");
711 BC_Display::lock_display("BC_WindowBase::run_window");
712 BC_Display::display_global->delete_window(this);
714 unset_all_repeaters();
716 BC_Display::unlock_display();
718 #else // SINGLE_THREAD
723 set_repeat(get_resources()->tooltip_delay);
725 // Start X server events
726 event_thread = new BC_WindowEvents(this);
727 event_thread->start();
733 // Handle common events
739 unset_all_repeaters();
743 event_condition->reset();
744 common_events.remove_all_objects();
748 #endif // SINGLE_THREAD
753 int BC_WindowBase::get_key_masks(unsigned int key_state)
755 // printf("BC_WindowBase::get_key_masks %llx\n",
756 // event->xkey.state);
757 ctrl_mask = (key_state & ControlMask) ? 1 : 0; // ctrl key down
758 shift_mask = (key_state & ShiftMask) ? 1 : 0; // shift key down
759 alt_mask = (key_state & Mod1Mask) ? 1 : 0; // alt key down
764 void BC_WindowBase::add_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *))
766 BC_KeyboardHandlerLock set;
767 BC_KeyboardHandler::listeners.append(new BC_KeyboardHandler(handler, this));
770 void BC_WindowBase::del_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *))
772 BC_KeyboardHandlerLock set;
773 int i = BC_KeyboardHandler::listeners.size();
774 while( --i >= 0 && BC_KeyboardHandler::listeners[i]->handler!=handler );
775 if( i >= 0 ) BC_KeyboardHandler::listeners.remove_object_number(i);
778 int BC_KeyboardHandler::run_event(BC_WindowBase *wp)
780 int result = (win->*handler)(wp);
784 int BC_KeyboardHandler::run_listeners(BC_WindowBase *wp)
787 BC_KeyboardHandlerLock set;
788 for( int i=0; !result && i<listeners.size(); ++i ) {
789 BC_KeyboardHandler *listener = listeners[i];
790 result = listener->run_event(wp);
795 void BC_KeyboardHandler::kill_grabs()
797 BC_KeyboardHandlerLock set;
798 for( int i=0; i<listeners.size(); ++i ) {
799 BC_WindowBase *win = listeners[i]->win;
800 if( win->get_window_type() != POPUP_WINDOW ) continue;
801 ((BC_Popup *)win)->ungrab_keyboard();
805 void BC_ActiveBitmaps::reque(XEvent *event)
807 XShmCompletionEvent *shm_ev = (XShmCompletionEvent *)event;
808 ShmSeg shmseg = shm_ev->shmseg;
809 Drawable drawable = shm_ev->drawable;
810 //printf("BC_BitmapImage::reque %08lx\n",shmseg);
811 active_lock.lock("BC_BitmapImage::reque");
812 BC_BitmapImage *bfr = first;
813 while( bfr && bfr->get_shmseg() != shmseg ) bfr = bfr->next;
814 if( bfr && bfr->drawable == drawable )
816 active_lock.unlock();
818 // sadly, X reports two drawable completions and creates false reporting, so no boobytrap
819 // printf("BC_BitmapImage::reque missed shmseg %08x, drawable %08x\n",
820 // (int)shmseg, (int)drawable);
823 if( bfr->drawable != drawable ) return;
824 if( bfr->is_zombie() ) { --BC_Bitmap::zombies; delete bfr; return; }
825 bfr->bitmap->reque(bfr);
828 void BC_ActiveBitmaps::insert(BC_BitmapImage *bfr, Drawable pixmap)
830 active_lock.lock("BC_BitmapImage::insert");
831 bfr->drawable = pixmap;
833 active_lock.unlock();
836 void BC_ActiveBitmaps::remove_buffers(BC_WindowBase *wdw)
838 active_lock.lock("BC_ActiveBitmaps::remove");
839 for( BC_BitmapImage *nxt=0, *bfr=first; bfr; bfr=nxt ) {
841 if( bfr->is_zombie() ) { --BC_Bitmap::zombies; delete bfr; continue; }
842 if( bfr->bitmap->parent_window == wdw ) remove_pointer(bfr);
844 active_lock.unlock();
847 BC_ActiveBitmaps::BC_ActiveBitmaps()
851 BC_ActiveBitmaps::~BC_ActiveBitmaps()
857 int BC_WindowBase::keysym_lookup(XEvent *event)
859 for( int i = 0; i < KEYPRESSLEN; ++i ) keys_return[i] = 0;
860 for( int i = 0; i < 4; ++i ) wkey_string[i] = 0;
862 if( event->xany.send_event && !event->xany.serial ) {
863 keysym = (KeySym) event->xkey.keycode;
864 keys_return[0] = keysym;
867 wkey_string_length = 0;
869 if( input_context ) {
870 wkey_string_length = XwcLookupString(input_context,
871 (XKeyEvent*)event, wkey_string, 4, &keysym, 0);
872 //printf("keysym_lookup 1 %d %d %lx %x %x %x %x\n", wkey_string_length, keysym,
873 // wkey_string[0], wkey_string[1], wkey_string[2], wkey_string[3]);
876 int ret = Xutf8LookupString(input_context, (XKeyEvent*)event,
877 keys_return, KEYPRESSLEN, &keysym, &stat);
878 //printf("keysym_lookup 2 %d %d %lx %x %x\n", ret, stat, keysym, keys_return[0], keys_return[1]);
879 if( stat == XLookupBoth ) return ret;
880 if( stat == XLookupKeySym ) return 0;
882 int ret = XLookupString((XKeyEvent*)event, keys_return, KEYPRESSLEN, &keysym, 0);
883 wkey_string_length = ret;
884 for( int i=0; i<ret; ++i ) wkey_string[i] = keys_return[i];
888 pthread_t locking_task = (pthread_t)-1L;
889 int locking_event = -1;
890 int locking_message = -1;
892 int BC_WindowBase::dispatch_event(XEvent *event)
896 XClientMessageEvent *ptr;
897 int cancel_resize, cancel_translation;
902 #ifndef SINGLE_THREAD
903 // If an event is waiting get it, otherwise
904 // wait for next event only if there are no compressed events.
905 if(get_event_count() ||
906 (!motion_events && !resize_events && !translation_events))
909 // Lock out window deletions
910 lock_window("BC_WindowBase::dispatch_event 1");
911 locking_event = event->type;
912 locking_task = pthread_self();
913 locking_message = event->xclient.message_type;
916 // Handle compressed events
918 lock_window("BC_WindowBase::dispatch_event 2");
920 dispatch_resize_event(last_resize_w, last_resize_h);
922 dispatch_motion_event();
923 if(translation_events)
924 dispatch_translation_event();
935 //static const char *event_names[] = {
936 // "Reply", "Error", "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", "MotionNotify",
937 // "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose",
938 // "NoExpose", "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify",
939 // "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify",
940 // "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear",
941 // "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify",
942 // "GenericEvent", "LASTEvent",
946 //if(event->type != ClientMessage) {
947 // printf("BC_WindowBase::dispatch_event %d %s %p %d (%s)\n",
948 //__LINE__, title, event, event->type,
949 // event->type>=0 && event->type<sizeof(event_names)/sizeof(event_names[0]) ?
950 // event_names[event->type] : "Unknown");
955 active_grab->lock_window("BC_WindowBase::dispatch_event 3");
956 result = active_grab->grab_event(event);
957 active_grab->unlock_window();
958 if( result ) return result;
959 lock_window("BC_WindowBase::dispatch_event 4");
962 switch(event->type) {
964 // Clear the resize buffer
965 if(resize_events) dispatch_resize_event(last_resize_w, last_resize_h);
966 // Clear the motion buffer since this can clear the window
969 dispatch_motion_event();
972 ptr = (XClientMessageEvent*)event;
975 if(ptr->message_type == ProtoXAtom &&
976 (Atom)ptr->data.l[0] == DelWinXAtom)
981 if(ptr->message_type == RepeaterXAtom)
983 dispatch_repeat_event(ptr->data.l[0]);
984 // Make sure the repeater still exists.
985 // for(int i = 0; i < repeaters.total; i++)
987 // if(repeaters.values[i]->repeat_id == ptr->data.l[0])
989 // dispatch_repeat_event_master(ptr->data.l[0]);
995 if(ptr->message_type == SetDoneXAtom)
999 { // We currently use X marshalling for xatom events, we can switch to something else later
1000 receive_custom_xatoms((xatom_event *)ptr);
1006 dispatch_focus_in();
1011 dispatch_focus_out();
1025 dispatch_motion_event();
1027 get_key_masks(event->xbutton.state);
1028 cursor_x = event->xbutton.x;
1029 cursor_y = event->xbutton.y;
1030 button_number = event->xbutton.button;
1032 //printf("BC_WindowBase::dispatch_event %d %d\n", __LINE__, button_number);
1033 event_win = event->xany.window;
1034 if (button_number < 6)
1036 if(button_number < 4)
1038 button_pressed = event->xbutton.button;
1039 button_time1 = button_time2;
1040 button_time2 = button_time3;
1041 button_time3 = event->xbutton.time;
1044 drag_win = event_win;
1045 drag_x1 = cursor_x - get_resources()->drag_radius;
1046 drag_x2 = cursor_x + get_resources()->drag_radius;
1047 drag_y1 = cursor_y - get_resources()->drag_radius;
1048 drag_y2 = cursor_y + get_resources()->drag_radius;
1050 if((long)(button_time3 - button_time1) < resources.double_click * 2)
1053 button_time3 = button_time2 = button_time1 = 0;
1055 if((long)(button_time3 - button_time2) < resources.double_click)
1058 // button_time3 = button_time2 = button_time1 = 0;
1066 dispatch_button_press();
1073 dispatch_motion_event();
1075 get_key_masks(event->xbutton.state);
1076 button_number = event->xbutton.button;
1077 event_win = event->xany.window;
1078 if (button_number < 6)
1080 if(button_number < 4)
1082 //printf("BC_WindowBase::dispatch_event %d %d\n", __LINE__, button_number);
1084 dispatch_button_release();
1089 event_win = event->xany.window;
1090 dispatch_expose_event();
1094 get_key_masks(event->xmotion.state);
1095 // Dispatch previous motion event if this is a subsequent motion from a different window
1096 if(motion_events && last_motion_win != event->xany.window)
1098 dispatch_motion_event();
1101 // Buffer the current motion
1103 last_motion_state = event->xmotion.state;
1104 last_motion_x = event->xmotion.x;
1105 last_motion_y = event->xmotion.y;
1106 last_motion_win = event->xany.window;
1109 case ConfigureNotify:
1110 // printf("BC_WindowBase::dispatch_event %d win=%p this->win=%p\n",
1112 // event->xany.window,
1115 XTranslateCoordinates(top_level->display,
1123 last_resize_w = event->xconfigure.width;
1124 last_resize_h = event->xconfigure.height;
1127 cancel_translation = 0;
1129 // Resize history prevents responses to recursive resize requests
1130 for(int i = 0; i < resize_history.total && !cancel_resize; i++)
1132 if(resize_history.values[i]->w == last_resize_w &&
1133 resize_history.values[i]->h == last_resize_h)
1135 delete resize_history.values[i];
1136 resize_history.remove_number(i);
1141 if(last_resize_w == w && last_resize_h == h)
1149 if((last_translate_x == x && last_translate_y == y))
1150 cancel_translation = 1;
1152 if(!cancel_translation)
1154 translation_events = 1;
1157 translation_count++;
1161 get_key_masks(event->xkey.state);
1162 keys_return[0] = 0; keysym = -1;
1163 if(XFilterEvent(event, win)) {
1166 if( keysym_lookup(event) < 0 ) {
1167 printf("keysym %x\n", (uint32_t)keysym);
1171 //printf("BC_WindowBase::dispatch_event %d keysym=0x%x\n",
1175 // block out control keys
1176 if(keysym > 0xffe0 && keysym < 0xffff) break;
1177 // block out Alt_GR key
1178 if(keysym == 0xfe03) break;
1181 printf("BC_WindowBase::dispatch_event %x\n", (uint32_t)keysym);
1183 #ifdef X_HAVE_UTF8_STRING
1184 //It's Ascii or UTF8?
1185 // if (keysym != 0xffff && (keys_return[0] & 0xff) >= 0x7f )
1186 //printf("BC_WindowBase::dispatch_event %d %02x%02x\n", __LINE__, keys_return[0], keys_return[1]);
1188 if( ((keys_return[1] & 0xff) > 0x80) &&
1189 ((keys_return[0] & 0xff) > 0xC0) ) {
1190 //printf("BC_WindowBase::dispatch_event %d\n", __LINE__);
1191 key_pressed = keysym & 0xff;
1197 // block out extra keys
1207 // Translate key codes
1208 case XK_Return: key_pressed = RETURN; break;
1209 case XK_Up: key_pressed = UP; break;
1210 case XK_Down: key_pressed = DOWN; break;
1211 case XK_Left: key_pressed = LEFT; break;
1212 case XK_Right: key_pressed = RIGHT; break;
1213 case XK_Next: key_pressed = PGDN; break;
1214 case XK_Prior: key_pressed = PGUP; break;
1215 case XK_BackSpace: key_pressed = BACKSPACE; break;
1216 case XK_Escape: key_pressed = ESC; break;
1219 key_pressed = LEFTTAB;
1223 case XK_ISO_Left_Tab: key_pressed = LEFTTAB; break;
1224 case XK_underscore: key_pressed = '_'; break;
1225 case XK_asciitilde: key_pressed = '~'; break;
1226 case XK_Delete: key_pressed = DELETE; break;
1227 case XK_Home: key_pressed = HOME; break;
1228 case XK_End: key_pressed = END; break;
1231 case XK_KP_Enter: key_pressed = KPENTER; break;
1232 case XK_KP_Add: key_pressed = KPPLUS; break;
1233 case XK_KP_Subtract: key_pressed = KPMINUS; break;
1234 case XK_KP_Multiply: key_pressed = KPSTAR; break;
1235 case XK_KP_Divide: key_pressed = KPSLASH; break;
1237 case XK_KP_End: key_pressed = KP1; break;
1239 case XK_KP_Down: key_pressed = KP2; break;
1241 case XK_KP_Page_Down: key_pressed = KP3; break;
1243 case XK_KP_Left: key_pressed = KP4; break;
1245 case XK_KP_Begin: key_pressed = KP5; break;
1247 case XK_KP_Right: key_pressed = KP6; break;
1249 case XK_KP_Home: key_pressed = KP7; break;
1251 case XK_KP_Up: key_pressed = KP8; break;
1253 case XK_KP_Page_Up: key_pressed = KP9; break;
1255 case XK_KP_Insert: key_pressed = KPINS; break;
1257 case XK_KP_Delete: key_pressed = KPDEL; break;
1259 case XK_F1: key_pressed = KEY_F1; break;
1260 case XK_F2: key_pressed = KEY_F2; break;
1261 case XK_F3: key_pressed = KEY_F3; break;
1262 case XK_F4: key_pressed = KEY_F4; break;
1263 case XK_F5: key_pressed = KEY_F5; break;
1264 case XK_F6: key_pressed = KEY_F6; break;
1265 case XK_F7: key_pressed = KEY_F7; break;
1266 case XK_F8: key_pressed = KEY_F8; break;
1267 case XK_F9: key_pressed = KEY_F9; break;
1268 case XK_F10: key_pressed = KEY_F10; break;
1269 case XK_F11: key_pressed = KEY_F11; break;
1270 case XK_F12: key_pressed = KEY_F12; break;
1272 case XK_Menu: key_pressed = KPMENU; break; /* menu */
1274 // above case XK_KP_Enter: key_pressed = KPENTER; break; /* check */
1275 case XF86XK_MenuKB: key_pressed = KPMENU; break; /* menu */
1276 // intercepted case XF86XK_PowerDown: key_pressed = KPPOWER; break; /* Power */
1277 case XF86XK_Launch1: key_pressed = KPTV; break; /* TV */
1278 case XF86XK_Launch2: key_pressed = KPDVD; break; /* DVD */
1279 // intercepted case XF86XK_WWW: key_pressed = KPWWEB; break; /* WEB */
1280 case XF86XK_Launch3: key_pressed = KPBOOK; break; /* book */
1281 case XF86XK_Launch4: key_pressed = KPHAND; break; /* hand */
1282 case XF86XK_Reply: key_pressed = KPTMR; break; /* timer */
1283 case SunXK_Front: key_pressed = KPMAXW; break; /* max */
1284 // above case XK_Left: key_pressed = LEFT; break; /* left */
1285 // above case XK_Right: key_pressed = RIGHT; break; /* right */
1286 // above case XK_Down: key_pressed = DOWN; break; /* down */
1287 // above case XK_Up: key_pressed = UP; break; /* up */
1288 // above case XK_SPACE: key_pressed = KPSPACE; break; /* ok */
1289 // intercepted case XF86XK_AudioRaiseVolume: key_pressed = KPVOLU; break; /* VOL + */
1290 // intercepted case XF86XK_AudioMute: key_pressed = KPMUTE; break; /* MUTE */
1291 // intercepted case XF86XK_AudioLowerVolume: key_pressed = KPVOLD; break; /* VOL - */
1292 case XF86XK_ScrollUp: key_pressed = KPCHUP; break; /* CH + */
1293 case XF86XK_ScrollDown: key_pressed = KPCHDN; break; /* CH - */
1294 case XF86XK_AudioRecord: key_pressed = KPRECD; break; /* ( o) red */
1295 case XF86XK_Forward: key_pressed = KPPLAY; break; /* ( >) */
1296 case XK_Redo: key_pressed = KPFWRD; break; /* (>>) */
1297 case XF86XK_Back: key_pressed = KPBACK; break; /* (<<) */
1298 case XK_Cancel: key_pressed = KPSTOP; break; /* ([]) */
1299 case XK_Pause: key_pressed = KPAUSE; break; /* ('') */
1302 key_pressed = keysym & 0xff;
1303 #ifdef X_HAVE_UTF8_STRING
1304 //printf("BC_WindowBase::dispatch_event %d\n", __LINE__);
1309 #ifdef X_HAVE_UTF8_STRING
1311 key_pressed_utf8 = keys_return;
1316 if( top_level == this )
1317 result = BC_KeyboardHandler::run_listeners(this);
1319 //printf("BC_WindowBase::dispatch_event %d %d %x\n", shift_down(), alt_down(), key_pressed);
1321 result = dispatch_keypress_event();
1322 // Handle some default keypresses
1325 if(key_pressed == 'w' ||
1334 XLookupString((XKeyEvent*)event, keys_return, 1, &keysym, 0);
1335 dispatch_keyrelease_event();
1336 // printf("BC_WindowBase::dispatch_event KeyRelease keysym=0x%x keystate=0x%lld\n",
1337 // keysym, event->xkey.state);
1341 if( event->xcrossing.mode != NotifyNormal ) break;
1343 event_win = event->xany.window;
1344 dispatch_cursor_leave();
1348 if( event->xcrossing.mode != NotifyNormal ) break;
1350 if( !cursor_entered ) {
1351 for( int i=0; i<popups.size(); ++i ) { // popups always take focus
1352 if( popups[i]->win == event->xcrossing.window )
1355 if( !cursor_entered && get_resources()->grab_input_focus &&
1356 !event->xcrossing.focus && event->xcrossing.window == win ) {
1359 if( cursor_entered )
1362 event_win = event->xany.window;
1363 cursor_x = event->xcrossing.x;
1364 cursor_y = event->xcrossing.y;
1365 dispatch_cursor_enter();
1371 //printf("100 %s %p %d\n", title, event, event->type);
1372 //if(event->type != ClientMessage) dump();
1374 #ifndef SINGLE_THREAD
1377 if( resend_event_window ) {
1378 resend_event_window->put_event(event);
1379 resend_event_window = 0;
1385 // if(done) completion_lock->unlock();
1388 if(debug) printf("BC_WindowBase::dispatch_event this=%p %d\n", this, __LINE__);
1392 int BC_WindowBase::dispatch_expose_event()
1395 for(int i = 0; i < subwindows->total && !result; i++)
1397 result = subwindows->values[i]->dispatch_expose_event();
1400 // Propagate to user
1401 if(!result) expose_event();
1405 int BC_WindowBase::dispatch_resize_event(int w, int h)
1407 // Can't store new w and h until the event is handles
1408 // because bcfilebox depends on the old w and h to
1409 // reposition widgets.
1410 if( window_type == MAIN_WINDOW ) {
1415 pixmap = new BC_Pixmap(this, w, h);
1416 clear_box(0, 0, w, h);
1419 // Propagate to subwindows
1420 for(int i = 0; i < subwindows->total; i++) {
1421 subwindows->values[i]->dispatch_resize_event(w, h);
1424 // Propagate to user
1427 if( window_type == MAIN_WINDOW ) {
1436 int BC_WindowBase::dispatch_flash()
1439 for(int i = 0; i < subwindows->total; i++)
1440 subwindows->values[i]->dispatch_flash();
1444 int BC_WindowBase::dispatch_translation_event()
1446 translation_events = 0;
1447 if(window_type == MAIN_WINDOW)
1451 x = last_translate_x;
1452 y = last_translate_y;
1453 // Correct for window manager offsets
1458 for(int i = 0; i < subwindows->total; i++)
1460 subwindows->values[i]->dispatch_translation_event();
1463 translation_event();
1467 int BC_WindowBase::dispatch_motion_event()
1472 if(top_level == this)
1475 event_win = last_motion_win;
1476 get_key_masks(last_motion_state);
1479 if(get_button_down() && !active_menubar && !active_popup_menu)
1483 cursor_x = last_motion_x;
1484 cursor_y = last_motion_y;
1485 result = dispatch_drag_motion();
1489 (last_motion_x < drag_x1 || last_motion_x >= drag_x2 ||
1490 last_motion_y < drag_y1 || last_motion_y >= drag_y2))
1495 result = dispatch_drag_start();
1499 cursor_x = last_motion_x;
1500 cursor_y = last_motion_y;
1502 // printf("BC_WindowBase::dispatch_motion_event %d %p %p %p\n",
1505 // active_popup_menu,
1506 // active_subwindow);
1508 if(active_menubar && !result) result = active_menubar->dispatch_motion_event();
1509 if(active_popup_menu && !result) result = active_popup_menu->dispatch_motion_event();
1510 if(active_subwindow && !result) result = active_subwindow->dispatch_motion_event();
1513 // Dispatch in stacking order
1514 for(int i = subwindows->size() - 1; i >= 0 && !result; i--)
1516 result = subwindows->values[i]->dispatch_motion_event();
1519 if(!result) result = cursor_motion_event(); // give to user
1523 int BC_WindowBase::dispatch_keypress_event()
1526 if(top_level == this)
1528 if(active_subwindow) result = active_subwindow->dispatch_keypress_event();
1531 for(int i = 0; i < subwindows->total && !result; i++)
1533 result = subwindows->values[i]->dispatch_keypress_event();
1536 if(!result) result = keypress_event();
1541 int BC_WindowBase::dispatch_keyrelease_event()
1544 if(top_level == this)
1546 if(active_subwindow) result = active_subwindow->dispatch_keyrelease_event();
1549 for(int i = 0; i < subwindows->total && !result; i++)
1551 result = subwindows->values[i]->dispatch_keyrelease_event();
1554 if(!result) result = keyrelease_event();
1559 int BC_WindowBase::dispatch_focus_in()
1561 for(int i = 0; i < subwindows->total; i++)
1563 subwindows->values[i]->dispatch_focus_in();
1571 int BC_WindowBase::dispatch_focus_out()
1573 for(int i = 0; i < subwindows->total; i++)
1575 subwindows->values[i]->dispatch_focus_out();
1583 int BC_WindowBase::get_has_focus()
1585 return top_level->has_focus;
1588 int BC_WindowBase::get_deleting()
1590 if(is_deleting) return 1;
1591 if(parent_window && parent_window->get_deleting()) return 1;
1595 int BC_WindowBase::dispatch_button_press()
1600 if(top_level == this)
1602 if(active_menubar) result = active_menubar->dispatch_button_press();
1603 if(active_popup_menu && !result) result = active_popup_menu->dispatch_button_press();
1604 if(active_subwindow && !result) result = active_subwindow->dispatch_button_press();
1607 for(int i = 0; i < subwindows->total && !result; i++)
1609 result = subwindows->values[i]->dispatch_button_press();
1612 if(!result) result = button_press_event();
1618 int BC_WindowBase::dispatch_button_release()
1621 if(top_level == this)
1623 if(active_menubar) result = active_menubar->dispatch_button_release();
1624 if(active_popup_menu && !result) result = active_popup_menu->dispatch_button_release();
1625 if(active_subwindow && !result) result = active_subwindow->dispatch_button_release();
1626 if(!result && button_number != 4 && button_number != 5)
1627 result = dispatch_drag_stop();
1630 for(int i = 0; i < subwindows->total && !result; i++)
1632 result = subwindows->values[i]->dispatch_button_release();
1637 result = button_release_event();
1644 int BC_WindowBase::dispatch_repeat_event(int64_t duration)
1647 // all repeat event handlers get called and decide based on activity and duration
1648 // whether to respond
1649 for(int i = 0; i < subwindows->total; i++)
1651 subwindows->values[i]->dispatch_repeat_event(duration);
1655 repeat_event(duration);
1659 // Unlock next repeat signal
1660 if(window_type == MAIN_WINDOW)
1662 #ifdef SINGLE_THREAD
1663 BC_Display::display_global->unlock_repeaters(duration);
1665 for(int i = 0; i < repeaters.total; i++)
1667 if(repeaters.values[i]->delay == duration)
1669 repeaters.values[i]->repeat_lock->unlock();
1677 void BC_WindowBase::unhide_cursor()
1682 if(top_level->is_hourglass)
1683 set_cursor(HOURGLASS_CURSOR, 1, 0);
1685 set_cursor(current_cursor, 1, 0);
1687 cursor_timer->update();
1691 void BC_WindowBase::update_video_cursor()
1693 if(video_on && !is_transparent)
1695 if(cursor_timer->get_difference() > VIDEO_CURSOR_TIMEOUT && !is_transparent)
1698 set_cursor(TRANSPARENT_CURSOR, 1, 1);
1699 cursor_timer->update();
1704 cursor_timer->update();
1709 int BC_WindowBase::dispatch_cursor_leave()
1713 for(int i = 0; i < subwindows->total; i++)
1715 subwindows->values[i]->dispatch_cursor_leave();
1718 cursor_leave_event();
1722 int BC_WindowBase::dispatch_cursor_enter()
1728 if(active_menubar) result = active_menubar->dispatch_cursor_enter();
1729 if(!result && active_popup_menu) result = active_popup_menu->dispatch_cursor_enter();
1730 if(!result && active_subwindow) result = active_subwindow->dispatch_cursor_enter();
1732 for(int i = 0; !result && i < subwindows->total; i++)
1734 result = subwindows->values[i]->dispatch_cursor_enter();
1737 if(!result) result = cursor_enter_event();
1741 int BC_WindowBase::cursor_enter_event()
1746 int BC_WindowBase::cursor_leave_event()
1751 int BC_WindowBase::close_event()
1757 int BC_WindowBase::dispatch_drag_start()
1760 if(active_menubar) result = active_menubar->dispatch_drag_start();
1761 if(!result && active_popup_menu) result = active_popup_menu->dispatch_drag_start();
1762 if(!result && active_subwindow) result = active_subwindow->dispatch_drag_start();
1764 for(int i = 0; i < subwindows->total && !result; i++)
1766 result = subwindows->values[i]->dispatch_drag_start();
1769 if(!result) result = is_dragging = drag_start_event();
1773 int BC_WindowBase::dispatch_drag_stop()
1777 for(int i = 0; i < subwindows->total && !result; i++)
1779 result = subwindows->values[i]->dispatch_drag_stop();
1782 if(is_dragging && !result)
1792 int BC_WindowBase::dispatch_drag_motion()
1795 for(int i = 0; i < subwindows->total && !result; i++)
1797 result = subwindows->values[i]->dispatch_drag_motion();
1800 if(is_dragging && !result)
1802 drag_motion_event();
1810 int BC_WindowBase::show_tooltip(const char *text, int x, int y, int w, int h)
1813 int forced = !text ? force_tooltip : 1;
1814 if( !text ) text = tooltip_text;
1815 if( !text || (!forced && !get_resources()->tooltips_enabled) ) {
1816 top_level->hide_tooltip();
1820 if(w < 0) w = get_text_width(MEDIUMFONT, text) + TOOLTIP_MARGIN * 2;
1821 if(h < 0) h = get_text_height(MEDIUMFONT, text) + TOOLTIP_MARGIN * 2;
1822 // default x,y (win relative)
1823 if( x < 0 ) x = get_w();
1824 if( y < 0 ) y = get_h();
1826 get_root_coordinates(x, y, &wx, &wy);
1827 // keep the tip inside the window/display
1828 int x0 = top_level->get_x(), x1 = x0 + top_level->get_w();
1829 int x2 = top_level->get_screen_x(0, -1) + top_level->get_screen_w(0, -1);
1830 if( x1 > x2 ) x1 = x2;
1831 if( wx < x0 ) wx = x0;
1832 if( wx >= (x1-=w) ) wx = x1;
1833 int y0 = top_level->get_y(), y1 = y0 + top_level->get_h();
1834 int y2 = top_level->get_root_h(0);
1835 if( y1 > y2 ) y1 = y2;
1836 if( wy < y0 ) wy = y0;
1837 if( wy >= (y1-=h) ) wy = y1;
1838 // avoid tip under cursor (flickers)
1840 get_abs_cursor(abs_x,abs_y, 0);
1841 if( wx < abs_x && abs_x < wx+w && wy < abs_y && abs_y < wy+h ) {
1842 if( wx-abs_x < wy-abs_y )
1849 tooltip_popup = new BC_Popup(top_level, wx, wy, w, h,
1850 get_resources()->tooltip_bg_color);
1853 tooltip_popup->reposition_window(wx, wy, w, h);
1856 tooltip_popup->flash();
1857 tooltip_popup->flush();
1861 int BC_WindowBase::hide_tooltip()
1864 for(int i = 0; i < subwindows->total; i++)
1866 subwindows->values[i]->hide_tooltip();
1872 delete tooltip_popup;
1878 const char *BC_WindowBase::get_tooltip()
1880 return tooltip_text;
1883 int BC_WindowBase::set_tooltip(const char *text)
1885 tooltip_text = text;
1887 // Update existing tooltip if it is visible
1891 tooltip_popup->flash();
1895 // signal the event handler to repeat
1896 int BC_WindowBase::set_repeat(int64_t duration)
1900 printf("BC_WindowBase::set_repeat duration=%jd\n", duration);
1903 if(window_type != MAIN_WINDOW) return top_level->set_repeat(duration);
1905 #ifdef SINGLE_THREAD
1906 BC_Display::display_global->set_repeat(this, duration);
1908 // test repeater database for duplicates
1909 for(int i = 0; i < repeaters.total; i++)
1912 if(repeaters.values[i]->delay == duration)
1914 repeaters.values[i]->start_repeating(this);
1919 BC_Repeater *repeater = new BC_Repeater(this, duration);
1920 repeater->initialize();
1921 repeaters.append(repeater);
1922 repeater->start_repeating();
1927 int BC_WindowBase::unset_repeat(int64_t duration)
1929 if(window_type != MAIN_WINDOW) return top_level->unset_repeat(duration);
1931 #ifdef SINGLE_THREAD
1932 BC_Display::display_global->unset_repeat(this, duration);
1934 for(int i = 0; i < repeaters.total; i++)
1936 if(repeaters.values[i]->delay == duration)
1938 repeaters.values[i]->stop_repeating();
1946 int BC_WindowBase::unset_all_repeaters()
1948 #ifdef SINGLE_THREAD
1949 BC_Display::display_global->unset_all_repeaters(this);
1951 for(int i = 0; i < repeaters.total; i++)
1953 repeaters.values[i]->stop_repeating();
1955 repeaters.remove_all_objects();
1960 // long BC_WindowBase::get_repeat_id()
1962 // return top_level->next_repeat_id++;
1965 XEvent *BC_WindowBase::new_xevent()
1967 XEvent *event = new XEvent;
1968 memset(event, 0, sizeof(*event));
1972 #ifndef SINGLE_THREAD
1973 int BC_WindowBase::arm_repeat(int64_t duration)
1975 XEvent *event = new_xevent();
1976 XClientMessageEvent *ptr = (XClientMessageEvent*)event;
1977 ptr->type = ClientMessage;
1978 ptr->message_type = RepeaterXAtom;
1980 ptr->data.l[0] = duration;
1982 // Couldn't use XSendEvent since it locked up randomly.
1988 int BC_WindowBase::receive_custom_xatoms(xatom_event *event)
1993 int BC_WindowBase::send_custom_xatom(xatom_event *event)
1995 #ifndef SINGLE_THREAD
1996 XEvent *myevent = new_xevent();
1997 XClientMessageEvent *ptr = (XClientMessageEvent*)myevent;
1998 ptr->type = ClientMessage;
1999 ptr->message_type = event->message_type;
2000 ptr->format = event->format;
2001 ptr->data.l[0] = event->data.l[0];
2002 ptr->data.l[1] = event->data.l[1];
2003 ptr->data.l[2] = event->data.l[2];
2004 ptr->data.l[3] = event->data.l[3];
2005 ptr->data.l[4] = event->data.l[4];
2014 Atom BC_WindowBase::create_xatom(const char *atom_name)
2016 return XInternAtom(display, atom_name, False);
2019 int BC_WindowBase::get_atoms()
2021 SetDoneXAtom = XInternAtom(display, "BC_REPEAT_EVENT", False);
2022 RepeaterXAtom = XInternAtom(display, "BC_CLOSE_EVENT", False);
2023 DestroyAtom = XInternAtom(display, "BC_DESTROY_WINDOW", False);
2024 DelWinXAtom = XInternAtom(display, "WM_DELETE_WINDOW", False);
2025 if( (ProtoXAtom = XInternAtom(display, "WM_PROTOCOLS", False)) != 0 )
2026 XChangeProperty(display, win, ProtoXAtom, XA_ATOM, 32,
2027 PropModeReplace, (unsigned char *)&DelWinXAtom, True);
2033 void BC_WindowBase::init_cursors()
2035 arrow_cursor = XCreateFontCursor(display, XC_top_left_arrow);
2036 cross_cursor = XCreateFontCursor(display, XC_crosshair);
2037 ibeam_cursor = XCreateFontCursor(display, XC_xterm);
2038 vseparate_cursor = XCreateFontCursor(display, XC_sb_v_double_arrow);
2039 hseparate_cursor = XCreateFontCursor(display, XC_sb_h_double_arrow);
2040 move_cursor = XCreateFontCursor(display, XC_fleur);
2041 left_cursor = XCreateFontCursor(display, XC_sb_left_arrow);
2042 right_cursor = XCreateFontCursor(display, XC_sb_right_arrow);
2043 upright_arrow_cursor = XCreateFontCursor(display, XC_arrow);
2044 upleft_resize_cursor = XCreateFontCursor(display, XC_top_left_corner);
2045 upright_resize_cursor = XCreateFontCursor(display, XC_top_right_corner);
2046 downleft_resize_cursor = XCreateFontCursor(display, XC_bottom_left_corner);
2047 downright_resize_cursor = XCreateFontCursor(display, XC_bottom_right_corner);
2048 hourglass_cursor = XCreateFontCursor(display, XC_watch);
2049 grabbed_cursor = create_grab_cursor();
2051 static char cursor_data[] = { 0,0,0,0, 0,0,0,0 };
2052 Colormap colormap = DefaultColormap(display, screen);
2053 Pixmap pixmap_bottom = XCreateBitmapFromData(display,
2054 rootwin, cursor_data, 8, 8);
2055 XColor black, dummy;
2056 XAllocNamedColor(display, colormap, "black", &black, &dummy);
2057 transparent_cursor = XCreatePixmapCursor(display,
2058 pixmap_bottom, pixmap_bottom, &black, &black, 0, 0);
2059 // XDefineCursor(display, win, transparent_cursor);
2060 XFreePixmap(display, pixmap_bottom);
2063 int BC_WindowBase::evaluate_color_model(int client_byte_order, int server_byte_order, int depth)
2065 int color_model = BC_TRANSPARENCY;
2069 color_model = BC_RGB8;
2072 color_model = (server_byte_order == client_byte_order) ? BC_RGB565 : BC_BGR565;
2075 color_model = server_byte_order ? BC_BGR888 : BC_RGB888;
2078 color_model = server_byte_order ? BC_BGR8888 : BC_ARGB8888;
2084 int BC_WindowBase::init_colors()
2087 current_color_value = current_color_pixel = 0;
2089 // Get the real depth
2092 ximage = XCreateImage(top_level->display,
2094 top_level->default_depth,
2102 bits_per_pixel = ximage->bits_per_pixel;
2103 XDestroyImage(ximage);
2105 color_model = evaluate_color_model(client_byte_order,
2108 // Get the color model
2114 cmap = XCreateColormap(display, rootwin, vis, AllocNone);
2115 create_private_colors();
2119 cmap = DefaultColormap(display, screen);
2120 create_shared_colors();
2123 allocate_color_table();
2127 //cmap = DefaultColormap(display, screen);
2128 cmap = XCreateColormap(display, rootwin, vis, AllocNone );
2134 int BC_WindowBase::create_private_colors()
2139 for(int i = 0; i < 255; i++)
2141 color = (i & 0xc0) << 16;
2142 color += (i & 0x38) << 10;
2143 color += (i & 0x7) << 5;
2144 color_table[i][0] = color;
2146 create_shared_colors(); // overwrite the necessary colors on the table
2151 int BC_WindowBase::create_color(int color)
2153 if(total_colors == 256)
2155 // replace the closest match with an exact match
2156 color_table[get_color_rgb8(color)][0] = color;
2160 // add the color to the table
2161 color_table[total_colors][0] = color;
2167 int BC_WindowBase::create_shared_colors()
2169 create_color(BLACK);
2170 create_color(WHITE);
2172 create_color(LTGREY);
2173 create_color(MEGREY);
2174 create_color(MDGREY);
2175 create_color(DKGREY);
2177 create_color(LTCYAN);
2178 create_color(MECYAN);
2179 create_color(MDCYAN);
2180 create_color(DKCYAN);
2182 create_color(LTGREEN);
2183 create_color(GREEN);
2184 create_color(DKGREEN);
2186 create_color(LTPINK);
2190 create_color(LTBLUE);
2192 create_color(DKBLUE);
2194 create_color(LTYELLOW);
2195 create_color(MEYELLOW);
2196 create_color(MDYELLOW);
2197 create_color(DKYELLOW);
2199 create_color(LTPURPLE);
2200 create_color(MEPURPLE);
2201 create_color(MDPURPLE);
2202 create_color(DKPURPLE);
2204 create_color(FGGREY);
2205 create_color(MNBLUE);
2206 create_color(ORANGE);
2207 create_color(FTGREY);
2212 Cursor BC_WindowBase::create_grab_cursor()
2214 int iw = 23, iw1 = iw-1, iw2 = iw/2;
2215 int ih = 23, ih1 = ih-1, ih2 = ih/2;
2216 VFrame grab(iw,ih,BC_RGB888);
2218 grab.set_pixel_color(RED); // fg
2219 grab.draw_smooth(iw2,0, iw1,0, iw1,ih2);
2220 grab.draw_smooth(iw1,ih2, iw1,ih1, iw2,ih1);
2221 grab.draw_smooth(iw2,ih1, 0,ih1, 0,ih2);
2222 grab.draw_smooth(0,ih2, 0,0, iw2,0);
2223 grab.set_pixel_color(WHITE); // bg
2224 grab.draw_line(0,ih2, iw2-2,ih2);
2225 grab.draw_line(iw2+2,ih2, iw1,ih2);
2226 grab.draw_line(iw2,0, iw2,ih2-2);
2227 grab.draw_line(iw2,ih2+2, iw2,ih1);
2229 int bpl = (iw+7)/8, isz = bpl * ih;
2230 char img[isz]; memset(img, 0, isz);
2231 char msk[isz]; memset(msk, 0, isz);
2232 unsigned char **rows = grab.get_rows();
2233 for( int iy=0; iy<ih; ++iy ) {
2234 char *op = img + iy*bpl;
2235 char *mp = msk + iy*bpl;
2236 unsigned char *ip = rows[iy];
2237 for( int ix=0; ix<iw; ++ix,ip+=3 ) {
2238 if( ip[0] ) mp[ix>>3] |= (1<<(ix&7));
2239 if( !ip[1] ) op[ix>>3] |= (1<<(ix&7));
2242 unsigned long white_pix = WhitePixel(display, screen);
2243 unsigned long black_pix = BlackPixel(display, screen);
2244 Pixmap img_xpm = XCreatePixmapFromBitmapData(display, rootwin,
2245 img, iw,ih, white_pix,black_pix, 1);
2246 Pixmap msk_xpm = XCreatePixmapFromBitmapData(display, rootwin,
2247 msk, iw,ih, white_pix,black_pix, 1);
2250 fc.flags = bc.flags = DoRed | DoGreen | DoBlue;
2251 fc.red = 0xffff; fc.green = fc.blue = 0; // fg
2252 bc.red = bc.green = bc.blue = 0x0000; // bg
2253 Cursor cursor = XCreatePixmapCursor(display, img_xpm,msk_xpm, &fc,&bc, iw2,ih2);
2254 XFreePixmap(display, img_xpm);
2255 XFreePixmap(display, msk_xpm);
2259 int BC_WindowBase::allocate_color_table()
2261 int red, green, blue, color;
2264 for(int i = 0; i < total_colors; i++)
2266 color = color_table[i][0];
2267 red = (color & 0xFF0000) >> 16;
2268 green = (color & 0x00FF00) >> 8;
2269 blue = color & 0xFF;
2271 col.flags = DoRed | DoGreen | DoBlue;
2272 col.red = red<<8 | red;
2273 col.green = green<<8 | green;
2274 col.blue = blue<<8 | blue;
2276 XAllocColor(display, cmap, &col);
2277 color_table[i][1] = col.pixel;
2280 XInstallColormap(display, cmap);
2284 int BC_WindowBase::init_window_shape()
2286 if(bg_pixmap && bg_pixmap->use_alpha())
2288 XShapeCombineMask(top_level->display,
2289 this->win, ShapeBounding, 0, 0,
2290 bg_pixmap->get_alpha(), ShapeSet);
2296 int BC_WindowBase::init_gc()
2298 unsigned long gcmask;
2299 gcmask = GCFont | GCGraphicsExposures;
2302 gcvalues.font = mediumfont->fid; // set the font
2303 gcvalues.graphics_exposures = 0; // prevent expose events for every redraw
2304 gc = XCreateGC(display, rootwin, gcmask, &gcvalues);
2306 // gcmask = GCCapStyle | GCJoinStyle;
2307 // XGetGCValues(display, gc, gcmask, &gcvalues);
2308 // printf("BC_WindowBase::init_gc %d %d %d\n", __LINE__, gcvalues.cap_style, gcvalues.join_style);
2312 int BC_WindowBase::init_fonts()
2314 if( !(smallfont = XLoadQueryFont(display, _(resources.small_font))) )
2315 if( !(smallfont = XLoadQueryFont(display, _(resources.small_font2))) )
2316 smallfont = XLoadQueryFont(display, "fixed");
2317 if( !(mediumfont = XLoadQueryFont(display, _(resources.medium_font))) )
2318 if( !(mediumfont = XLoadQueryFont(display, _(resources.medium_font2))) )
2319 mediumfont = XLoadQueryFont(display, "fixed");
2320 if( !(largefont = XLoadQueryFont(display, _(resources.large_font))) )
2321 if( !(largefont = XLoadQueryFont(display, _(resources.large_font2))) )
2322 largefont = XLoadQueryFont(display, "fixed");
2323 if( !(bigfont = XLoadQueryFont(display, _(resources.big_font))) )
2324 if( !(bigfont = XLoadQueryFont(display, _(resources.big_font2))) )
2325 bigfont = XLoadQueryFont(display, "fixed");
2327 if((clockfont = XLoadQueryFont(display, _(resources.clock_font))) == NULL)
2328 if((clockfont = XLoadQueryFont(display, _(resources.clock_font2))) == NULL)
2329 clockfont = XLoadQueryFont(display, "fixed");
2332 if(get_resources()->use_fontset)
2337 // FIXME: should check the m,d,n values
2338 smallfontset = XCreateFontSet(display, resources.small_fontset, &m, &n, &d);
2340 smallfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2341 mediumfontset = XCreateFontSet(display, resources.medium_fontset, &m, &n, &d);
2342 if( !mediumfontset )
2343 mediumfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2344 largefontset = XCreateFontSet(display, resources.large_fontset, &m, &n, &d);
2346 largefontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2347 bigfontset = XCreateFontSet(display, resources.big_fontset, &m, &n, &d);
2349 bigfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2350 clockfontset = XCreateFontSet(display, resources.clock_fontset, &m, &n, &d);
2352 clockfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2353 if(clockfontset && bigfontset && largefontset && mediumfontset && smallfontset) {
2354 curr_fontset = mediumfontset;
2355 get_resources()->use_fontset = 1;
2359 get_resources()->use_fontset = 0;
2366 void BC_WindowBase::init_xft()
2369 if( !get_resources()->use_xft ) return;
2370 // apparently, xft is not reentrant, more than this is needed
2371 static Mutex xft_init_lock("BC_WindowBase::xft_init_lock", 0);
2372 xft_init_lock.lock("BC_WindowBase::init_xft");
2373 if(!(smallfont_xft =
2374 (resources.small_font_xft[0] == '-' ?
2375 xftFontOpenXlfd(display, screen, resources.small_font_xft) :
2376 xftFontOpenName(display, screen, resources.small_font_xft))) )
2377 if(!(smallfont_xft =
2378 xftFontOpenXlfd(display, screen, resources.small_font_xft2)))
2379 smallfont_xft = xftFontOpenXlfd(display, screen, "fixed");
2380 if(!(mediumfont_xft =
2381 (resources.medium_font_xft[0] == '-' ?
2382 xftFontOpenXlfd(display, screen, resources.medium_font_xft) :
2383 xftFontOpenName(display, screen, resources.medium_font_xft))) )
2384 if(!(mediumfont_xft =
2385 xftFontOpenXlfd(display, screen, resources.medium_font_xft2)))
2386 mediumfont_xft = xftFontOpenXlfd(display, screen, "fixed");
2387 if(!(largefont_xft =
2388 (resources.large_font_xft[0] == '-' ?
2389 xftFontOpenXlfd(display, screen, resources.large_font_xft) :
2390 xftFontOpenName(display, screen, resources.large_font_xft))) )
2391 if(!(largefont_xft =
2392 xftFontOpenXlfd(display, screen, resources.large_font_xft2)))
2393 largefont_xft = xftFontOpenXlfd(display, screen, "fixed");
2395 (resources.big_font_xft[0] == '-' ?
2396 xftFontOpenXlfd(display, screen, resources.big_font_xft) :
2397 xftFontOpenName(display, screen, resources.big_font_xft))) )
2399 xftFontOpenXlfd(display, screen, resources.big_font_xft2)))
2400 bigfont_xft = xftFontOpenXlfd(display, screen, "fixed");
2401 if(!(clockfont_xft =
2402 (resources.clock_font_xft[0] == '-' ?
2403 xftFontOpenXlfd(display, screen, resources.clock_font_xft) :
2404 xftFontOpenName(display, screen, resources.clock_font_xft))) )
2405 clockfont_xft = xftFontOpenXlfd(display, screen, "fixed");
2408 if(!(bold_smallfont_xft =
2409 (resources.small_b_font_xft[0] == '-' ?
2410 xftFontOpenXlfd(display, screen, resources.small_b_font_xft) :
2411 xftFontOpenName(display, screen, resources.small_b_font_xft))) )
2412 bold_smallfont_xft = xftFontOpenXlfd(display, screen, "fixed");
2413 if(!(bold_mediumfont_xft =
2414 (resources.medium_b_font_xft[0] == '-' ?
2415 xftFontOpenXlfd(display, screen, resources.medium_b_font_xft) :
2416 xftFontOpenName(display, screen, resources.medium_b_font_xft))) )
2417 bold_mediumfont_xft = xftFontOpenXlfd(display, screen, "fixed");
2418 if(!(bold_largefont_xft =
2419 (resources.large_b_font_xft[0] == '-' ?
2420 xftFontOpenXlfd(display, screen, resources.large_b_font_xft) :
2421 xftFontOpenName(display, screen, resources.large_b_font_xft))) )
2422 bold_largefont_xft = xftFontOpenXlfd(display, screen, "fixed");
2424 if( !smallfont_xft || !mediumfont_xft || !largefont_xft || !bigfont_xft ||
2425 !bold_largefont_xft || !bold_mediumfont_xft || !bold_largefont_xft ||
2427 printf("BC_WindowBase::init_fonts: no xft fonts found:"
2428 " %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n",
2429 resources.small_font_xft, smallfont_xft,
2430 resources.medium_font_xft, mediumfont_xft,
2431 resources.large_font_xft, largefont_xft,
2432 resources.big_font_xft, bigfont_xft,
2433 resources.clock_font_xft, clockfont_xft,
2434 resources.small_b_font_xft, bold_smallfont_xft,
2435 resources.medium_b_font_xft, bold_mediumfont_xft,
2436 resources.large_b_font_xft, bold_largefont_xft);
2437 get_resources()->use_xft = 0;
2440 // _XftDisplayInfo needs a lock.
2441 xftDefaultHasRender(display);
2442 xft_init_lock.unlock();
2446 void BC_WindowBase::init_im()
2448 XIMStyles *xim_styles;
2451 if(!(input_method = XOpenIM(display, NULL, NULL, NULL)))
2453 printf("BC_WindowBase::init_im: Could not open input method.\n");
2456 if(XGetIMValues(input_method, XNQueryInputStyle, &xim_styles, NULL) ||
2459 printf("BC_WindowBase::init_im: Input method doesn't support any styles.\n");
2460 XCloseIM(input_method);
2465 for(int z = 0; z < xim_styles->count_styles; z++)
2467 if(xim_styles->supported_styles[z] == (XIMPreeditNothing | XIMStatusNothing))
2469 xim_style = xim_styles->supported_styles[z];
2477 printf("BC_WindowBase::init_im: Input method doesn't support the style we need.\n");
2478 XCloseIM(input_method);
2482 input_context = XCreateIC(input_method, XNInputStyle, xim_style,
2483 XNClientWindow, win, XNFocusWindow, win, NULL);
2486 printf("BC_WindowBase::init_im: Failed to create input context.\n");
2487 XCloseIM(input_method);
2492 void BC_WindowBase::finit_im()
2494 if( input_context ) {
2495 XDestroyIC(input_context);
2498 if( input_method ) {
2499 XCloseIM(input_method);
2505 int BC_WindowBase::get_color(int64_t color)
2507 // return pixel of color
2508 // use this only for drawing subwindows not for bitmaps
2509 int i, test, difference;
2515 return get_color_rgb8(color);
2516 // test last color looked up
2517 if(current_color_value == color)
2518 return current_color_pixel;
2521 current_color_value = color;
2522 for(i = 0; i < total_colors; i++)
2524 if(color_table[i][0] == color)
2526 current_color_pixel = color_table[i][1];
2527 return current_color_pixel;
2531 // find nearest match
2532 difference = 0xFFFFFF;
2534 for(i = 0; i < total_colors; i++)
2536 test = abs((int)(color_table[i][0] - color));
2538 if(test < difference)
2540 current_color_pixel = color_table[i][1];
2544 return current_color_pixel;
2547 return get_color_rgb16(color);
2550 return get_color_bgr16(color);
2554 return client_byte_order == server_byte_order ?
2555 color : get_color_bgr24(color);
2563 int BC_WindowBase::get_color_rgb8(int color)
2567 pixel = (color & 0xc00000) >> 16;
2568 pixel += (color & 0xe000) >> 10;
2569 pixel += (color & 0xe0) >> 5;
2573 int64_t BC_WindowBase::get_color_rgb16(int color)
2576 result = (color & 0xf80000) >> 8;
2577 result += (color & 0xfc00) >> 5;
2578 result += (color & 0xf8) >> 3;
2583 int64_t BC_WindowBase::get_color_bgr16(int color)
2586 result = (color & 0xf80000) >> 19;
2587 result += (color & 0xfc00) >> 5;
2588 result += (color & 0xf8) << 8;
2593 int64_t BC_WindowBase::get_color_bgr24(int color)
2596 result = (color & 0xff) << 16;
2597 result += (color & 0xff00);
2598 result += (color & 0xff0000) >> 16;
2602 void BC_WindowBase::start_video()
2604 cursor_timer->update();
2606 // set_color(BLACK);
2607 // draw_box(0, 0, get_w(), get_h());
2611 void BC_WindowBase::stop_video()
2619 int64_t BC_WindowBase::get_color()
2621 return top_level->current_color;
2624 void BC_WindowBase::set_color(int64_t color)
2626 top_level->current_color = color;
2627 XSetForeground(top_level->display,
2629 top_level->get_color(color));
2632 void BC_WindowBase::set_opaque()
2634 XSetFunction(top_level->display, top_level->gc, GXcopy);
2637 void BC_WindowBase::set_inverse()
2639 XSetFunction(top_level->display, top_level->gc, GXxor);
2642 void BC_WindowBase::set_line_width(int value)
2644 this->line_width = value;
2645 XSetLineAttributes(top_level->display, top_level->gc, value, /* line_width */
2646 line_dashes == 0 ? LineSolid : LineOnOffDash, /* line_style */
2647 line_dashes == 0 ? CapRound : CapNotLast, /* cap_style */
2648 JoinMiter); /* join_style */
2650 if(line_dashes > 0) {
2651 const char dashes = line_dashes;
2652 XSetDashes(top_level->display, top_level->gc, 0, &dashes, 1);
2655 // XGCValues gcvalues;
2656 // unsigned long gcmask;
2657 // gcmask = GCCapStyle | GCJoinStyle;
2658 // XGetGCValues(top_level->display, top_level->gc, gcmask, &gcvalues);
2659 // printf("BC_WindowBase::set_line_width %d %d %d\n", __LINE__, gcvalues.cap_style, gcvalues.join_style);
2662 void BC_WindowBase::set_line_dashes(int value)
2664 line_dashes = value;
2665 // call XSetLineAttributes
2666 set_line_width(line_width);
2670 Cursor BC_WindowBase::get_cursor_struct(int cursor)
2674 case ARROW_CURSOR: return top_level->arrow_cursor;
2675 case CROSS_CURSOR: return top_level->cross_cursor;
2676 case IBEAM_CURSOR: return top_level->ibeam_cursor;
2677 case VSEPARATE_CURSOR: return top_level->vseparate_cursor;
2678 case HSEPARATE_CURSOR: return top_level->hseparate_cursor;
2679 case MOVE_CURSOR: return top_level->move_cursor;
2680 case LEFT_CURSOR: return top_level->left_cursor;
2681 case RIGHT_CURSOR: return top_level->right_cursor;
2682 case UPRIGHT_ARROW_CURSOR: return top_level->upright_arrow_cursor;
2683 case UPLEFT_RESIZE: return top_level->upleft_resize_cursor;
2684 case UPRIGHT_RESIZE: return top_level->upright_resize_cursor;
2685 case DOWNLEFT_RESIZE: return top_level->downleft_resize_cursor;
2686 case DOWNRIGHT_RESIZE: return top_level->downright_resize_cursor;
2687 case HOURGLASS_CURSOR: return top_level->hourglass_cursor;
2688 case TRANSPARENT_CURSOR: return top_level->transparent_cursor;
2689 case GRABBED_CURSOR: return top_level->grabbed_cursor;
2694 void BC_WindowBase::set_cursor(int cursor, int override, int flush)
2696 // inherit cursor from parent
2699 XUndefineCursor(top_level->display, win);
2700 current_cursor = cursor;
2703 // don't change cursor if overridden
2704 if((!top_level->is_hourglass && !is_transparent) ||
2707 XDefineCursor(top_level->display, win, get_cursor_struct(cursor));
2708 if(flush) this->flush();
2711 if(!override) current_cursor = cursor;
2714 void BC_WindowBase::set_x_cursor(int cursor)
2716 temp_cursor = XCreateFontCursor(top_level->display, cursor);
2717 XDefineCursor(top_level->display, win, temp_cursor);
2718 current_cursor = cursor;
2722 int BC_WindowBase::get_cursor()
2724 return current_cursor;
2727 void BC_WindowBase::start_hourglass()
2729 top_level->start_hourglass_recursive();
2733 void BC_WindowBase::stop_hourglass()
2735 top_level->stop_hourglass_recursive();
2739 void BC_WindowBase::start_hourglass_recursive()
2741 if(this == top_level)
2749 set_cursor(HOURGLASS_CURSOR, 1, 0);
2750 for(int i = 0; i < subwindows->total; i++)
2752 subwindows->values[i]->start_hourglass_recursive();
2757 void BC_WindowBase::stop_hourglass_recursive()
2759 if(this == top_level)
2761 if(hourglass_total == 0) return;
2762 top_level->hourglass_total--;
2765 if(!top_level->hourglass_total)
2767 top_level->is_hourglass = 0;
2769 // Cause set_cursor to perform change
2771 set_cursor(current_cursor, 1, 0);
2773 for(int i = 0; i < subwindows->total; i++)
2775 subwindows->values[i]->stop_hourglass_recursive();
2783 XFontStruct* BC_WindowBase::get_font_struct(int font)
2785 // Clear out unrelated flags
2786 if(font & BOLDFACE) font ^= BOLDFACE;
2789 case SMALLFONT: return top_level->smallfont; break;
2790 case MEDIUMFONT: return top_level->mediumfont; break;
2791 case LARGEFONT: return top_level->largefont; break;
2792 case BIGFONT: return top_level->bigfont; break;
2793 case CLOCKFONT: return top_level->clockfont; break;
2798 XFontSet BC_WindowBase::get_fontset(int font)
2802 if(get_resources()->use_fontset)
2804 switch(font & 0xff) {
2805 case SMALLFONT: fs = top_level->smallfontset; break;
2806 case MEDIUMFONT: fs = top_level->mediumfontset; break;
2807 case LARGEFONT: fs = top_level->largefontset; break;
2808 case BIGFONT: fs = top_level->bigfontset; break;
2809 case CLOCKFONT: fs = top_level->clockfontset; break;
2817 XftFont* BC_WindowBase::get_xft_struct(int font)
2820 case SMALLFONT: return (XftFont*)top_level->smallfont_xft;
2821 case MEDIUMFONT: return (XftFont*)top_level->mediumfont_xft;
2822 case LARGEFONT: return (XftFont*)top_level->largefont_xft;
2823 case BIGFONT: return (XftFont*)top_level->bigfont_xft;
2824 case CLOCKFONT: return (XftFont*)top_level->clockfont_xft;
2825 case MEDIUMFONT_3D: return (XftFont*)top_level->bold_mediumfont_xft;
2826 case SMALLFONT_3D: return (XftFont*)top_level->bold_smallfont_xft;
2827 case LARGEFONT_3D: return (XftFont*)top_level->bold_largefont_xft;
2835 int BC_WindowBase::get_current_font()
2837 return top_level->current_font;
2840 void BC_WindowBase::set_font(int font)
2842 top_level->current_font = font;
2845 if(get_resources()->use_xft) {}
2848 if(get_resources()->use_fontset) {
2852 if(get_font_struct(font))
2854 XSetFont(top_level->display, top_level->gc, get_font_struct(font)->fid);
2860 void BC_WindowBase::set_fontset(int font)
2864 if(get_resources()->use_fontset) {
2866 case SMALLFONT: fs = top_level->smallfontset; break;
2867 case MEDIUMFONT: fs = top_level->mediumfontset; break;
2868 case LARGEFONT: fs = top_level->largefontset; break;
2869 case BIGFONT: fs = top_level->bigfontset; break;
2870 case CLOCKFONT: fs = top_level->clockfontset; break;
2878 XFontSet BC_WindowBase::get_curr_fontset(void)
2880 if(get_resources()->use_fontset)
2881 return curr_fontset;
2885 int BC_WindowBase::get_single_text_width(int font, const char *text, int length)
2888 if(get_resources()->use_xft && get_xft_struct(font))
2891 #ifdef X_HAVE_UTF8_STRING
2892 if(get_resources()->locale_utf8)
2894 xftTextExtentsUtf8(top_level->display,
2895 get_xft_struct(font),
2896 (const XftChar8 *)text,
2903 xftTextExtents8(top_level->display,
2904 get_xft_struct(font),
2905 (const XftChar8 *)text,
2909 return extents.xOff;
2913 if(get_resources()->use_fontset && top_level->get_fontset(font))
2914 return XmbTextEscapement(top_level->get_fontset(font), text, length);
2916 if(get_font_struct(font))
2917 return XTextWidth(get_font_struct(font), text, length);
2923 case MEDIUM_7SEGMENT:
2924 return get_resources()->medium_7segment[0]->get_w() * length;
2934 int BC_WindowBase::get_text_width(int font, const char *text, int length)
2936 int i, j, w = 0, line_w = 0;
2937 if(length < 0) length = strlen(text);
2939 for(i = 0, j = 0; i <= length; i++)
2944 line_w = get_single_text_width(font, &text[j], i - j);
2950 line_w = get_single_text_width(font, &text[j], length - j);
2952 if(line_w > w) w = line_w;
2955 if(i > length && w == 0)
2957 w = get_single_text_width(font, text, length);
2963 int BC_WindowBase::get_text_width(int font, const wchar_t *text, int length)
2966 if( length < 0 ) length = wcslen(text);
2968 for( i=j=0; i<length && text[i]; ++i ) {
2969 if( text[i] != '\n' ) continue;
2971 int lw = get_single_text_width(font, &text[j], i-j);
2972 if( w < lw ) w = lw;
2977 int lw = get_single_text_width(font, &text[j], length-j);
2978 if( w < lw ) w = lw;
2984 int BC_WindowBase::get_text_ascent(int font)
2988 if( (fstruct = get_xft_struct(font)) != 0 )
2989 return fstruct->ascent;
2991 if(get_resources()->use_fontset && top_level->get_fontset(font))
2993 XFontSetExtents *extents;
2995 extents = XExtentsOfFontSet(top_level->get_fontset(font));
2996 return -extents->max_logical_extent.y;
2999 if(get_font_struct(font))
3000 return top_level->get_font_struct(font)->ascent;
3003 case MEDIUM_7SEGMENT:
3004 return get_resources()->medium_7segment[0]->get_h();
3009 int BC_WindowBase::get_text_descent(int font)
3013 if( (fstruct = get_xft_struct(font)) != 0 )
3014 return fstruct->descent;
3016 if(get_resources()->use_fontset && top_level->get_fontset(font)) {
3017 XFontSetExtents *extents;
3018 extents = XExtentsOfFontSet(top_level->get_fontset(font));
3019 return (extents->max_logical_extent.height
3020 + extents->max_logical_extent.y);
3023 if(get_font_struct(font))
3024 return top_level->get_font_struct(font)->descent;
3029 int BC_WindowBase::get_text_height(int font, const char *text)
3034 if( (fstruct = get_xft_struct(font)) != 0 )
3035 rowh = fstruct->height;
3038 rowh = get_text_ascent(font) + get_text_descent(font);
3040 if(!text) return rowh;
3042 // Add height of lines
3043 int h = 0, i, length = strlen(text);
3044 for(i = 0; i <= length; i++)
3055 BC_Bitmap* BC_WindowBase::new_bitmap(int w, int h, int color_model)
3057 if(color_model < 0) color_model = top_level->get_color_model();
3058 return new BC_Bitmap(top_level, w, h, color_model);
3061 void BC_WindowBase::init_wait()
3063 #ifndef SINGLE_THREAD
3064 if(window_type != MAIN_WINDOW)
3065 top_level->init_wait();
3066 init_lock->lock("BC_WindowBase::init_wait");
3067 init_lock->unlock();
3071 int BC_WindowBase::accel_available(int color_model, int lock_it)
3073 if( window_type != MAIN_WINDOW )
3074 return top_level->accel_available(color_model, lock_it);
3076 lock_window("BC_WindowBase::accel_available");
3078 switch(color_model) {
3080 grab_port_id(color_model);
3084 grab_port_id(color_model);
3093 //printf("BC_WindowBase::accel_available %d %d\n", color_model, xvideo_port_id);
3094 return xvideo_port_id >= 0 ? 1 : 0;
3098 int BC_WindowBase::grab_port_id(int color_model)
3100 if( !get_resources()->use_xvideo || // disabled
3101 !get_resources()->use_shm ) // Only local server is fast enough.
3103 if( xvideo_port_id >= 0 )
3104 return xvideo_port_id;
3106 unsigned int ver, rev, reqBase, eventBase, errorBase;
3107 if( Success != XvQueryExtension(display, // XV extension is available
3108 &ver, &rev, &reqBase, &eventBase, &errorBase) )
3111 // XV adaptors are available
3112 unsigned int numAdapt = 0;
3113 XvAdaptorInfo *info = 0;
3114 XvQueryAdaptors(display, DefaultRootWindow(display), &numAdapt, &info);
3118 // Translate from color_model to X color model
3119 int x_color_model = BC_CModels::bc_to_x(color_model);
3121 // Get adaptor with desired color model
3122 for( int i = 0; i < (int)numAdapt && xvideo_port_id == -1; i++) {
3123 if( !(info[i].type & XvImageMask) || !info[i].num_ports ) continue;
3124 // adaptor supports XvImages
3125 int numFormats = 0, numPorts = info[i].num_ports;
3126 XvImageFormatValues *formats =
3127 XvListImageFormats(display, info[i].base_id, &numFormats);
3128 if( !formats ) continue;
3130 for( int j=0; j<numFormats && xvideo_port_id<0; ++j ) {
3131 if( formats[j].id != x_color_model ) continue;
3132 // this adaptor supports the desired format, grab a port
3133 for( int k=0; k<numPorts; ++k ) {
3134 if( Success == XvGrabPort(top_level->display,
3135 info[i].base_id+k, CurrentTime) ) {
3136 //printf("BC_WindowBase::grab_port_id %llx\n", info[i].base_id);
3137 xvideo_port_id = info[i].base_id + k;
3145 XvFreeAdaptorInfo(info);
3147 return xvideo_port_id;
3151 int BC_WindowBase::show_window(int flush)
3153 for(int i = 0; i < subwindows->size(); i++)
3155 subwindows->get(i)->show_window(0);
3158 XMapWindow(top_level->display, win);
3159 if(flush) XFlush(top_level->display);
3160 // XSync(top_level->display, 0);
3165 int BC_WindowBase::hide_window(int flush)
3167 for(int i = 0; i < subwindows->size(); i++)
3169 subwindows->get(i)->hide_window(0);
3172 XUnmapWindow(top_level->display, win);
3173 if(flush) this->flush();
3178 BC_MenuBar* BC_WindowBase::add_menubar(BC_MenuBar *menu_bar)
3180 subwindows->append((BC_SubWindow*)menu_bar);
3182 menu_bar->parent_window = this;
3183 menu_bar->top_level = this->top_level;
3184 menu_bar->initialize();
3188 BC_WindowBase* BC_WindowBase::add_popup(BC_WindowBase *window)
3190 //printf("BC_WindowBase::add_popup window=%p win=%p\n", window, window->win);
3191 if(this != top_level) return top_level->add_popup(window);
3192 popups.append(window);
3196 void BC_WindowBase::remove_popup(BC_WindowBase *window)
3198 //printf("BC_WindowBase::remove_popup %d size=%d window=%p win=%p\n", __LINE__, popups.size(), window, window->win);
3199 if(this != top_level)
3200 top_level->remove_popup(window);
3202 popups.remove(window);
3203 //printf("BC_WindowBase::remove_popup %d size=%d window=%p win=%p\n", __LINE__, popups.size(), window, window->win);
3207 BC_WindowBase* BC_WindowBase::add_subwindow(BC_WindowBase *subwindow)
3209 subwindows->append(subwindow);
3211 if(subwindow->bg_color == -1) subwindow->bg_color = this->bg_color;
3213 // parent window must be set before the subwindow initialization
3214 subwindow->parent_window = this;
3215 subwindow->top_level = this->top_level;
3217 // Execute derived initialization
3218 subwindow->initialize();
3223 BC_WindowBase* BC_WindowBase::add_tool(BC_WindowBase *subwindow)
3225 return add_subwindow(subwindow);
3228 int BC_WindowBase::flash(int x, int y, int w, int h, int flush)
3230 if( !top_level->flash_enabled ) return 0;
3231 //printf("BC_WindowBase::flash %d %d %d %d %d\n", __LINE__, w, h, this->w, this->h);
3233 XSetWindowBackgroundPixmap(top_level->display, win, pixmap->opaque_pixmap);
3236 XClearArea(top_level->display, win, x, y, w, h, 0);
3240 XClearWindow(top_level->display, win);
3248 int BC_WindowBase::flash(int flush)
3250 flash(-1, -1, -1, -1, flush);
3254 void BC_WindowBase::flush()
3256 //if(!get_window_lock())
3257 // printf("BC_WindowBase::flush %s not locked\n", top_level->title);
3258 // X gets hosed if Flush/Sync are not user locked (at libX11-1.1.5 / libxcb-1.1.91)
3259 // _XReply deadlocks in condition_wait waiting for xlib lock when waiters!=-1
3260 int locked = get_window_lock();
3261 if( !locked ) lock_window("BC_WindowBase::flush");
3262 XFlush(top_level->display);
3263 if( !locked ) unlock_window();
3266 void BC_WindowBase::sync_display()
3268 int locked = get_window_lock();
3269 if( !locked ) lock_window("BC_WindowBase::sync_display");
3270 XSync(top_level->display, False);
3271 if( !locked ) unlock_window();
3274 int BC_WindowBase::get_window_lock()
3276 #ifdef SINGLE_THREAD
3277 return BC_Display::display_global->get_display_locked();
3279 return top_level->window_lock;
3283 int BC_WindowBase::lock_window(const char *location)
3285 if(top_level && top_level != this)
3287 top_level->lock_window(location);
3292 SET_LOCK(this, title, location);
3293 #ifdef SINGLE_THREAD
3294 BC_Display::lock_display(location);
3296 XLockDisplay(top_level->display);
3297 top_level->display_lock_owner = pthread_self();
3300 ++top_level->window_lock;
3304 printf("BC_WindowBase::lock_window top_level NULL\n");
3309 int BC_WindowBase::unlock_window()
3311 if(top_level && top_level != this)
3313 top_level->unlock_window();
3320 // if(!top_level->window_lock)
3322 // printf("BC_WindowBase::unlock_window %d %s already unlocked\n",
3326 if( top_level->window_lock > 0 )
3327 if( --top_level->window_lock == 0 )
3328 top_level->display_lock_owner = 0;
3329 #ifdef SINGLE_THREAD
3330 BC_Display::unlock_display();
3332 XUnlockDisplay(top_level->display);
3337 printf("BC_WindowBase::unlock_window top_level NULL\n");
3342 void BC_WindowBase::set_done(int return_value)
3344 if(done_set) return;
3346 if(window_type != MAIN_WINDOW)
3347 top_level->set_done(return_value);
3350 #ifdef SINGLE_THREAD
3351 this->return_value = return_value;
3352 BC_Display::display_global->arm_completion(this);
3353 completion_lock->unlock();
3354 #else // SINGLE_THREAD
3356 if( !event_thread ) return;
3357 XEvent *event = new_xevent();
3358 XClientMessageEvent *ptr = (XClientMessageEvent*)event;
3359 event->type = ClientMessage;
3360 ptr->message_type = SetDoneXAtom;
3362 this->return_value = return_value;
3363 // May lock up here because XSendEvent doesn't work too well
3364 // asynchronous with XNextEvent.
3365 // This causes BC_WindowEvents to forward a copy of the event to run_window where
3367 // Deletion of event_thread is done at the end of BC_WindowBase::run_window() - by calling the destructor
3373 void BC_WindowBase::close(int return_value)
3375 hide_window(); flush();
3376 set_done(return_value);
3379 int BC_WindowBase::grab(BC_WindowBase *window)
3381 if( window->active_grab && this != window->active_grab ) return 0;
3382 window->active_grab = this;
3383 this->grab_active = window;
3386 int BC_WindowBase::ungrab(BC_WindowBase *window)
3388 if( window->active_grab && this != window->active_grab ) return 0;
3389 window->active_grab = 0;
3390 this->grab_active = 0;
3393 int BC_WindowBase::grab_event_count()
3396 #ifndef SINGLE_THREAD
3397 result = grab_active->get_event_count();
3401 int BC_WindowBase::grab_buttons()
3403 XSync(top_level->display, False);
3404 if( XGrabButton(top_level->display, AnyButton, AnyModifier,
3405 top_level->rootwin, True, ButtonPressMask | ButtonReleaseMask,
3406 GrabModeAsync, GrabModeSync, None, None) == GrabSuccess ) {
3407 set_active_subwindow(this);
3412 void BC_WindowBase::ungrab_buttons()
3414 XUngrabButton(top_level->display, AnyButton, AnyModifier, top_level->rootwin);
3415 set_active_subwindow(0);
3418 void BC_WindowBase::grab_cursor()
3420 Cursor cursor_grab = get_cursor_struct(GRABBED_CURSOR);
3421 XGrabPointer(top_level->display, top_level->rootwin, True,
3422 PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
3423 GrabModeAsync, GrabModeAsync, None, cursor_grab, CurrentTime);
3425 void BC_WindowBase::ungrab_cursor()
3427 XUngrabPointer(top_level->display, CurrentTime);
3431 // WidthOfScreen/HeightOfScreen of XDefaultScreenOfDisplay
3432 // this is the bounding box of all the screens
3434 int BC_WindowBase::get_root_w(int lock_display)
3436 if(lock_display) lock_window("BC_WindowBase::get_root_w");
3437 Screen *def_screen = XDefaultScreenOfDisplay(top_level->display);
3438 int result = WidthOfScreen(def_screen);
3439 if(lock_display) unlock_window();
3443 int BC_WindowBase::get_root_h(int lock_display)
3445 if(lock_display) lock_window("BC_WindowBase::get_root_h");
3446 Screen *def_screen = XDefaultScreenOfDisplay(top_level->display);
3447 int result = HeightOfScreen(def_screen);
3448 if(lock_display) unlock_window();
3452 XineramaScreenInfo *
3453 BC_WindowBase::get_xinerama_info(int screen)
3455 if( !xinerama_info || !xinerama_screens ) return 0;
3457 for( int i=0; i<xinerama_screens; ++i )
3458 if( xinerama_info[i].screen_number == screen )
3459 return &xinerama_info[i];
3462 int top_x = get_x(), top_y = get_y();
3463 if( BC_DisplayInfo::left_border >= 0 ) top_x += BC_DisplayInfo::left_border;
3464 if( BC_DisplayInfo::top_border >= 0 ) top_y += BC_DisplayInfo::top_border;
3465 for( int i=0; i<xinerama_screens; ++i ) {
3466 int scr_y = top_y - xinerama_info[i].y_org;
3467 if( scr_y < 0 || scr_y >= xinerama_info[i].height ) continue;
3468 int scr_x = top_x - xinerama_info[i].x_org;
3469 if( scr_x >= 0 && scr_x < xinerama_info[i].width )
3470 return &xinerama_info[i];
3475 void BC_WindowBase::get_fullscreen_geometry(int &wx, int &wy, int &ww, int &wh)
3477 XineramaScreenInfo *info = top_level->get_xinerama_info(-1);
3479 wx = info->x_org; wy = info->y_org;
3480 ww = info->width; wh = info->height;
3483 wx = get_screen_x(0, -1);
3484 wy = get_screen_y(0, -1);
3485 int scr_w0 = get_screen_w(0, 0);
3486 int root_w = get_root_w(0);
3487 int root_h = get_root_h(0);
3488 if( root_w > scr_w0 ) { // multi-headed
3489 if( wx >= scr_w0 ) {
3490 // assumes right side is the big one
3491 ww = root_w - scr_w0;
3495 // use same aspect ratio to compute left height
3497 wh = (w*root_h) / (root_w-scr_w0);
3507 int BC_WindowBase::get_screen_x(int lock_display, int screen)
3510 if(lock_display) lock_window("BC_WindowBase::get_screen_x");
3511 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3514 int root_w = get_root_w(0);
3515 int root_h = get_root_h(0);
3516 // Shift X based on position of current window if dual head
3517 if( (float)root_w/root_h > 1.8 ) {
3518 root_w = get_screen_w(0, 0);
3519 if( top_level->get_x() >= root_w )
3524 result = info->x_org;
3525 if(lock_display) unlock_window();
3529 int BC_WindowBase::get_screen_y(int lock_display, int screen)
3531 if(lock_display) lock_window("BC_WindowBase::get_screen_y");
3532 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3533 int result = !info ? 0 : info->y_org;
3534 if(lock_display) unlock_window();
3538 int BC_WindowBase::get_screen_w(int lock_display, int screen)
3541 if(lock_display) lock_window("BC_WindowBase::get_screen_w");
3542 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3544 int width = get_root_w(0);
3545 int height = get_root_h(0);
3546 if( (float)width/height > 1.8 ) {
3547 // If dual head, the screen width is > 16x9
3548 // but we only want to fill one screen
3549 // this code assumes the "big" screen is on the right
3550 int scr_w0 = width / 2;
3552 case 600: scr_w0 = 800; break;
3553 case 720: scr_w0 = 1280; break;
3554 case 1024: scr_w0 = 1280; break;
3555 case 1200: scr_w0 = 1600; break;
3556 case 1080: scr_w0 = 1920; break;
3558 int scr_w1 = width - scr_w0;
3559 result = screen > 0 ? scr_w1 :
3560 screen == 0 ? scr_w0 :
3561 top_level->get_x() < scr_w0 ? scr_w0 : scr_w1;
3567 result = info->width;
3568 if(lock_display) unlock_window();
3572 int BC_WindowBase::get_screen_h(int lock_display, int screen)
3574 if(lock_display) lock_window("BC_WindowBase::get_screen_h");
3575 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3576 int result = info ? info->height : get_root_h(0);
3577 if(lock_display) unlock_window();
3581 // Bottom right corner
3582 int BC_WindowBase::get_x2()
3587 int BC_WindowBase::get_y2()
3592 int BC_WindowBase::get_video_on()
3597 int BC_WindowBase::get_hidden()
3599 return top_level->hidden;
3602 int BC_WindowBase::cursor_inside()
3604 return (top_level->cursor_x >= 0 &&
3605 top_level->cursor_y >= 0 &&
3606 top_level->cursor_x < w &&
3607 top_level->cursor_y < h);
3610 BC_WindowBase* BC_WindowBase::get_top_level()
3615 BC_WindowBase* BC_WindowBase::get_parent()
3617 return parent_window;
3620 int BC_WindowBase::get_color_model()
3622 return top_level->color_model;
3625 BC_Resources* BC_WindowBase::get_resources()
3627 return &BC_WindowBase::resources;
3630 BC_Synchronous* BC_WindowBase::get_synchronous()
3632 return BC_WindowBase::resources.get_synchronous();
3635 int BC_WindowBase::get_bg_color()
3640 void BC_WindowBase::set_bg_color(int color)
3642 this->bg_color = color;
3645 BC_Pixmap* BC_WindowBase::get_bg_pixmap()
3650 void BC_WindowBase::set_active_subwindow(BC_WindowBase *subwindow)
3652 top_level->active_subwindow = subwindow;
3655 int BC_WindowBase::activate()
3660 int BC_WindowBase::deactivate()
3662 if(window_type == MAIN_WINDOW)
3664 if( top_level->active_menubar ) {
3665 top_level->active_menubar->deactivate();
3666 top_level->active_menubar = 0;
3668 if( top_level->active_popup_menu ) {
3669 top_level->active_popup_menu->deactivate();
3670 top_level->active_popup_menu = 0;
3672 if( top_level->active_subwindow ) {
3673 top_level->active_subwindow->deactivate();
3674 top_level->active_subwindow = 0;
3676 if( top_level->motion_events && top_level->last_motion_win == this->win )
3677 top_level->motion_events = 0;
3683 int BC_WindowBase::cycle_textboxes(int amount)
3686 BC_WindowBase *new_textbox = 0;
3690 BC_WindowBase *first_textbox = 0;
3691 find_next_textbox(&first_textbox, &new_textbox, result);
3692 if(!new_textbox) new_textbox = first_textbox;
3698 BC_WindowBase *last_textbox = 0;
3699 find_prev_textbox(&last_textbox, &new_textbox, result);
3700 if(!new_textbox) new_textbox = last_textbox;
3704 if(new_textbox != active_subwindow)
3707 new_textbox->activate();
3713 int BC_WindowBase::find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result)
3715 // Search subwindows for textbox
3716 for(int i = 0; i < subwindows->total && result < 2; i++)
3718 BC_WindowBase *test_subwindow = subwindows->values[i];
3719 test_subwindow->find_next_textbox(first_textbox, next_textbox, result);
3726 if(!*first_textbox) *first_textbox = this;
3730 if(top_level->active_subwindow == this)
3736 *next_textbox = this;
3743 int BC_WindowBase::find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result)
3749 if(!*last_textbox) *last_textbox = this;
3753 if(top_level->active_subwindow == this)
3759 *prev_textbox = this;
3764 // Search subwindows for textbox
3765 for(int i = subwindows->total - 1; i >= 0 && result < 2; i--)
3767 BC_WindowBase *test_subwindow = subwindows->values[i];
3768 test_subwindow->find_prev_textbox(last_textbox, prev_textbox, result);
3773 BC_Clipboard* BC_WindowBase::get_clipboard()
3775 #ifdef SINGLE_THREAD
3776 return BC_Display::display_global->clipboard;
3778 return top_level->clipboard;
3782 Atom BC_WindowBase::to_clipboard(const char *data, long len, int clipboard_num)
3784 return get_clipboard()->to_clipboard(this, data, len, clipboard_num);
3787 long BC_WindowBase::from_clipboard(char *data, long maxlen, int clipboard_num)
3789 return get_clipboard()->from_clipboard(data, maxlen, clipboard_num);
3792 long BC_WindowBase::clipboard_len(int clipboard_num)
3794 return get_clipboard()->clipboard_len(clipboard_num);
3797 int BC_WindowBase::do_selection_clear(Window win)
3799 top_level->event_win = win;
3800 return dispatch_selection_clear();
3803 int BC_WindowBase::dispatch_selection_clear()
3806 for( int i=0; i<subwindows->total && !result; ++i )
3807 result = subwindows->values[i]->dispatch_selection_clear();
3809 result = selection_clear_event();
3814 void BC_WindowBase::get_relative_cursor(int &x, int &y, int lock_window)
3816 int abs_x, abs_y, win_x, win_y;
3817 unsigned int temp_mask;
3820 if(lock_window) this->lock_window("BC_WindowBase::get_relative_cursor");
3821 XQueryPointer(top_level->display, top_level->win,
3822 &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y,
3825 XTranslateCoordinates(top_level->display, top_level->rootwin,
3826 win, abs_x, abs_y, &x, &y, &temp_win);
3827 if(lock_window) this->unlock_window();
3829 int BC_WindowBase::get_relative_cursor_x(int lock_window)
3832 get_relative_cursor(x, y, lock_window);
3835 int BC_WindowBase::get_relative_cursor_y(int lock_window)
3838 get_relative_cursor(x, y, lock_window);
3842 void BC_WindowBase::get_abs_cursor(int &abs_x, int &abs_y, int lock_window)
3845 unsigned int temp_mask;
3848 if(lock_window) this->lock_window("BC_WindowBase::get_abs_cursor");
3849 XQueryPointer(top_level->display, top_level->win,
3850 &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y,
3852 if(lock_window) this->unlock_window();
3854 int BC_WindowBase::get_abs_cursor_x(int lock_window)
3857 get_abs_cursor(abs_x, abs_y, lock_window);
3860 int BC_WindowBase::get_abs_cursor_y(int lock_window)
3863 get_abs_cursor(abs_x, abs_y, lock_window);
3867 void BC_WindowBase::get_pop_cursor(int &px, int &py, int lock_window)
3870 get_abs_cursor(px, py, lock_window);
3871 if( px < margin ) px = margin;
3872 if( py < margin ) py = margin;
3873 int wd = get_screen_w(lock_window,-1) - margin;
3874 if( px > wd ) px = wd;
3875 int ht = get_screen_h(lock_window,-1) - margin;
3876 if( py > ht ) py = ht;
3878 int BC_WindowBase::get_pop_cursor_x(int lock_window)
3881 get_pop_cursor(px, py, lock_window);
3884 int BC_WindowBase::get_pop_cursor_y(int lock_window)
3887 get_pop_cursor(px, py, lock_window);
3891 int BC_WindowBase::match_window(Window win)
3893 if (this->win == win) return 1;
3895 for(int i = 0; i < subwindows->total; i++) {
3896 result = subwindows->values[i]->match_window(win);
3897 if (result) return result;
3903 int BC_WindowBase::get_cursor_over_window()
3905 int abs_x, abs_y, win_x, win_y;
3906 unsigned int mask_return;
3907 Window root_return, child_return;
3909 int ret = XQueryPointer(top_level->display, top_level->rootwin,
3910 &root_return, &child_return, &abs_x, &abs_y,
3911 &win_x, &win_y, &mask_return);
3912 if( ret && child_return == None ) ret = 0;
3913 if( ret && win != child_return )
3914 ret = top_level->match_window(child_return);
3915 // query pointer can return a window manager window with this top_level as a child
3916 // for kde this can be two levels deep
3917 unsigned int nchildren_return = 0;
3918 Window parent_return, *children_return = 0;
3919 Window top_win = top_level->win;
3920 while( !ret && top_win != top_level->rootwin && top_win != root_return &&
3921 XQueryTree(top_level->display, top_win, &root_return,
3922 &parent_return, &children_return, &nchildren_return) ) {
3923 if( children_return ) XFree(children_return);
3924 if( (top_win=parent_return) == child_return ) ret = 1;
3929 int BC_WindowBase::cursor_above()
3932 get_relative_cursor(rx, ry);
3933 return rx < 0 || rx >= get_w() ||
3934 ry < 0 || ry >= get_h() ? 0 : 1;
3937 int BC_WindowBase::get_drag_x()
3939 return top_level->drag_x;
3942 int BC_WindowBase::get_drag_y()
3944 return top_level->drag_y;
3947 int BC_WindowBase::get_cursor_x()
3949 return top_level->cursor_x;
3952 int BC_WindowBase::get_cursor_y()
3954 return top_level->cursor_y;
3957 int BC_WindowBase::dump_windows()
3959 printf("\tBC_WindowBase::dump_windows window=%p win=%p '%s', %dx%d+%d+%d %s\n",
3960 this, (void*)this->win, title, w,h,x,y, typeid(*this).name());
3961 for(int i = 0; i < subwindows->size(); i++)
3962 subwindows->get(i)->dump_windows();
3963 for(int i = 0; i < popups.size(); i++) {
3964 BC_WindowBase *p = popups[i];
3965 printf("\tBC_WindowBase::dump_windows popup=%p win=%p '%s', %dx%d+%d+%d %s\n",
3966 p, (void*)p->win, p->title, p->w,p->h,p->x,p->y, typeid(*p).name());
3971 int BC_WindowBase::is_event_win()
3973 return this->win == top_level->event_win;
3976 void BC_WindowBase::set_dragging(int value)
3978 is_dragging = value;
3981 int BC_WindowBase::get_dragging()
3986 int BC_WindowBase::get_buttonpress()
3988 return top_level->button_number;
3991 int BC_WindowBase::get_button_down()
3993 return top_level->button_down;
3996 int BC_WindowBase::alt_down()
3998 return top_level->alt_mask;
4001 int BC_WindowBase::shift_down()
4003 return top_level->shift_mask;
4006 int BC_WindowBase::ctrl_down()
4008 return top_level->ctrl_mask;
4011 wchar_t* BC_WindowBase::get_wkeystring(int *length)
4014 *length = top_level->wkey_string_length;
4015 return top_level->wkey_string;
4018 #ifdef X_HAVE_UTF8_STRING
4019 char* BC_WindowBase::get_keypress_utf8()
4021 return top_level->key_pressed_utf8;
4026 int BC_WindowBase::get_keypress()
4028 return top_level->key_pressed;
4031 int BC_WindowBase::get_double_click()
4033 return top_level->double_click;
4036 int BC_WindowBase::get_triple_click()
4038 return top_level->triple_click;
4041 int BC_WindowBase::get_bgcolor()
4046 int BC_WindowBase::resize_window(int w, int h)
4048 if(this->w == w && this->h == h) return 0;
4050 if(window_type == MAIN_WINDOW && !allow_resize)
4052 XSizeHints size_hints;
4053 size_hints.flags = PSize | PMinSize | PMaxSize;
4054 size_hints.width = w;
4055 size_hints.height = h;
4056 size_hints.min_width = w;
4057 size_hints.max_width = w;
4058 size_hints.min_height = h;
4059 size_hints.max_height = h;
4060 XSetNormalHints(top_level->display, win, &size_hints);
4062 XResizeWindow(top_level->display, win, w, h);
4067 pixmap = new BC_Pixmap(this, w, h);
4069 // Propagate to menubar
4070 for(int i = 0; i < subwindows->total; i++)
4072 subwindows->values[i]->dispatch_resize_event(w, h);
4075 draw_background(0, 0, w, h);
4076 if(top_level == this && get_resources()->recursive_resizing)
4077 resize_history.append(new BC_ResizeCall(w, h));
4081 // The only way for resize events to be propagated is by updating the internal w and h
4082 int BC_WindowBase::resize_event(int w, int h)
4084 if(window_type == MAIN_WINDOW)
4092 int BC_WindowBase::reposition_window(int x, int y)
4094 reposition_window(x, y, -1, -1);
4099 int BC_WindowBase::reposition_window(int x, int y, int w, int h)
4103 // Some tools set their own dimensions before calling this, causing the
4104 // resize check to skip.
4108 if(w > 0 && w != this->w)
4114 if(h > 0 && h != this->h)
4120 //printf("BC_WindowBase::reposition_window %d %d %d\n", translation_count, x_correction, y_correction);
4123 printf("BC_WindowBase::reposition_window this->w == %d\n", this->w);
4125 printf("BC_WindowBase::reposition_window this->h == %d\n", this->h);
4127 if(translation_count && window_type == MAIN_WINDOW)
4129 // KDE shifts window right and down.
4130 // FVWM leaves window alone and adds border around it.
4131 XMoveResizeWindow(top_level->display,
4133 x - BC_DisplayInfo::auto_reposition_x,
4134 y - BC_DisplayInfo::auto_reposition_y,
4140 XMoveResizeWindow(top_level->display,
4151 pixmap = new BC_Pixmap(this, this->w, this->h);
4152 clear_box(0,0, this->w, this->h);
4153 // Propagate to menubar
4154 for(int i = 0; i < subwindows->total; i++)
4156 subwindows->values[i]->dispatch_resize_event(this->w, this->h);
4159 // draw_background(0, 0, w, h);
4165 int BC_WindowBase::reposition_window_relative(int dx, int dy, int w, int h)
4167 return reposition_window(get_x()+dx, get_y()+dy, w, h);
4170 int BC_WindowBase::reposition_window_relative(int dx, int dy)
4172 return reposition_window_relative(dx, dy, -1, -1);
4175 void BC_WindowBase::set_tooltips(int v)
4177 get_resources()->tooltips_enabled = v;
4180 void BC_WindowBase::set_force_tooltip(int v)
4185 int BC_WindowBase::raise_window(int do_flush)
4187 XRaiseWindow(top_level->display, win);
4188 if(do_flush) XFlush(top_level->display);
4192 int BC_WindowBase::lower_window(int do_flush)
4194 XLowerWindow(top_level->display, win);
4195 if(do_flush) XFlush(top_level->display);
4199 void BC_WindowBase::set_background(VFrame *bitmap)
4201 if(bg_pixmap && !shared_bg_pixmap) delete bg_pixmap;
4203 bg_pixmap = new BC_Pixmap(this, bitmap, PIXMAP_OPAQUE);
4204 shared_bg_pixmap = 0;
4205 draw_background(0, 0, w, h);
4208 void BC_WindowBase::put_title(const char *text)
4210 char *cp = this->title, *ep = cp+sizeof(this->title)-1;
4211 for( const unsigned char *bp = (const unsigned char *)text; *bp && cp<ep; ++bp )
4212 *cp++ = *bp >= ' ' ? *bp : ' ';
4216 void BC_WindowBase::set_title(const char *text, int utf8)
4218 // utf8>0: wm + net_wm, utf8=0: wm only, utf<0: net_wm only
4220 const unsigned char *wm_title = (const unsigned char *)title;
4221 int title_len = strlen((const char *)title);
4223 Atom xa_wm_name = XA_WM_NAME;
4224 Atom xa_icon_name = XA_WM_ICON_NAME;
4225 Atom xa_string = XA_STRING;
4226 XChangeProperty(display, win, xa_wm_name, xa_string, 8,
4227 PropModeReplace, wm_title, title_len);
4228 XChangeProperty(display, win, xa_icon_name, xa_string, 8,
4229 PropModeReplace, wm_title, title_len);
4232 Atom xa_net_wm_name = XInternAtom(display, "_NET_WM_NAME", True);
4233 Atom xa_net_icon_name = XInternAtom(display, "_NET_WM_ICON_NAME", True);
4234 Atom xa_utf8_string = XInternAtom(display, "UTF8_STRING", True);
4235 XChangeProperty(display, win, xa_net_wm_name, xa_utf8_string, 8,
4236 PropModeReplace, wm_title, title_len);
4237 XChangeProperty(display, win, xa_net_icon_name, xa_utf8_string, 8,
4238 PropModeReplace, wm_title, title_len);
4243 const char *BC_WindowBase::get_title()
4248 int BC_WindowBase::get_toggle_value()
4250 return toggle_value;
4253 int BC_WindowBase::get_toggle_drag()
4258 int BC_WindowBase::set_icon(VFrame *data)
4260 if(icon_pixmap) delete icon_pixmap;
4261 icon_pixmap = new BC_Pixmap(top_level, data, PIXMAP_ALPHA, 1);
4263 if(icon_window) delete icon_window;
4264 icon_window = new BC_Popup(this,
4267 icon_pixmap->get_w(),
4268 icon_pixmap->get_h(),
4270 1, // All windows are hidden initially
4274 wm_hints.flags = WindowGroupHint | IconPixmapHint | IconMaskHint | IconWindowHint;
4275 wm_hints.icon_pixmap = icon_pixmap->get_pixmap();
4276 wm_hints.icon_mask = icon_pixmap->get_alpha();
4277 wm_hints.icon_window = icon_window->win;
4278 wm_hints.window_group = XGroupLeader;
4280 // for(int i = 0; i < 1000; i++)
4281 // printf("02x ", icon_pixmap->get_alpha()->get_row_pointers()[0][i]);
4284 XSetWMHints(top_level->display, top_level->win, &wm_hints);
4285 XSync(top_level->display, 0);
4289 int BC_WindowBase::set_w(int w)
4295 int BC_WindowBase::set_h(int h)
4301 int BC_WindowBase::load_defaults(BC_Hash *defaults)
4303 BC_Resources *resources = get_resources();
4304 char string[BCTEXTLEN];
4305 int newest_id = - 1;
4306 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
4308 sprintf(string, "FILEBOX_HISTORY_PATH%d", i);
4309 resources->filebox_history[i].path[0] = 0;
4310 defaults->get(string, resources->filebox_history[i].path);
4311 sprintf(string, "FILEBOX_HISTORY_ID%d", i);
4312 resources->filebox_history[i].id = defaults->get(string, resources->get_id());
4313 if(resources->filebox_history[i].id > newest_id)
4314 newest_id = resources->filebox_history[i].id;
4317 resources->filebox_id = newest_id + 1;
4318 resources->filebox_mode = defaults->get("FILEBOX_MODE", get_resources()->filebox_mode);
4319 resources->filebox_w = defaults->get("FILEBOX_W", get_resources()->filebox_w);
4320 resources->filebox_h = defaults->get("FILEBOX_H", get_resources()->filebox_h);
4321 resources->filebox_columntype[0] = defaults->get("FILEBOX_TYPE0", resources->filebox_columntype[0]);
4322 resources->filebox_columntype[1] = defaults->get("FILEBOX_TYPE1", resources->filebox_columntype[1]);
4323 resources->filebox_columntype[2] = defaults->get("FILEBOX_TYPE2", resources->filebox_columntype[2]);
4324 resources->filebox_columntype[3] = defaults->get("FILEBOX_TYPE3", resources->filebox_columntype[3]);
4325 resources->filebox_columnwidth[0] = defaults->get("FILEBOX_WIDTH0", resources->filebox_columnwidth[0]);
4326 resources->filebox_columnwidth[1] = defaults->get("FILEBOX_WIDTH1", resources->filebox_columnwidth[1]);
4327 resources->filebox_columnwidth[2] = defaults->get("FILEBOX_WIDTH2", resources->filebox_columnwidth[2]);
4328 resources->filebox_columnwidth[3] = defaults->get("FILEBOX_WIDTH3", resources->filebox_columnwidth[3]);
4329 resources->filebox_size_format = defaults->get("FILEBOX_SIZE_FORMAT", get_resources()->filebox_size_format);
4330 defaults->get("FILEBOX_FILTER", resources->filebox_filter);
4334 int BC_WindowBase::save_defaults(BC_Hash *defaults)
4336 BC_Resources *resources = get_resources();
4337 char string[BCTEXTLEN];
4338 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
4340 sprintf(string, "FILEBOX_HISTORY_PATH%d", i);
4341 defaults->update(string, resources->filebox_history[i].path);
4342 sprintf(string, "FILEBOX_HISTORY_ID%d", i);
4343 defaults->update(string, resources->filebox_history[i].id);
4345 defaults->update("FILEBOX_MODE", resources->filebox_mode);
4346 defaults->update("FILEBOX_W", resources->filebox_w);
4347 defaults->update("FILEBOX_H", resources->filebox_h);
4348 defaults->update("FILEBOX_TYPE0", resources->filebox_columntype[0]);
4349 defaults->update("FILEBOX_TYPE1", resources->filebox_columntype[1]);
4350 defaults->update("FILEBOX_TYPE2", resources->filebox_columntype[2]);
4351 defaults->update("FILEBOX_TYPE3", resources->filebox_columntype[3]);
4352 defaults->update("FILEBOX_WIDTH0", resources->filebox_columnwidth[0]);
4353 defaults->update("FILEBOX_WIDTH1", resources->filebox_columnwidth[1]);
4354 defaults->update("FILEBOX_WIDTH2", resources->filebox_columnwidth[2]);
4355 defaults->update("FILEBOX_WIDTH3", resources->filebox_columnwidth[3]);
4356 defaults->update("FILEBOX_FILTER", resources->filebox_filter);
4357 defaults->update("FILEBOX_SIZE_FORMAT", get_resources()->filebox_size_format);
4363 // For some reason XTranslateCoordinates can take a long time to return.
4364 // We work around this by only calling it when the event windows are different.
4365 void BC_WindowBase::translate_coordinates(Window src_w,
4377 *dest_x_return = src_x;
4378 *dest_y_return = src_y;
4382 XTranslateCoordinates(top_level->display,
4390 //printf("BC_WindowBase::translate_coordinates 1 %lld\n", timer.get_difference());
4394 void BC_WindowBase::get_root_coordinates(int x, int y, int *abs_x, int *abs_y)
4396 translate_coordinates(win, top_level->rootwin, x, y, abs_x, abs_y);
4399 void BC_WindowBase::get_win_coordinates(int abs_x, int abs_y, int *x, int *y)
4401 translate_coordinates(top_level->rootwin, win, abs_x, abs_y, x, y);
4409 #ifdef HAVE_LIBXXF86VM
4410 void BC_WindowBase::closest_vm(int *vm, int *width, int *height)
4414 if(XF86VidModeQueryExtension(top_level->display,&foo,&bar)) {
4416 XF86VidModeModeInfo **vm_modelines;
4417 XF86VidModeGetAllModeLines(top_level->display,XDefaultScreen(top_level->display),&vm_count,&vm_modelines);
4418 for (i = 0; i < vm_count; i++) {
4419 if (vm_modelines[i]->hdisplay < vm_modelines[*vm]->hdisplay && vm_modelines[i]->hdisplay >= *width)
4422 display = top_level->display;
4423 if (vm_modelines[*vm]->hdisplay == *width)
4427 *width = vm_modelines[*vm]->hdisplay;
4428 *height = vm_modelines[*vm]->vdisplay;
4433 void BC_WindowBase::scale_vm(int vm)
4435 int foo,bar,dotclock;
4436 if(XF86VidModeQueryExtension(top_level->display,&foo,&bar))
4439 XF86VidModeModeInfo **vm_modelines;
4440 XF86VidModeModeLine vml;
4441 XF86VidModeGetAllModeLines(top_level->display,XDefaultScreen(top_level->display),&vm_count,&vm_modelines);
4442 XF86VidModeGetModeLine(top_level->display,XDefaultScreen(top_level->display),&dotclock,&vml);
4443 orig_modeline.dotclock = dotclock;
4444 orig_modeline.hdisplay = vml.hdisplay;
4445 orig_modeline.hsyncstart = vml.hsyncstart;
4446 orig_modeline.hsyncend = vml.hsyncend;
4447 orig_modeline.htotal = vml.htotal;
4448 orig_modeline.vdisplay = vml.vdisplay;
4449 orig_modeline.vsyncstart = vml.vsyncstart;
4450 orig_modeline.vsyncend = vml.vsyncend;
4451 orig_modeline.vtotal = vml.vtotal;
4452 orig_modeline.flags = vml.flags;
4453 orig_modeline.privsize = vml.privsize;
4454 // orig_modeline.private = vml.private;
4455 XF86VidModeSwitchToMode(top_level->display,XDefaultScreen(top_level->display),vm_modelines[vm]);
4456 XF86VidModeSetViewPort(top_level->display,XDefaultScreen(top_level->display),0,0);
4457 XFlush(top_level->display);
4461 void BC_WindowBase::restore_vm()
4463 XF86VidModeSwitchToMode(top_level->display,XDefaultScreen(top_level->display),&orig_modeline);
4464 XFlush(top_level->display);
4487 #ifndef SINGLE_THREAD
4488 int BC_WindowBase::get_event_count()
4490 event_lock->lock("BC_WindowBase::get_event_count");
4491 int result = common_events.total;
4492 event_lock->unlock();
4496 XEvent* BC_WindowBase::get_event()
4499 while(!done && !result)
4501 event_condition->lock("BC_WindowBase::get_event");
4502 event_lock->lock("BC_WindowBase::get_event");
4504 if(common_events.total && !done)
4506 result = common_events.values[0];
4507 common_events.remove_number(0);
4510 event_lock->unlock();
4515 void BC_WindowBase::put_event(XEvent *event)
4517 event_lock->lock("BC_WindowBase::put_event");
4518 common_events.append(event);
4519 event_lock->unlock();
4520 event_condition->unlock();
4523 void BC_WindowBase::dequeue_events(Window win)
4525 event_lock->lock("BC_WindowBase::dequeue_events");
4527 int out = 0, total = common_events.size();
4528 for( int in=0; in<total; ++in ) {
4529 if( common_events[in]->xany.window == win ) continue;
4530 common_events[out++] = common_events[in];
4532 common_events.total = out;
4534 event_lock->unlock();
4537 int BC_WindowBase::resend_event(BC_WindowBase *window)
4539 if( resend_event_window ) return 1;
4540 resend_event_window = window;
4546 int BC_WindowBase::resend_event(BC_WindowBase *window)
4551 #endif // SINGLE_THREAD
4553 int BC_WindowBase::get_id()
4559 BC_Pixmap *BC_WindowBase::create_pixmap(VFrame *vframe)
4561 int w = vframe->get_w(), h = vframe->get_h();
4562 BC_Pixmap *icon = new BC_Pixmap(this, w, h);
4563 icon->draw_vframe(vframe, 0,0, w,h, 0,0);
4568 void BC_WindowBase::flicker(int n, int ms)
4570 int color = get_bg_color();
4571 for( int i=2*n; --i>=0; ) {
4572 set_inverse(); set_bg_color(WHITE);
4573 clear_box(0,0, w,h); flash(1);
4574 sync_display(); Timer::delay(ms);
4576 set_bg_color(color);
4580 void BC_WindowBase::focus()
4582 XWindowAttributes xwa;
4583 XGetWindowAttributes(top_level->display, top_level->win, &xwa);
4584 if( xwa.map_state == IsViewable )
4585 XSetInputFocus(top_level->display, top_level->win, RevertToParent, CurrentTime);