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"
58 #include <X11/extensions/Xinerama.h>
59 #include <X11/extensions/Xvlib.h>
60 #include <X11/extensions/shape.h>
61 #include <X11/XF86keysym.h>
62 #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(int opts)
91 //printf("BC_WindowBase::BC_WindowBase 1\n");
92 BC_WindowBase::initialize();
95 BC_WindowBase::~BC_WindowBase()
98 BC_Display::lock_display("BC_WindowBase::~BC_WindowBase");
100 if(window_type == MAIN_WINDOW)
101 lock_window("BC_WindowBase::~BC_WindowBase");
104 #ifdef HAVE_LIBXXF86VM
105 if(window_type == VIDMODE_SCALED_WINDOW && vm_switched)
112 if(window_type != MAIN_WINDOW)
114 if(top_level->active_menubar == this) top_level->active_menubar = 0;
115 if(top_level->active_popup_menu == this) top_level->active_popup_menu = 0;
116 if(top_level->active_subwindow == this) top_level->active_subwindow = 0;
117 // Remove pointer from parent window to this
118 parent_window->subwindows->remove(this);
121 if(icon_window) delete icon_window;
122 if(window_type == POPUP_WINDOW) parent_window->remove_popup(this);
124 // Delete the subwindows
128 while(subwindows->total)
130 // Subwindow removes its own pointer
131 delete subwindows->values[0];
139 if( get_resources()->get_synchronous() && top_level->options & GLX_WINDOW ) {
141 // NVIDIA library threading problem, XCloseDisplay SEGVs without this
142 sync_lock("BC_WindowBase::~BC_WindowBase:XDestroyWindow");
143 glXMakeContextCurrent(top_level->display, 0, 0, 0);
144 XDestroyWindow(top_level->display, win);
148 get_resources()->get_synchronous()->delete_window(this);
152 XDestroyWindow(top_level->display, win);
154 if(bg_pixmap && !shared_bg_pixmap) delete bg_pixmap;
155 if(icon_pixmap) delete icon_pixmap;
156 if(temp_bitmap) delete temp_bitmap;
157 top_level->active_bitmaps.remove_buffers(this);
158 if(_7segment_pixmaps)
160 for(int i = 0; i < TOTAL_7SEGMENT; i++)
161 delete _7segment_pixmaps[i];
163 delete [] _7segment_pixmaps;
168 if(window_type == MAIN_WINDOW)
170 XFreeGC(display, gc);
171 XFreeFont(display, smallfont);
172 XFreeFont(display, mediumfont);
173 XFreeFont(display, largefont);
174 XFreeFont(display, bigfont);
176 // bug in X causes XRenderExtensionInfo to be damaged if this is done here
177 // left to be done in XCloseDisplay by Xlib.
178 #if defined(HAVE_XFT) && 0
180 XftFontClose (display, (XftFont*)bigfont_xft);
182 XftFontClose (display, (XftFont*)largefont_xft);
184 XftFontClose (display, (XftFont*)mediumfont_xft);
186 XftFontClose (display, (XftFont*)smallfont_xft);
194 XFree(xinerama_info);
195 xinerama_screens = 0;
199 // Can't close display if another thread is waiting for events.
200 // Synchronous thread must delete display it owns a GLX_WINDOW
201 // Must be last reference to display.
202 #ifndef SINGLE_THREAD
204 if( (options & GLX_DISPLAY) != 0 && get_resources()->get_synchronous() ) {
205 printf(_("BC_WindowBase::~BC_WindowBase window deleted but opengl deletion is not\n"
206 "implemented for BC_Pixmap.\n"));
207 get_resources()->get_synchronous()->delete_display(this);
211 XCloseDisplay(display);
212 // clipboard uses a different display connection
213 clipboard->stop_clipboard();
215 #endif // SINGLE_THREAD
218 resize_history.remove_all_objects();
220 #ifndef SINGLE_THREAD
221 common_events.remove_all_objects();
223 delete event_condition;
226 top_level->window_lock = 0;
227 BC_Display::unlock_display();
232 if( glx_fbcfgs_window ) XFree(glx_fbcfgs_window);
233 if( glx_fbcfgs_pbuffer) XFree(glx_fbcfgs_pbuffer);
234 if( glx_fbcfgs_pixmap ) XFree(glx_fbcfgs_pixmap);
237 UNSET_ALL_LOCKS(this)
240 int BC_WindowBase::initialize()
260 xinerama_screens = 0;
265 translation_events = 0;
266 ctrl_mask = shift_mask = alt_mask = 0;
267 cursor_x = cursor_y = button_number = 0;
279 active_popup_menu = 0;
280 active_subwindow = 0;
283 _7segment_pixmaps = 0;
286 // next_repeat_id = 0;
289 current_font = MEDIUMFONT;
290 current_color = BLACK;
291 current_cursor = ARROW_CURSOR;
294 shared_bg_pixmap = 0;
297 window_type = MAIN_WINDOW;
298 translation_count = 0;
299 x_correction = y_correction = 0;
308 #ifdef HAVE_LIBXXF86VM
312 bold_largefont_xft = 0;
313 bold_mediumfont_xft = 0;
314 bold_smallfont_xft = 0;
322 completion_lock = new Condition(0, "BC_WindowBase::completion_lock");
324 // Need these right away since put_event is called before run_window sometimes.
325 event_lock = new Mutex("BC_WindowBase::event_lock");
326 event_condition = new Condition(0, "BC_WindowBase::event_condition");
327 init_lock = new Condition(0, "BC_WindowBase::init_lock");
330 cursor_timer = new Timer;
333 glx_fbcfgs_window = 0; n_fbcfgs_window = 0;
334 glx_fbcfgs_pbuffer = 0; n_fbcfgs_pbuffer = 0;
335 glx_fbcfgs_pixmap = 0; n_fbcfgs_pixmap = 0;
347 #define DEFAULT_EVENT_MASKS EnterWindowMask | \
350 ButtonReleaseMask | \
351 PointerMotionMask | \
355 int BC_WindowBase::create_window(BC_WindowBase *parent_window,
367 const char *display_name,
369 BC_Pixmap *bg_pixmap,
372 XSetWindowAttributes attr;
374 XSizeHints size_hints;
377 #ifdef HAVE_LIBXXF86VM
381 id = get_resources()->get_id();
383 if(parent_window) top_level = parent_window->top_level;
384 if( top_level ) { // need this to avoid deadlock with Xlib's locks
386 lock_window("BC_WindowBase::create_window");
388 get_resources()->create_window_lock->lock("BC_WindowBase::create_window");
390 #ifdef HAVE_LIBXXF86VM
391 if(window_type == VIDMODE_SCALED_WINDOW)
392 closest_vm(&vm,&w,&h);
399 this->bg_color = bg_color;
400 this->window_type = window_type;
402 this->private_color = private_color;
403 this->parent_window = parent_window;
404 this->bg_pixmap = bg_pixmap;
405 this->allow_resize = allow_resize;
407 strcpy(this->display_name, display_name);
409 this->display_name[0] = 0;
411 strcpy(this->title, _(title));
412 if(bg_pixmap) shared_bg_pixmap = 1;
414 subwindows = new BC_SubWindowList;
416 if(window_type == MAIN_WINDOW)
419 parent_window = this;
423 display = BC_Display::get_display(display_name);
424 BC_Display::lock_display("BC_WindowBase::create_window");
425 // BC_Display::display_global->new_window(this);
428 // get the display connection
430 // This function must be the first Xlib
431 // function a multi-threaded program calls
433 display = init_display(display_name);
434 if( shm_completion_event < 0 ) shm_completion_event =
435 ShmCompletion + XShmGetEventBase(display);
438 screen = DefaultScreen(display);
439 rootwin = RootWindow(display, screen);
440 // window placement boundaries
441 if( !xinerama_screens && XineramaIsActive(display) )
442 xinerama_info = XineramaQueryScreens(display, &xinerama_screens);
443 root_w = get_root_w(0);
444 root_h = get_root_h(0);
447 vis = get_glx_visual(display);
450 vis = DefaultVisual(display, screen);
452 default_depth = DefaultDepth(display, screen);
454 client_byte_order = (*(const u_int32_t*)"a ") & 0x00000001;
455 server_byte_order = (XImageByteOrder(display) == MSBFirst) ? 0 : 1;
458 // This must be done before fonts to know if antialiasing is available.
461 if(resources.use_shm < 0) resources.initialize_display(this);
462 x_correction = get_resources()->get_left_border();
463 y_correction = get_resources()->get_top_border();
465 // clamp window placement
466 if(this->x + this->w + x_correction > root_w)
467 this->x = root_w - this->w - x_correction;
468 if(this->y + this->h + y_correction > root_h)
469 this->y = root_h - this->h - y_correction;
470 if(this->x < 0) this->x = 0;
471 if(this->y < 0) this->y = 0;
473 if(this->bg_color == -1)
474 this->bg_color = resources.get_bg_color();
476 // printf("bcwindowbase 1 %s\n", title);
477 // if(window_type == MAIN_WINDOW) sleep(1);
478 // printf("bcwindowbase 10\n");
484 mask = CWEventMask | CWBackPixel | CWColormap | CWCursor;
486 attr.event_mask = DEFAULT_EVENT_MASKS |
487 StructureNotifyMask |
491 attr.background_pixel = get_color(this->bg_color);
492 attr.colormap = cmap;
493 attr.cursor = get_cursor_struct(ARROW_CURSOR);
495 win = XCreateWindow(display, rootwin,
496 this->x, this->y, this->w, this->h, 0,
497 top_level->default_depth, InputOutput,
499 XGetNormalHints(display, win, &size_hints);
501 size_hints.flags = PSize | PMinSize | PMaxSize;
502 size_hints.width = this->w;
503 size_hints.height = this->h;
504 size_hints.min_width = allow_resize ? minw : this->w;
505 size_hints.max_width = allow_resize ? 32767 : this->w;
506 size_hints.min_height = allow_resize ? minh : this->h;
507 size_hints.max_height = allow_resize ? 32767 : this->h;
508 if(x > -BC_INFINITY && x < BC_INFINITY)
510 size_hints.flags |= PPosition;
511 size_hints.x = this->x;
512 size_hints.y = this->y;
516 txlist[0] = this->title;
518 XTextProperty titleprop;
519 if(options & WINDOW_UTF8)
520 Xutf8TextListToTextProperty(display, txlist, 1,
521 XUTF8StringStyle, &titleprop);
523 XmbTextListToTextProperty(display, txlist, 1,
524 XStdICCTextStyle, &titleprop);
525 XSetWMProperties(display, win, &titleprop, &titleprop,
526 0, 0, &size_hints, 0, 0);
527 XFree(titleprop.value);
530 #ifndef SINGLE_THREAD
531 clipboard = new BC_Clipboard(display_name);
532 clipboard->start_clipboard();
538 Atom ClientLeaderXAtom;
539 if (XGroupLeader == 0)
541 const char *instance_name = "cinelerra";
542 const char *class_name = "Cinelerra";
543 XClassHint *class_hints = XAllocClassHint();
544 class_hints->res_name = (char*)instance_name;
545 class_hints->res_class = (char*)class_name;
546 XSetClassHint(top_level->display, win, class_hints);
548 ClientLeaderXAtom = XInternAtom(display, "WM_CLIENT_LEADER", True);
549 XChangeProperty(display, win, ClientLeaderXAtom, XA_WINDOW, 32,
550 PropModeReplace, (unsigned char *)&XGroupLeader, true);
555 #ifdef HAVE_LIBXXF86VM
556 if(window_type == VIDMODE_SCALED_WINDOW && vm != -1)
563 #ifdef HAVE_LIBXXF86VM
564 if(window_type == POPUP_WINDOW || window_type == VIDMODE_SCALED_WINDOW)
566 if(window_type == POPUP_WINDOW)
569 mask = CWEventMask | CWBackPixel | CWColormap |
570 CWOverrideRedirect | CWSaveUnder | CWCursor;
572 attr.event_mask = DEFAULT_EVENT_MASKS |
576 if(this->bg_color == -1)
577 this->bg_color = resources.get_bg_color();
578 attr.background_pixel = top_level->get_color(bg_color);
579 attr.colormap = top_level->cmap;
580 if(top_level->is_hourglass)
581 attr.cursor = top_level->get_cursor_struct(HOURGLASS_CURSOR);
583 attr.cursor = top_level->get_cursor_struct(ARROW_CURSOR);
584 attr.override_redirect = True;
585 attr.save_under = True;
587 win = XCreateWindow(top_level->display,
588 top_level->rootwin, this->x, this->y, this->w, this->h, 0,
589 top_level->default_depth, InputOutput, top_level->vis, mask,
591 top_level->add_popup(this);
594 if(window_type == SUB_WINDOW)
596 mask = CWEventMask | CWBackPixel | CWCursor;
597 attr.event_mask = DEFAULT_EVENT_MASKS;
598 attr.background_pixel = top_level->get_color(this->bg_color);
599 if(top_level->is_hourglass)
600 attr.cursor = top_level->get_cursor_struct(HOURGLASS_CURSOR);
602 attr.cursor = top_level->get_cursor_struct(ARROW_CURSOR);
603 win = XCreateWindow(top_level->display,
604 parent_window->win, this->x, this->y, this->w, this->h, 0,
605 top_level->default_depth, InputOutput, top_level->vis, mask,
608 if(!hidden) XMapWindow(top_level->display, win);
611 // Create pixmap for all windows
612 pixmap = new BC_Pixmap(this, this->w, this->h);
614 // Set up options for main window
615 if(window_type == MAIN_WINDOW)
617 if(get_resources()->bg_image && !bg_pixmap && bg_color < 0)
619 this->bg_pixmap = new BC_Pixmap(this,
620 get_resources()->bg_image,
624 if(!hidden) show_window();
631 draw_background(0, 0, this->w, this->h);
633 flash(-1, -1, -1, -1, 0);
635 // Set up options for popup window
636 #ifdef HAVE_LIBXXF86VM
637 if(window_type == POPUP_WINDOW || window_type == VIDMODE_SCALED_WINDOW)
639 if(window_type == POPUP_WINDOW)
643 if(!hidden) show_window();
645 get_resources()->create_window_lock->unlock();
646 if(need_lock) unlock_window();
651 Display* BC_WindowBase::init_display(const char *display_name)
655 if(display_name && display_name[0] == 0) display_name = NULL;
656 if((display = XOpenDisplay(display_name)) == NULL) {
657 printf("BC_WindowBase::init_display: cannot connect to X server %s\n",
659 if(getenv("DISPLAY") == NULL) {
660 printf(_("'DISPLAY' environment variable not set.\n"));
664 // Try again with default display.
665 if((display = XOpenDisplay(0)) == NULL) {
666 printf("BC_WindowBase::init_display: cannot connect to default X server.\n");
674 Display* BC_WindowBase::get_display()
676 return top_level->display;
679 int BC_WindowBase::get_screen()
681 return top_level->screen;
684 int BC_WindowBase::run_window()
690 // Events may have been sent before run_window so can't initialize them here.
693 set_repeat(get_resources()->tooltip_delay);
694 BC_Display::display_global->new_window(this);
696 // If the first window created, run the display loop in this thread.
697 if(BC_Display::display_global->is_first(this))
699 BC_Display::unlock_display();
700 BC_Display::display_global->loop();
704 BC_Display::unlock_display();
705 completion_lock->lock("BC_WindowBase::run_window");
708 BC_Display::lock_display("BC_WindowBase::run_window");
709 BC_Display::display_global->delete_window(this);
711 unset_all_repeaters();
713 BC_Display::unlock_display();
715 #else // SINGLE_THREAD
720 set_repeat(get_resources()->tooltip_delay);
722 // Start X server events
723 event_thread = new BC_WindowEvents(this);
724 event_thread->start();
730 // Handle common events
736 unset_all_repeaters();
740 event_condition->reset();
741 common_events.remove_all_objects();
745 #endif // SINGLE_THREAD
750 int BC_WindowBase::get_key_masks(unsigned int key_state)
752 // printf("BC_WindowBase::get_key_masks %llx\n",
753 // event->xkey.state);
754 ctrl_mask = (key_state & ControlMask) ? 1 : 0; // ctrl key down
755 shift_mask = (key_state & ShiftMask) ? 1 : 0; // shift key down
756 alt_mask = (key_state & Mod1Mask) ? 1 : 0; // alt key down
761 void BC_WindowBase::add_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *))
763 BC_KeyboardHandlerLock set;
764 BC_KeyboardHandler::listeners.append(new BC_KeyboardHandler(handler, this));
767 void BC_WindowBase::del_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *))
769 BC_KeyboardHandlerLock set;
770 int i = BC_KeyboardHandler::listeners.size();
771 while( --i >= 0 && BC_KeyboardHandler::listeners[i]->handler!=handler );
772 if( i >= 0 ) BC_KeyboardHandler::listeners.remove_object_number(i);
775 int BC_KeyboardHandler::run_event(BC_WindowBase *wp)
777 int result = (win->*handler)(wp);
781 int BC_KeyboardHandler::run_listeners(BC_WindowBase *wp)
784 BC_KeyboardHandlerLock set;
785 for( int i=0; !result && i<listeners.size(); ++i ) {
786 BC_KeyboardHandler *listener = listeners[i];
787 result = listener->run_event(wp);
792 void BC_KeyboardHandler::kill_grabs()
794 BC_KeyboardHandlerLock set;
795 for( int i=0; i<listeners.size(); ++i ) {
796 BC_WindowBase *win = listeners[i]->win;
797 if( win->get_window_type() != POPUP_WINDOW ) continue;
798 ((BC_Popup *)win)->ungrab_keyboard();
802 void BC_ActiveBitmaps::reque(XEvent *event)
804 XShmCompletionEvent *shm_ev = (XShmCompletionEvent *)event;
805 ShmSeg shmseg = shm_ev->shmseg;
806 Drawable drawable = shm_ev->drawable;
807 //printf("BC_BitmapImage::reque %08lx\n",shmseg);
808 active_lock.lock("BC_BitmapImage::reque");
809 BC_BitmapImage *bfr = first;
810 while( bfr && bfr->get_shmseg() != shmseg ) bfr = bfr->next;
811 if( bfr && bfr->drawable == drawable )
813 active_lock.unlock();
815 // sadly, X reports two drawable completions and creates false reporting, so no boobytrap
816 // printf("BC_BitmapImage::reque missed shmseg %08x, drawable %08x\n",
817 // (int)shmseg, (int)drawable);
820 if( bfr->drawable != drawable ) return;
821 if( bfr->is_zombie() ) { --BC_Bitmap::zombies; delete bfr; return; }
822 bfr->bitmap->reque(bfr);
825 void BC_ActiveBitmaps::insert(BC_BitmapImage *bfr, Drawable pixmap)
827 active_lock.lock("BC_BitmapImage::insert");
828 bfr->drawable = pixmap;
830 active_lock.unlock();
833 void BC_ActiveBitmaps::remove_buffers(BC_WindowBase *wdw)
835 active_lock.lock("BC_ActiveBitmaps::remove");
836 for( BC_BitmapImage *nxt=0, *bfr=first; bfr; bfr=nxt ) {
838 if( bfr->is_zombie() ) { --BC_Bitmap::zombies; delete bfr; continue; }
839 if( bfr->bitmap->parent_window == wdw ) remove_pointer(bfr);
841 active_lock.unlock();
844 BC_ActiveBitmaps::BC_ActiveBitmaps()
848 BC_ActiveBitmaps::~BC_ActiveBitmaps()
854 int BC_WindowBase::keysym_lookup(XEvent *event)
856 for( int i = 0; i < KEYPRESSLEN; ++i ) keys_return[i] = 0;
857 for( int i = 0; i < 4; ++i ) wkey_string[i] = 0;
859 if( event->xany.send_event && !event->xany.serial ) {
860 keysym = (KeySym) event->xkey.keycode;
861 keys_return[0] = keysym;
865 wkey_string_length = XwcLookupString(input_context,
866 (XKeyEvent*)event, wkey_string, 4, &keysym, 0);
867 //printf("keysym_lookup 1 %d %d %lx %x %x %x %x\n", wkey_string_length, keysym,
868 // wkey_string[0], wkey_string[1], wkey_string[2], wkey_string[3]);
871 int ret = Xutf8LookupString(input_context, (XKeyEvent*)event,
872 keys_return, KEYPRESSLEN, &keysym, &stat);
873 //printf("keysym_lookup 2 %d %d %lx %x %x\n", ret, stat, keysym, keys_return[0], keys_return[1]);
874 if( stat == XLookupBoth ) return ret;
875 if( stat == XLookupKeySym ) return 0;
877 return XLookupString((XKeyEvent*)event, keys_return, KEYPRESSLEN, &keysym, 0);
880 pthread_t locking_task = -1;
881 int locking_event = -1;
882 int locking_message = -1;
884 int BC_WindowBase::dispatch_event(XEvent *event)
888 XClientMessageEvent *ptr;
889 int cancel_resize, cancel_translation;
894 #ifndef SINGLE_THREAD
895 // If an event is waiting get it, otherwise
896 // wait for next event only if there are no compressed events.
897 if(get_event_count() ||
898 (!motion_events && !resize_events && !translation_events))
901 // Lock out window deletions
902 lock_window("BC_WindowBase::dispatch_event 1");
903 locking_event = event->type;
904 locking_task = pthread_self();
905 locking_message = event->xclient.message_type;
908 // Handle compressed events
910 lock_window("BC_WindowBase::dispatch_event 2");
912 dispatch_resize_event(last_resize_w, last_resize_h);
914 dispatch_motion_event();
915 if(translation_events)
916 dispatch_translation_event();
927 //static const char *event_names[] = {
928 // "Reply", "Error", "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", "MotionNotify",
929 // "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose",
930 // "NoExpose", "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify",
931 // "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify",
932 // "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear",
933 // "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify",
934 // "GenericEvent", "LASTEvent",
938 //if(event->type != ClientMessage) {
939 // printf("BC_WindowBase::dispatch_event %d %s %p %d (%s)\n",
940 //__LINE__, title, event, event->type,
941 // event->type>=0 && event->type<sizeof(event_names)/sizeof(event_names[0]) ?
942 // event_names[event->type] : "Unknown");
948 switch(event->type) {
950 // Clear the resize buffer
951 if(resize_events) dispatch_resize_event(last_resize_w, last_resize_h);
952 // Clear the motion buffer since this can clear the window
955 dispatch_motion_event();
958 ptr = (XClientMessageEvent*)event;
961 if(ptr->message_type == ProtoXAtom &&
962 (Atom)ptr->data.l[0] == DelWinXAtom)
967 if(ptr->message_type == RepeaterXAtom)
969 dispatch_repeat_event(ptr->data.l[0]);
970 // Make sure the repeater still exists.
971 // for(int i = 0; i < repeaters.total; i++)
973 // if(repeaters.values[i]->repeat_id == ptr->data.l[0])
975 // dispatch_repeat_event_master(ptr->data.l[0]);
981 if(ptr->message_type == SetDoneXAtom)
985 { // We currently use X marshalling for xatom events, we can switch to something else later
986 recieve_custom_xatoms((xatom_event *)ptr);
997 dispatch_focus_out();
1009 get_key_masks(event->xbutton.state);
1010 cursor_x = event->xbutton.x;
1011 cursor_y = event->xbutton.y;
1012 button_number = event->xbutton.button;
1014 //printf("BC_WindowBase::dispatch_event %d %d\n", __LINE__, button_number);
1015 event_win = event->xany.window;
1016 if (button_number < 6)
1018 if(button_number < 4)
1020 button_pressed = event->xbutton.button;
1021 button_time1 = button_time2;
1022 button_time2 = button_time3;
1023 button_time3 = event->xbutton.time;
1026 drag_win = event_win;
1027 drag_x1 = cursor_x - get_resources()->drag_radius;
1028 drag_x2 = cursor_x + get_resources()->drag_radius;
1029 drag_y1 = cursor_y - get_resources()->drag_radius;
1030 drag_y2 = cursor_y + get_resources()->drag_radius;
1032 if((long)(button_time3 - button_time1) < resources.double_click * 2)
1035 button_time3 = button_time2 = button_time1 = 0;
1037 if((long)(button_time3 - button_time2) < resources.double_click)
1040 // button_time3 = button_time2 = button_time1 = 0;
1048 dispatch_button_press();
1053 get_key_masks(event->xbutton.state);
1054 button_number = event->xbutton.button;
1055 event_win = event->xany.window;
1056 if (button_number < 6)
1058 if(button_number < 4)
1060 //printf("BC_WindowBase::dispatch_event %d %d\n", __LINE__, button_number);
1062 dispatch_button_release();
1067 event_win = event->xany.window;
1068 dispatch_expose_event();
1072 get_key_masks(event->xmotion.state);
1073 // Dispatch previous motion event if this is a subsequent motion from a different window
1074 if(motion_events && last_motion_win != event->xany.window)
1076 dispatch_motion_event();
1079 // Buffer the current motion
1081 last_motion_state = event->xmotion.state;
1082 last_motion_x = event->xmotion.x;
1083 last_motion_y = event->xmotion.y;
1084 last_motion_win = event->xany.window;
1087 case ConfigureNotify:
1088 // printf("BC_WindowBase::dispatch_event %d win=%p this->win=%p\n",
1090 // event->xany.window,
1093 XTranslateCoordinates(top_level->display,
1101 last_resize_w = event->xconfigure.width;
1102 last_resize_h = event->xconfigure.height;
1105 cancel_translation = 0;
1107 // Resize history prevents responses to recursive resize requests
1108 for(int i = 0; i < resize_history.total && !cancel_resize; i++)
1110 if(resize_history.values[i]->w == last_resize_w &&
1111 resize_history.values[i]->h == last_resize_h)
1113 delete resize_history.values[i];
1114 resize_history.remove_number(i);
1119 if(last_resize_w == w && last_resize_h == h)
1127 if((last_translate_x == x && last_translate_y == y))
1128 cancel_translation = 1;
1130 if(!cancel_translation)
1132 translation_events = 1;
1135 translation_count++;
1139 get_key_masks(event->xkey.state);
1140 keys_return[0] = 0; keysym = -1;
1141 if(XFilterEvent(event, win)) {
1144 if( keysym_lookup(event) < 0 ) {
1145 printf("keysym %x\n", (uint32_t)keysym);
1149 //printf("BC_WindowBase::dispatch_event %d keysym=0x%x\n",
1153 // block out control keys
1154 if(keysym > 0xffe0 && keysym < 0xffff) break;
1155 // block out Alt_GR key
1156 if(keysym == 0xfe03) break;
1159 printf("BC_WindowBase::dispatch_event %x\n", (uint32_t)keysym);
1161 #ifdef X_HAVE_UTF8_STRING
1162 //It's Ascii or UTF8?
1163 // if (keysym != 0xffff && (keys_return[0] & 0xff) >= 0x7f )
1164 //printf("BC_WindowBase::dispatch_event %d %02x%02x\n", __LINE__, keys_return[0], keys_return[1]);
1166 if( ((keys_return[1] & 0xff) > 0x80) &&
1167 ((keys_return[0] & 0xff) > 0xC0) ) {
1168 //printf("BC_WindowBase::dispatch_event %d\n", __LINE__);
1169 key_pressed = keysym & 0xff;
1175 // block out extra keys
1185 // Translate key codes
1186 case XK_Return: key_pressed = RETURN; break;
1187 case XK_Up: key_pressed = UP; break;
1188 case XK_Down: key_pressed = DOWN; break;
1189 case XK_Left: key_pressed = LEFT; break;
1190 case XK_Right: key_pressed = RIGHT; break;
1191 case XK_Next: key_pressed = PGDN; break;
1192 case XK_Prior: key_pressed = PGUP; break;
1193 case XK_BackSpace: key_pressed = BACKSPACE; break;
1194 case XK_Escape: key_pressed = ESC; break;
1197 key_pressed = LEFTTAB;
1201 case XK_ISO_Left_Tab: key_pressed = LEFTTAB; break;
1202 case XK_underscore: key_pressed = '_'; break;
1203 case XK_asciitilde: key_pressed = '~'; break;
1204 case XK_Delete: key_pressed = DELETE; break;
1205 case XK_Home: key_pressed = HOME; break;
1206 case XK_End: key_pressed = END; break;
1209 case XK_KP_Enter: key_pressed = KPENTER; break;
1210 case XK_KP_Add: key_pressed = KPPLUS; break;
1211 case XK_KP_Subtract: key_pressed = KPMINUS; break;
1212 case XK_KP_Multiply: key_pressed = KPSTAR; break;
1213 case XK_KP_Divide: key_pressed = KPSLASH; break;
1215 case XK_KP_End: key_pressed = KP1; break;
1217 case XK_KP_Down: key_pressed = KP2; break;
1219 case XK_KP_Page_Down: key_pressed = KP3; break;
1221 case XK_KP_Left: key_pressed = KP4; break;
1223 case XK_KP_Begin: key_pressed = KP5; break;
1225 case XK_KP_Right: key_pressed = KP6; break;
1227 case XK_KP_Home: key_pressed = KP7; break;
1229 case XK_KP_Up: key_pressed = KP8; break;
1231 case XK_KP_Page_Up: key_pressed = KP9; break;
1233 case XK_KP_Insert: key_pressed = KPINS; break;
1235 case XK_KP_Delete: key_pressed = KPDEL; break;
1236 case XK_Menu: key_pressed = KPMENU; break; /* menu */
1238 // above case XK_KP_Enter: key_pressed = KPENTER; break; /* check */
1239 case XF86XK_MenuKB: key_pressed = KPMENU; break; /* menu */
1240 // intercepted case XF86XK_PowerDown: key_pressed = KPPOWER; break; /* Power */
1241 case XF86XK_Launch1: key_pressed = KPTV; break; /* TV */
1242 case XF86XK_Launch2: key_pressed = KPDVD; break; /* DVD */
1243 // intercepted case XF86XK_WWW: key_pressed = KPWWEB; break; /* WEB */
1244 case XF86XK_Launch3: key_pressed = KPBOOK; break; /* book */
1245 case XF86XK_Launch4: key_pressed = KPHAND; break; /* hand */
1246 case XF86XK_Reply: key_pressed = KPTMR; break; /* timer */
1247 case SunXK_Front: key_pressed = KPMAXW; break; /* max */
1248 // above case XK_Left: key_pressed = LEFT; break; /* left */
1249 // above case XK_Right: key_pressed = RIGHT; break; /* right */
1250 // above case XK_Down: key_pressed = DOWN; break; /* down */
1251 // above case XK_Up: key_pressed = UP; break; /* up */
1252 // above case XK_SPACE: key_pressed = KPSPACE; break; /* ok */
1253 // intercepted case XF86XK_AudioRaiseVolume: key_pressed = KPVOLU; break; /* VOL + */
1254 // intercepted case XF86XK_AudioMute: key_pressed = KPMUTE; break; /* MUTE */
1255 // intercepted case XF86XK_AudioLowerVolume: key_pressed = KPVOLD; break; /* VOL - */
1256 case XF86XK_ScrollUp: key_pressed = KPCHUP; break; /* CH + */
1257 case XF86XK_ScrollDown: key_pressed = KPCHDN; break; /* CH - */
1258 case XF86XK_AudioRecord: key_pressed = KPRECD; break; /* ( o) red */
1259 case XF86XK_Forward: key_pressed = KPPLAY; break; /* ( >) */
1260 case XK_Redo: key_pressed = KPFWRD; break; /* (>>) */
1261 case XF86XK_Back: key_pressed = KPBACK; break; /* (<<) */
1262 case XK_Cancel: key_pressed = KPSTOP; break; /* ([]) */
1263 case XK_Pause: key_pressed = KPAUSE; break; /* ('') */
1266 key_pressed = keysym & 0xff;
1267 #ifdef X_HAVE_UTF8_STRING
1268 //printf("BC_WindowBase::dispatch_event %d\n", __LINE__);
1273 #ifdef X_HAVE_UTF8_STRING
1275 key_pressed_utf8 = keys_return;
1280 if( top_level == this )
1281 result = BC_KeyboardHandler::run_listeners(this);
1283 //printf("BC_WindowBase::dispatch_event %d %d %x\n", shift_down(), alt_down(), key_pressed);
1285 result = dispatch_keypress_event();
1286 // Handle some default keypresses
1289 if(key_pressed == 'w' ||
1298 XLookupString((XKeyEvent*)event, keys_return, 1, &keysym, 0);
1299 dispatch_keyrelease_event();
1300 // printf("BC_WindowBase::dispatch_event KeyRelease keysym=0x%x keystate=0x%lld\n",
1301 // keysym, event->xkey.state);
1305 event_win = event->xany.window;
1306 dispatch_cursor_leave();
1310 event_win = event->xany.window;
1311 cursor_x = event->xcrossing.x;
1312 cursor_y = event->xcrossing.y;
1313 dispatch_cursor_enter();
1318 //printf("100 %s %p %d\n", title, event, event->type);
1319 //if(event->type != ClientMessage) dump();
1321 #ifndef SINGLE_THREAD
1323 if(event) delete event;
1325 // if(done) completion_lock->unlock();
1328 if(debug) printf("BC_WindowBase::dispatch_event this=%p %d\n", this, __LINE__);
1332 int BC_WindowBase::dispatch_expose_event()
1335 for(int i = 0; i < subwindows->total && !result; i++)
1337 result = subwindows->values[i]->dispatch_expose_event();
1340 // Propagate to user
1341 if(!result) expose_event();
1345 int BC_WindowBase::dispatch_resize_event(int w, int h)
1347 // Can't store new w and h until the event is handles
1348 // because bcfilebox depends on the old w and h to
1349 // reposition widgets.
1350 if(window_type == MAIN_WINDOW)
1354 pixmap = new BC_Pixmap(this, w, h);
1356 clear_box(0, 0, w, h);
1359 // Propagate to subwindows
1360 for(int i = 0; i < subwindows->total; i++)
1362 subwindows->values[i]->dispatch_resize_event(w, h);
1365 // Propagate to user
1368 if(window_type == MAIN_WINDOW)
1376 int BC_WindowBase::dispatch_translation_event()
1378 translation_events = 0;
1379 if(window_type == MAIN_WINDOW)
1383 x = last_translate_x;
1384 y = last_translate_y;
1385 // Correct for window manager offsets
1390 for(int i = 0; i < subwindows->total; i++)
1392 subwindows->values[i]->dispatch_translation_event();
1395 translation_event();
1399 int BC_WindowBase::dispatch_motion_event()
1404 if(top_level == this)
1407 event_win = last_motion_win;
1408 get_key_masks(last_motion_state);
1411 if(get_button_down() && !active_menubar && !active_popup_menu)
1415 cursor_x = last_motion_x;
1416 cursor_y = last_motion_y;
1417 result = dispatch_drag_motion();
1421 (last_motion_x < drag_x1 || last_motion_x >= drag_x2 ||
1422 last_motion_y < drag_y1 || last_motion_y >= drag_y2))
1427 result = dispatch_drag_start();
1431 cursor_x = last_motion_x;
1432 cursor_y = last_motion_y;
1434 // printf("BC_WindowBase::dispatch_motion_event %d %p %p %p\n",
1437 // active_popup_menu,
1438 // active_subwindow);
1440 if(active_menubar && !result) result = active_menubar->dispatch_motion_event();
1441 if(active_popup_menu && !result) result = active_popup_menu->dispatch_motion_event();
1442 if(active_subwindow && !result) result = active_subwindow->dispatch_motion_event();
1445 // Dispatch in stacking order
1446 for(int i = subwindows->size() - 1; i >= 0 && !result; i--)
1448 result = subwindows->values[i]->dispatch_motion_event();
1451 if(!result) result = cursor_motion_event(); // give to user
1455 int BC_WindowBase::dispatch_keypress_event()
1458 if(top_level == this)
1460 if(active_subwindow) result = active_subwindow->dispatch_keypress_event();
1463 for(int i = 0; i < subwindows->total && !result; i++)
1465 result = subwindows->values[i]->dispatch_keypress_event();
1468 if(!result) result = keypress_event();
1473 int BC_WindowBase::dispatch_keyrelease_event()
1476 if(top_level == this)
1478 if(active_subwindow) result = active_subwindow->dispatch_keyrelease_event();
1481 for(int i = 0; i < subwindows->total && !result; i++)
1483 result = subwindows->values[i]->dispatch_keyrelease_event();
1486 if(!result) result = keyrelease_event();
1491 int BC_WindowBase::dispatch_focus_in()
1493 for(int i = 0; i < subwindows->total; i++)
1495 subwindows->values[i]->dispatch_focus_in();
1503 int BC_WindowBase::dispatch_focus_out()
1505 for(int i = 0; i < subwindows->total; i++)
1507 subwindows->values[i]->dispatch_focus_out();
1515 int BC_WindowBase::get_has_focus()
1517 return top_level->has_focus;
1520 int BC_WindowBase::get_deleting()
1522 if(is_deleting) return 1;
1523 if(parent_window && parent_window->get_deleting()) return 1;
1527 int BC_WindowBase::dispatch_button_press()
1532 if(top_level == this)
1534 if(active_menubar) result = active_menubar->dispatch_button_press();
1535 if(active_popup_menu && !result) result = active_popup_menu->dispatch_button_press();
1536 if(active_subwindow && !result) result = active_subwindow->dispatch_button_press();
1539 for(int i = 0; i < subwindows->total && !result; i++)
1541 result = subwindows->values[i]->dispatch_button_press();
1544 if(!result) result = button_press_event();
1550 int BC_WindowBase::dispatch_button_release()
1553 if(top_level == this)
1555 if(active_menubar) result = active_menubar->dispatch_button_release();
1556 if(active_popup_menu && !result) result = active_popup_menu->dispatch_button_release();
1557 if(active_subwindow && !result) result = active_subwindow->dispatch_button_release();
1558 if(!result && button_number != 4 && button_number != 5)
1559 result = dispatch_drag_stop();
1562 for(int i = 0; i < subwindows->total && !result; i++)
1564 result = subwindows->values[i]->dispatch_button_release();
1569 result = button_release_event();
1576 int BC_WindowBase::dispatch_repeat_event(int64_t duration)
1579 // all repeat event handlers get called and decide based on activity and duration
1580 // whether to respond
1581 for(int i = 0; i < subwindows->total; i++)
1583 subwindows->values[i]->dispatch_repeat_event(duration);
1587 repeat_event(duration);
1591 // Unlock next repeat signal
1592 if(window_type == MAIN_WINDOW)
1594 #ifdef SINGLE_THREAD
1595 BC_Display::display_global->unlock_repeaters(duration);
1597 for(int i = 0; i < repeaters.total; i++)
1599 if(repeaters.values[i]->delay == duration)
1601 repeaters.values[i]->repeat_lock->unlock();
1609 void BC_WindowBase::unhide_cursor()
1614 if(top_level->is_hourglass)
1615 set_cursor(HOURGLASS_CURSOR, 1, 0);
1617 set_cursor(current_cursor, 1, 0);
1619 cursor_timer->update();
1623 void BC_WindowBase::update_video_cursor()
1625 if(video_on && !is_transparent)
1627 if(cursor_timer->get_difference() > VIDEO_CURSOR_TIMEOUT && !is_transparent)
1630 set_cursor(TRANSPARENT_CURSOR, 1, 1);
1631 cursor_timer->update();
1636 cursor_timer->update();
1641 int BC_WindowBase::dispatch_cursor_leave()
1645 for(int i = 0; i < subwindows->total; i++)
1647 subwindows->values[i]->dispatch_cursor_leave();
1650 cursor_leave_event();
1654 int BC_WindowBase::dispatch_cursor_enter()
1660 if(active_menubar) result = active_menubar->dispatch_cursor_enter();
1661 if(!result && active_popup_menu) result = active_popup_menu->dispatch_cursor_enter();
1662 if(!result && active_subwindow) result = active_subwindow->dispatch_cursor_enter();
1664 for(int i = 0; !result && i < subwindows->total; i++)
1666 result = subwindows->values[i]->dispatch_cursor_enter();
1669 if(!result) result = cursor_enter_event();
1673 int BC_WindowBase::cursor_enter_event()
1678 int BC_WindowBase::cursor_leave_event()
1683 int BC_WindowBase::close_event()
1689 int BC_WindowBase::dispatch_drag_start()
1692 if(active_menubar) result = active_menubar->dispatch_drag_start();
1693 if(!result && active_popup_menu) result = active_popup_menu->dispatch_drag_start();
1694 if(!result && active_subwindow) result = active_subwindow->dispatch_drag_start();
1696 for(int i = 0; i < subwindows->total && !result; i++)
1698 result = subwindows->values[i]->dispatch_drag_start();
1701 if(!result) result = is_dragging = drag_start_event();
1705 int BC_WindowBase::dispatch_drag_stop()
1709 for(int i = 0; i < subwindows->total && !result; i++)
1711 result = subwindows->values[i]->dispatch_drag_stop();
1714 if(is_dragging && !result)
1724 int BC_WindowBase::dispatch_drag_motion()
1727 for(int i = 0; i < subwindows->total && !result; i++)
1729 result = subwindows->values[i]->dispatch_drag_motion();
1732 if(is_dragging && !result)
1734 drag_motion_event();
1745 int BC_WindowBase::show_tooltip(int w, int h)
1749 if(tooltip_text && !tooltip_on &&
1750 (force_tooltip || get_resources()->tooltips_enabled))
1753 top_level->hide_tooltip();
1757 w = get_text_width(MEDIUMFONT, tooltip_text);
1760 h = get_text_height(MEDIUMFONT, tooltip_text);
1762 w += TOOLTIP_MARGIN * 2;
1763 h += TOOLTIP_MARGIN * 2;
1765 XTranslateCoordinates(top_level->display, win,
1766 top_level->rootwin, get_w(), get_h(),
1768 // keep the tip inside the window/display
1769 int top_x = top_level->get_x();
1770 if( x < top_x ) x = top_x;
1771 int top_w = top_x + top_level->get_w();
1772 int lmt_w = top_level->get_screen_x(0, -1) + top_level->get_screen_w(0, -1);
1773 if( top_w < lmt_w ) lmt_w = top_w;
1774 if( x+w > lmt_w ) x = lmt_w-w;
1776 int top_y = top_level->get_y();
1777 if( y < top_y ) y = top_y;
1778 int top_h = top_y + top_level->get_h();
1779 int lmt_h = top_level->get_root_h(0);
1780 if( top_h < lmt_h ) lmt_h = top_h;
1781 if( y+h > lmt_h ) y = lmt_h-h;
1783 int abs_x, abs_y, win_x, win_y;
1784 unsigned int temp_mask;
1786 XQueryPointer(top_level->display, top_level->win,
1787 &temp_win, &temp_win, &abs_x, &abs_y,
1788 &win_x, &win_y, &temp_mask);
1789 // check for cursor inside popup
1790 if( x < abs_x && abs_x < x+w && y < abs_y && abs_y < y+h )
1792 if( x-abs_x < y-abs_y )
1797 tooltip_popup = new BC_Popup(top_level, x, y, w, h,
1798 get_resources()->tooltip_bg_color);
1801 tooltip_popup->set_font(MEDIUMFONT);
1802 tooltip_popup->flash();
1803 tooltip_popup->flush();
1808 int BC_WindowBase::hide_tooltip()
1811 for(int i = 0; i < subwindows->total; i++)
1813 subwindows->values[i]->hide_tooltip();
1819 delete tooltip_popup;
1825 const char *BC_WindowBase::get_tooltip()
1827 return tooltip_text;
1830 int BC_WindowBase::set_tooltip(const char *text)
1832 tooltip_text = text;
1834 // Update existing tooltip if it is visible
1838 tooltip_popup->flash();
1843 // signal the event handler to repeat
1844 int BC_WindowBase::set_repeat(int64_t duration)
1848 printf("BC_WindowBase::set_repeat duration=%jd\n", duration);
1851 if(window_type != MAIN_WINDOW) return top_level->set_repeat(duration);
1853 #ifdef SINGLE_THREAD
1854 BC_Display::display_global->set_repeat(this, duration);
1856 // test repeater database for duplicates
1857 for(int i = 0; i < repeaters.total; i++)
1860 if(repeaters.values[i]->delay == duration)
1862 repeaters.values[i]->start_repeating(this);
1867 BC_Repeater *repeater = new BC_Repeater(this, duration);
1868 repeater->initialize();
1869 repeaters.append(repeater);
1870 repeater->start_repeating();
1875 int BC_WindowBase::unset_repeat(int64_t duration)
1877 if(window_type != MAIN_WINDOW) return top_level->unset_repeat(duration);
1879 #ifdef SINGLE_THREAD
1880 BC_Display::display_global->unset_repeat(this, duration);
1882 for(int i = 0; i < repeaters.total; i++)
1884 if(repeaters.values[i]->delay == duration)
1886 repeaters.values[i]->stop_repeating();
1894 int BC_WindowBase::unset_all_repeaters()
1896 #ifdef SINGLE_THREAD
1897 BC_Display::display_global->unset_all_repeaters(this);
1899 for(int i = 0; i < repeaters.total; i++)
1901 repeaters.values[i]->stop_repeating();
1903 repeaters.remove_all_objects();
1908 // long BC_WindowBase::get_repeat_id()
1910 // return top_level->next_repeat_id++;
1914 #ifndef SINGLE_THREAD
1915 int BC_WindowBase::arm_repeat(int64_t duration)
1917 XEvent *event = new XEvent;
1918 XClientMessageEvent *ptr = (XClientMessageEvent*)event;
1919 ptr->type = ClientMessage;
1920 ptr->message_type = RepeaterXAtom;
1922 ptr->data.l[0] = duration;
1924 // Couldn't use XSendEvent since it locked up randomly.
1930 int BC_WindowBase::recieve_custom_xatoms(xatom_event *event)
1935 int BC_WindowBase::send_custom_xatom(xatom_event *event)
1937 XEvent *myevent = new XEvent;
1938 XClientMessageEvent *ptr = (XClientMessageEvent*)myevent;
1939 ptr->type = ClientMessage;
1940 ptr->message_type = event->message_type;
1941 ptr->format = event->format;
1942 ptr->data.l[0] = event->data.l[0];
1943 ptr->data.l[1] = event->data.l[1];
1944 ptr->data.l[2] = event->data.l[2];
1945 ptr->data.l[3] = event->data.l[3];
1946 ptr->data.l[4] = event->data.l[4];
1954 Atom BC_WindowBase::create_xatom(const char *atom_name)
1956 return XInternAtom(display, atom_name, False);
1959 int BC_WindowBase::get_atoms()
1961 SetDoneXAtom = create_xatom("BC_REPEAT_EVENT");
1962 RepeaterXAtom = create_xatom("BC_CLOSE_EVENT");
1963 DelWinXAtom = create_xatom("WM_DELETE_WINDOW");
1964 ProtoXAtom = create_xatom("WM_PROTOCOLS");
1965 SetDoneXAtom = XInternAtom(display, "BC_REPEAT_EVENT", False);
1966 RepeaterXAtom = XInternAtom(display, "BC_CLOSE_EVENT", False);
1967 DelWinXAtom = XInternAtom(display, "WM_DELETE_WINDOW", False);
1968 if( (ProtoXAtom = XInternAtom(display, "WM_PROTOCOLS", False)) != 0 )
1969 XChangeProperty(display, win, ProtoXAtom, XA_ATOM, 32,
1970 PropModeReplace, (unsigned char *)&DelWinXAtom, True);
1976 void BC_WindowBase::init_cursors()
1978 arrow_cursor = XCreateFontCursor(display, XC_top_left_arrow);
1979 cross_cursor = XCreateFontCursor(display, XC_crosshair);
1980 ibeam_cursor = XCreateFontCursor(display, XC_xterm);
1981 vseparate_cursor = XCreateFontCursor(display, XC_sb_v_double_arrow);
1982 hseparate_cursor = XCreateFontCursor(display, XC_sb_h_double_arrow);
1983 move_cursor = XCreateFontCursor(display, XC_fleur);
1984 left_cursor = XCreateFontCursor(display, XC_sb_left_arrow);
1985 right_cursor = XCreateFontCursor(display, XC_sb_right_arrow);
1986 upright_arrow_cursor = XCreateFontCursor(display, XC_arrow);
1987 upleft_resize_cursor = XCreateFontCursor(display, XC_top_left_corner);
1988 upright_resize_cursor = XCreateFontCursor(display, XC_top_right_corner);
1989 downleft_resize_cursor = XCreateFontCursor(display, XC_bottom_left_corner);
1990 downright_resize_cursor = XCreateFontCursor(display, XC_bottom_right_corner);
1991 hourglass_cursor = XCreateFontCursor(display, XC_watch);
1994 char cursor_data[] = { 0,0,0,0, 0,0,0,0 };
1995 Colormap colormap = DefaultColormap(display, screen);
1996 Pixmap pixmap_bottom = XCreateBitmapFromData(display,
1997 rootwin, cursor_data, 8, 8);
1998 XColor black, dummy;
1999 XAllocNamedColor(display, colormap, "black", &black, &dummy);
2000 transparent_cursor = XCreatePixmapCursor(display,
2001 pixmap_bottom, pixmap_bottom, &black, &black, 0, 0);
2002 // XDefineCursor(display, win, transparent_cursor);
2003 XFreePixmap(display, pixmap_bottom);
2006 int BC_WindowBase::evaluate_color_model(int client_byte_order, int server_byte_order, int depth)
2008 int color_model = BC_TRANSPARENCY;
2012 color_model = BC_RGB8;
2015 color_model = (server_byte_order == client_byte_order) ? BC_RGB565 : BC_BGR565;
2018 color_model = server_byte_order ? BC_BGR888 : BC_RGB888;
2021 color_model = server_byte_order ? BC_BGR8888 : BC_ARGB8888;
2027 int BC_WindowBase::init_colors()
2030 current_color_value = current_color_pixel = 0;
2032 // Get the real depth
2035 ximage = XCreateImage(top_level->display,
2037 top_level->default_depth,
2045 bits_per_pixel = ximage->bits_per_pixel;
2046 XDestroyImage(ximage);
2048 color_model = evaluate_color_model(client_byte_order,
2051 // Get the color model
2057 cmap = XCreateColormap(display, rootwin, vis, AllocNone);
2058 create_private_colors();
2062 cmap = DefaultColormap(display, screen);
2063 create_shared_colors();
2066 allocate_color_table();
2070 //cmap = DefaultColormap(display, screen);
2071 cmap = XCreateColormap(display, rootwin, vis, AllocNone );
2077 int BC_WindowBase::create_private_colors()
2082 for(int i = 0; i < 255; i++)
2084 color = (i & 0xc0) << 16;
2085 color += (i & 0x38) << 10;
2086 color += (i & 0x7) << 5;
2087 color_table[i][0] = color;
2089 create_shared_colors(); // overwrite the necessary colors on the table
2094 int BC_WindowBase::create_color(int color)
2096 if(total_colors == 256)
2098 // replace the closest match with an exact match
2099 color_table[get_color_rgb8(color)][0] = color;
2103 // add the color to the table
2104 color_table[total_colors][0] = color;
2110 int BC_WindowBase::create_shared_colors()
2112 create_color(BLACK);
2113 create_color(WHITE);
2115 create_color(LTGREY);
2116 create_color(MEGREY);
2117 create_color(MDGREY);
2118 create_color(DKGREY);
2120 create_color(LTCYAN);
2121 create_color(MECYAN);
2122 create_color(MDCYAN);
2123 create_color(DKCYAN);
2125 create_color(LTGREEN);
2126 create_color(GREEN);
2127 create_color(DKGREEN);
2129 create_color(LTPINK);
2133 create_color(LTBLUE);
2135 create_color(DKBLUE);
2137 create_color(LTYELLOW);
2138 create_color(MEYELLOW);
2139 create_color(MDYELLOW);
2140 create_color(DKYELLOW);
2142 create_color(LTPURPLE);
2143 create_color(MEPURPLE);
2144 create_color(MDPURPLE);
2145 create_color(DKPURPLE);
2147 create_color(FGGREY);
2148 create_color(MNBLUE);
2149 create_color(ORANGE);
2150 create_color(FTGREY);
2155 int BC_WindowBase::allocate_color_table()
2157 int red, green, blue, color;
2160 for(int i = 0; i < total_colors; i++)
2162 color = color_table[i][0];
2163 red = (color & 0xFF0000) >> 16;
2164 green = (color & 0x00FF00) >> 8;
2165 blue = color & 0xFF;
2167 col.flags = DoRed | DoGreen | DoBlue;
2168 col.red = red<<8 | red;
2169 col.green = green<<8 | green;
2170 col.blue = blue<<8 | blue;
2172 XAllocColor(display, cmap, &col);
2173 color_table[i][1] = col.pixel;
2176 XInstallColormap(display, cmap);
2180 int BC_WindowBase::init_window_shape()
2182 if(bg_pixmap && bg_pixmap->use_alpha())
2184 XShapeCombineMask(top_level->display,
2185 this->win, ShapeBounding, 0, 0,
2186 bg_pixmap->get_alpha(), ShapeSet);
2192 int BC_WindowBase::init_gc()
2194 unsigned long gcmask;
2195 gcmask = GCFont | GCGraphicsExposures;
2198 gcvalues.font = mediumfont->fid; // set the font
2199 gcvalues.graphics_exposures = 0; // prevent expose events for every redraw
2200 gc = XCreateGC(display, rootwin, gcmask, &gcvalues);
2202 // gcmask = GCCapStyle | GCJoinStyle;
2203 // XGetGCValues(display, gc, gcmask, &gcvalues);
2204 // printf("BC_WindowBase::init_gc %d %d %d\n", __LINE__, gcvalues.cap_style, gcvalues.join_style);
2208 int BC_WindowBase::init_fonts()
2210 if( !(smallfont = XLoadQueryFont(display, _(resources.small_font))) )
2211 if( !(smallfont = XLoadQueryFont(display, _(resources.small_font2))) )
2212 smallfont = XLoadQueryFont(display, "fixed");
2213 if( !(mediumfont = XLoadQueryFont(display, _(resources.medium_font))) )
2214 if( !(mediumfont = XLoadQueryFont(display, _(resources.medium_font2))) )
2215 mediumfont = XLoadQueryFont(display, "fixed");
2216 if( !(largefont = XLoadQueryFont(display, _(resources.large_font))) )
2217 if( !(largefont = XLoadQueryFont(display, _(resources.large_font2))) )
2218 largefont = XLoadQueryFont(display, "fixed");
2219 if( !(bigfont = XLoadQueryFont(display, _(resources.big_font))) )
2220 if( !(bigfont = XLoadQueryFont(display, _(resources.big_font2))) )
2221 bigfont = XLoadQueryFont(display, "fixed");
2224 if(get_resources()->use_fontset)
2229 // FIXME: should check the m,d,n values
2230 smallfontset = XCreateFontSet(display, resources.small_fontset, &m, &n, &d);
2232 smallfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2233 mediumfontset = XCreateFontSet(display, resources.medium_fontset, &m, &n, &d);
2234 if( !mediumfontset )
2235 mediumfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2236 largefontset = XCreateFontSet(display, resources.large_fontset, &m, &n, &d);
2238 largefontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2239 bigfontset = XCreateFontSet(display, resources.big_fontset, &m, &n, &d);
2241 largefontset = XCreateFontSet(display, "fixed,*", &m, &n, &d);
2242 if(bigfontset && largefontset && mediumfontset && smallfontset) {
2243 curr_fontset = mediumfontset;
2244 get_resources()->use_fontset = 1;
2248 get_resources()->use_fontset = 0;
2255 void BC_WindowBase::init_xft()
2258 if(!(smallfont_xft =
2259 (resources.small_font_xft[0] == '-' ?
2260 XftFontOpenXlfd(display, screen, resources.small_font_xft) :
2261 XftFontOpenName(display, screen, resources.small_font_xft))) )
2262 if(!(smallfont_xft =
2263 XftFontOpenXlfd(display, screen, resources.small_font_xft2)))
2264 smallfont_xft = XftFontOpenXlfd(display, screen, "fixed");
2265 if(!(mediumfont_xft =
2266 (resources.medium_font_xft[0] == '-' ?
2267 XftFontOpenXlfd(display, screen, resources.medium_font_xft) :
2268 XftFontOpenName(display, screen, resources.medium_font_xft))) )
2269 if(!(mediumfont_xft =
2270 XftFontOpenXlfd(display, screen, resources.medium_font_xft2)))
2271 mediumfont_xft = XftFontOpenXlfd(display, screen, "fixed");
2272 if(!(largefont_xft =
2273 (resources.large_font_xft[0] == '-' ?
2274 XftFontOpenXlfd(display, screen, resources.large_font_xft) :
2275 XftFontOpenXlfd(display, screen, resources.large_font_xft))) )
2276 if(!(largefont_xft =
2277 XftFontOpenXlfd(display, screen, resources.large_font_xft2)))
2278 largefont_xft = XftFontOpenXlfd(display, screen, "fixed");
2280 (resources.big_font_xft[0] == '-' ?
2281 XftFontOpenXlfd(display, screen, resources.big_font_xft) :
2282 XftFontOpenName(display, screen, resources.big_font_xft))) )
2284 XftFontOpenXlfd(display, screen, resources.big_font_xft2)))
2285 bigfont_xft = XftFontOpenXlfd(display, screen, "fixed");
2287 // Extension failed to locate fonts
2288 if( !smallfont_xft || !mediumfont_xft || !largefont_xft || !bigfont_xft) {
2289 printf("BC_WindowBase::init_fonts: no xft fonts found %s=%p %s=%p %s=%p %s=%p\n",
2290 resources.small_font_xft, smallfont_xft,
2291 resources.medium_font_xft, mediumfont_xft,
2292 resources.large_font_xft, largefont_xft,
2293 resources.big_font_xft, bigfont_xft);
2294 get_resources()->use_xft = 0;
2300 void BC_WindowBase::init_im()
2302 XIMStyles *xim_styles;
2305 if(!(input_method = XOpenIM(display, NULL, NULL, NULL)))
2307 printf("BC_WindowBase::init_im: Could not open input method.\n");
2310 if(XGetIMValues(input_method, XNQueryInputStyle, &xim_styles, NULL) ||
2313 printf("BC_WindowBase::init_im: Input method doesn't support any styles.\n");
2314 XCloseIM(input_method);
2319 for(int z = 0; z < xim_styles->count_styles; z++)
2321 if(xim_styles->supported_styles[z] == (XIMPreeditNothing | XIMStatusNothing))
2323 xim_style = xim_styles->supported_styles[z];
2331 printf("BC_WindowBase::init_im: Input method doesn't support the style we need.\n");
2332 XCloseIM(input_method);
2336 input_context = XCreateIC(input_method, XNInputStyle, xim_style,
2337 XNClientWindow, win, XNFocusWindow, win, NULL);
2340 printf("BC_WindowBase::init_im: Failed to create input context.\n");
2341 XCloseIM(input_method);
2346 void BC_WindowBase::finit_im()
2348 if( input_context ) {
2349 XDestroyIC(input_context);
2352 if( input_method ) {
2353 XCloseIM(input_method);
2359 int BC_WindowBase::get_color(int64_t color)
2361 // return pixel of color
2362 // use this only for drawing subwindows not for bitmaps
2363 int i, test, difference;
2369 return get_color_rgb8(color);
2370 // test last color looked up
2371 if(current_color_value == color)
2372 return current_color_pixel;
2375 current_color_value = color;
2376 for(i = 0; i < total_colors; i++)
2378 if(color_table[i][0] == color)
2380 current_color_pixel = color_table[i][1];
2381 return current_color_pixel;
2385 // find nearest match
2386 difference = 0xFFFFFF;
2388 for(i = 0; i < total_colors; i++)
2390 test = abs((int)(color_table[i][0] - color));
2392 if(test < difference)
2394 current_color_pixel = color_table[i][1];
2398 return current_color_pixel;
2401 return get_color_rgb16(color);
2404 return get_color_bgr16(color);
2408 return client_byte_order == server_byte_order ?
2409 color : get_color_bgr24(color);
2417 int BC_WindowBase::get_color_rgb8(int color)
2421 pixel = (color & 0xc00000) >> 16;
2422 pixel += (color & 0xe000) >> 10;
2423 pixel += (color & 0xe0) >> 5;
2427 int64_t BC_WindowBase::get_color_rgb16(int color)
2430 result = (color & 0xf80000) >> 8;
2431 result += (color & 0xfc00) >> 5;
2432 result += (color & 0xf8) >> 3;
2437 int64_t BC_WindowBase::get_color_bgr16(int color)
2440 result = (color & 0xf80000) >> 19;
2441 result += (color & 0xfc00) >> 5;
2442 result += (color & 0xf8) << 8;
2447 int64_t BC_WindowBase::get_color_bgr24(int color)
2450 result = (color & 0xff) << 16;
2451 result += (color & 0xff00);
2452 result += (color & 0xff0000) >> 16;
2456 void BC_WindowBase::start_video()
2458 cursor_timer->update();
2460 // set_color(BLACK);
2461 // draw_box(0, 0, get_w(), get_h());
2465 void BC_WindowBase::stop_video()
2473 int64_t BC_WindowBase::get_color()
2475 return top_level->current_color;
2478 void BC_WindowBase::set_color(int64_t color)
2480 top_level->current_color = color;
2481 XSetForeground(top_level->display,
2483 top_level->get_color(color));
2486 void BC_WindowBase::set_opaque()
2488 XSetFunction(top_level->display, top_level->gc, GXcopy);
2491 void BC_WindowBase::set_inverse()
2493 XSetFunction(top_level->display, top_level->gc, GXxor);
2496 void BC_WindowBase::set_line_width(int value)
2498 this->line_width = value;
2499 XSetLineAttributes(top_level->display, top_level->gc, value, /* line_width */
2500 line_dashes == 0 ? LineSolid : LineOnOffDash, /* line_style */
2501 line_dashes == 0 ? CapRound : CapNotLast, /* cap_style */
2502 JoinMiter); /* join_style */
2504 if(line_dashes > 0) {
2505 const char dashes = line_dashes;
2506 XSetDashes(top_level->display, top_level->gc, 0, &dashes, 1);
2509 // XGCValues gcvalues;
2510 // unsigned long gcmask;
2511 // gcmask = GCCapStyle | GCJoinStyle;
2512 // XGetGCValues(top_level->display, top_level->gc, gcmask, &gcvalues);
2513 // printf("BC_WindowBase::set_line_width %d %d %d\n", __LINE__, gcvalues.cap_style, gcvalues.join_style);
2516 void BC_WindowBase::set_line_dashes(int value)
2518 line_dashes = value;
2519 // call XSetLineAttributes
2520 set_line_width(line_width);
2524 Cursor BC_WindowBase::get_cursor_struct(int cursor)
2528 case ARROW_CURSOR: return top_level->arrow_cursor; break;
2529 case CROSS_CURSOR: return top_level->cross_cursor;
2530 case IBEAM_CURSOR: return top_level->ibeam_cursor; break;
2531 case VSEPARATE_CURSOR: return top_level->vseparate_cursor; break;
2532 case HSEPARATE_CURSOR: return top_level->hseparate_cursor; break;
2533 case MOVE_CURSOR: return top_level->move_cursor; break;
2534 case LEFT_CURSOR: return top_level->left_cursor; break;
2535 case RIGHT_CURSOR: return top_level->right_cursor; break;
2536 case UPRIGHT_ARROW_CURSOR: return top_level->upright_arrow_cursor; break;
2537 case UPLEFT_RESIZE: return top_level->upleft_resize_cursor; break;
2538 case UPRIGHT_RESIZE: return top_level->upright_resize_cursor; break;
2539 case DOWNLEFT_RESIZE: return top_level->downleft_resize_cursor; break;
2540 case DOWNRIGHT_RESIZE: return top_level->downright_resize_cursor; break;
2541 case HOURGLASS_CURSOR: return top_level->hourglass_cursor; break;
2542 case TRANSPARENT_CURSOR: return top_level->transparent_cursor; break;
2547 void BC_WindowBase::set_cursor(int cursor, int override, int flush)
2549 // inherit cursor from parent
2552 XUndefineCursor(top_level->display, win);
2553 current_cursor = cursor;
2556 // don't change cursor if overridden
2557 if((!top_level->is_hourglass && !is_transparent) ||
2560 XDefineCursor(top_level->display, win, get_cursor_struct(cursor));
2561 if(flush) this->flush();
2564 if(!override) current_cursor = cursor;
2567 void BC_WindowBase::set_x_cursor(int cursor)
2569 temp_cursor = XCreateFontCursor(top_level->display, cursor);
2570 XDefineCursor(top_level->display, win, temp_cursor);
2571 current_cursor = cursor;
2575 int BC_WindowBase::get_cursor()
2577 return current_cursor;
2580 void BC_WindowBase::start_hourglass()
2582 top_level->start_hourglass_recursive();
2586 void BC_WindowBase::stop_hourglass()
2588 top_level->stop_hourglass_recursive();
2592 void BC_WindowBase::start_hourglass_recursive()
2594 if(this == top_level)
2602 set_cursor(HOURGLASS_CURSOR, 1, 0);
2603 for(int i = 0; i < subwindows->total; i++)
2605 subwindows->values[i]->start_hourglass_recursive();
2610 void BC_WindowBase::stop_hourglass_recursive()
2612 if(this == top_level)
2614 if(hourglass_total == 0) return;
2615 top_level->hourglass_total--;
2618 if(!top_level->hourglass_total)
2620 top_level->is_hourglass = 0;
2622 // Cause set_cursor to perform change
2624 set_cursor(current_cursor, 1, 0);
2626 for(int i = 0; i < subwindows->total; i++)
2628 subwindows->values[i]->stop_hourglass_recursive();
2636 XFontStruct* BC_WindowBase::get_font_struct(int font)
2638 // Clear out unrelated flags
2639 if(font & BOLDFACE) font ^= BOLDFACE;
2642 case SMALLFONT: return top_level->smallfont; break;
2643 case MEDIUMFONT: return top_level->mediumfont; break;
2644 case LARGEFONT: return top_level->largefont; break;
2645 case BIGFONT: return top_level->bigfont; break;
2650 XFontSet BC_WindowBase::get_fontset(int font)
2654 if(get_resources()->use_fontset)
2656 switch(font & 0xff) {
2657 case SMALLFONT: fs = top_level->smallfontset; break;
2658 case MEDIUMFONT: fs = top_level->mediumfontset; break;
2659 case LARGEFONT: fs = top_level->largefontset; break;
2660 case BIGFONT: fs = top_level->bigfontset; break;
2668 XftFont* BC_WindowBase::get_xft_struct(int font)
2671 case SMALLFONT: return (XftFont*)top_level->smallfont_xft;
2672 case MEDIUMFONT: return (XftFont*)top_level->mediumfont_xft;
2673 case LARGEFONT: return (XftFont*)top_level->largefont_xft;
2674 case BIGFONT: return (XftFont*)top_level->bigfont_xft;
2675 case MEDIUMFONT_3D: return (XftFont*)top_level->bold_mediumfont_xft;
2676 case SMALLFONT_3D: return (XftFont*)top_level->bold_smallfont_xft;
2677 case LARGEFONT_3D: return (XftFont*)top_level->bold_largefont_xft;
2692 int BC_WindowBase::get_current_font()
2694 return top_level->current_font;
2697 void BC_WindowBase::set_font(int font)
2699 top_level->current_font = font;
2702 if(get_resources()->use_xft) {}
2705 if(get_resources()->use_fontset) {
2709 if(get_font_struct(font))
2711 XSetFont(top_level->display, top_level->gc, get_font_struct(font)->fid);
2717 void BC_WindowBase::set_fontset(int font)
2721 if(get_resources()->use_fontset) {
2723 case SMALLFONT: fs = top_level->smallfontset; break;
2724 case MEDIUMFONT: fs = top_level->mediumfontset; break;
2725 case LARGEFONT: fs = top_level->largefontset; break;
2726 case BIGFONT: fs = top_level->bigfontset; break;
2734 XFontSet BC_WindowBase::get_curr_fontset(void)
2736 if(get_resources()->use_fontset)
2737 return curr_fontset;
2741 int BC_WindowBase::get_single_text_width(int font, const char *text, int length)
2744 if(get_resources()->use_xft && get_xft_struct(font))
2747 #ifdef X_HAVE_UTF8_STRING
2748 if(get_resources()->locale_utf8)
2750 XftTextExtentsUtf8(top_level->display,
2751 get_xft_struct(font),
2752 (const XftChar8 *)text,
2759 XftTextExtents8(top_level->display,
2760 get_xft_struct(font),
2761 (const XftChar8 *)text,
2765 return extents.xOff;
2769 if(get_resources()->use_fontset && top_level->get_fontset(font))
2770 return XmbTextEscapement(top_level->get_fontset(font), text, length);
2772 if(get_font_struct(font))
2773 return XTextWidth(get_font_struct(font), text, length);
2779 case MEDIUM_7SEGMENT:
2780 return get_resources()->medium_7segment[0]->get_w() * length;
2790 int BC_WindowBase::get_single_text_width(int font, const wchar_t *text, int length)
2795 XftTextExtents32(top_level->display,
2796 get_xft_struct(font),
2797 (const FcChar32*)text,
2800 return extents.xOff;
2804 int BC_WindowBase::get_text_width(int font, const char *text, int length)
2806 int i, j, w = 0, line_w = 0;
2807 if(length < 0) length = strlen(text);
2809 for(i = 0, j = 0; i <= length; i++)
2814 line_w = get_single_text_width(font, &text[j], i - j);
2820 line_w = get_single_text_width(font, &text[j], length - j);
2822 if(line_w > w) w = line_w;
2825 if(i > length && w == 0)
2827 w = get_single_text_width(font, text, length);
2833 int BC_WindowBase::get_text_width(int font, const wchar_t *text, int length)
2835 int i, j, w = 0, line_w = 0;
2837 if(length < 0) length = wcslen(text);
2839 for(i = 0, j = 0; i <= length; i++)
2844 line_w = get_single_text_width(font, &text[j], i - j);
2849 line_w = get_single_text_width(font, &text[j], length - j);
2851 if(line_w > w) w = line_w;
2854 if(i > length && w == 0)
2855 w = get_single_text_width(font, text, length);
2860 int BC_WindowBase::get_text_ascent(int font)
2864 if( (fstruct = get_xft_struct(font)) != 0 )
2865 return fstruct->ascent;
2867 if(get_resources()->use_fontset && top_level->get_fontset(font))
2869 XFontSetExtents *extents;
2871 extents = XExtentsOfFontSet(top_level->get_fontset(font));
2872 return -extents->max_logical_extent.y;
2875 if(get_font_struct(font))
2876 return top_level->get_font_struct(font)->ascent;
2879 case MEDIUM_7SEGMENT:
2880 return get_resources()->medium_7segment[0]->get_h();
2885 int BC_WindowBase::get_text_descent(int font)
2889 if( (fstruct = get_xft_struct(font)) != 0 )
2890 return fstruct->descent;
2892 if(get_resources()->use_fontset && top_level->get_fontset(font)) {
2893 XFontSetExtents *extents;
2894 extents = XExtentsOfFontSet(top_level->get_fontset(font));
2895 return (extents->max_logical_extent.height
2896 + extents->max_logical_extent.y);
2899 if(get_font_struct(font))
2900 return top_level->get_font_struct(font)->descent;
2905 int BC_WindowBase::get_text_height(int font, const char *text)
2910 if( (fstruct = get_xft_struct(font)) != 0 )
2911 rowh = fstruct->height;
2914 rowh = get_text_ascent(font) + get_text_descent(font);
2916 if(!text) return rowh;
2918 // Add height of lines
2919 int h = 0, i, length = strlen(text);
2920 for(i = 0; i <= length; i++)
2931 BC_Bitmap* BC_WindowBase::new_bitmap(int w, int h, int color_model)
2933 if(color_model < 0) color_model = top_level->get_color_model();
2934 return new BC_Bitmap(top_level, w, h, color_model);
2937 void BC_WindowBase::init_wait()
2939 #ifndef SINGLE_THREAD
2940 if(window_type != MAIN_WINDOW)
2941 top_level->init_wait();
2942 init_lock->lock("BC_WindowBase::init_wait");
2943 init_lock->unlock();
2947 int BC_WindowBase::accel_available(int color_model, int lock_it)
2949 if(window_type != MAIN_WINDOW)
2950 return top_level->accel_available(color_model, lock_it);
2954 if(lock_it) lock_window("BC_WindowBase::accel_available");
2958 result = grab_port_id(this, color_model);
2961 xvideo_port_id = result;
2973 //printf("BC_WindowBase::accel_available 1\n");
2974 result = grab_port_id(this, color_model);
2975 //printf("BC_WindowBase::accel_available 2 %d\n", result);
2978 xvideo_port_id = result;
2983 //printf("BC_WindowBase::accel_available 3 %d\n", xvideo_port_id);
2991 if(lock_it) unlock_window();
2992 //printf("BC_WindowBase::accel_available %d %d\n", color_model, result);
2997 int BC_WindowBase::grab_port_id(BC_WindowBase *window, int color_model)
2999 int numFormats, i, j, k;
3000 unsigned int ver, rev, numAdapt, reqBase, eventBase, errorBase;
3001 XvAdaptorInfo *info;
3002 XvImageFormatValues *formats;
3005 if(!get_resources()->use_xvideo) return -1;
3007 // Translate from color_model to X color model
3008 x_color_model = BC_CModels::bc_to_x(color_model);
3010 // Only local server is fast enough.
3011 if(!resources.use_shm) return -1;
3013 // XV extension is available
3014 if(Success != XvQueryExtension(window->display, &ver, &rev,
3015 &reqBase, &eventBase, &errorBase)) {
3019 // XV adaptors are available
3020 XvQueryAdaptors(window->display,
3021 DefaultRootWindow(window->display),
3028 // Get adaptor with desired color model
3029 for(i = 0; i < (int)numAdapt && xvideo_port_id == -1; i++) {
3030 /* adaptor supports XvImages */
3031 if(info[i].type & XvImageMask)
3033 formats = XvListImageFormats(window->display,
3036 // for(j = 0; j < numFormats; j++)
3037 // printf("%08x\n", formats[j].id);
3039 int numPorts = info[i].num_ports;
3040 for(j = 0; j < (int)numFormats && xvideo_port_id < 0; j++)
3042 /* this adaptor supports the desired format */
3043 if(formats[j].id == x_color_model)
3045 /* Try to grab a port */
3046 for(k = 0; k < numPorts; k++)
3049 if(Success == XvGrabPort(top_level->display,
3050 info[i].base_id + k,
3053 //printf("BC_WindowBase::grab_port_id %llx\n", info[i].base_id);
3054 xvideo_port_id = info[i].base_id + k;
3060 if(formats) XFree(formats);
3064 XvFreeAdaptorInfo(info);
3066 return xvideo_port_id;
3070 int BC_WindowBase::show_window(int flush)
3072 for(int i = 0; i < subwindows->size(); i++)
3074 subwindows->get(i)->show_window(0);
3077 XMapWindow(top_level->display, win);
3078 if(flush) XFlush(top_level->display);
3079 // XSync(top_level->display, 0);
3084 int BC_WindowBase::hide_window(int flush)
3086 for(int i = 0; i < subwindows->size(); i++)
3088 subwindows->get(i)->hide_window(0);
3091 XUnmapWindow(top_level->display, win);
3092 if(flush) this->flush();
3097 BC_MenuBar* BC_WindowBase::add_menubar(BC_MenuBar *menu_bar)
3099 subwindows->append((BC_SubWindow*)menu_bar);
3101 menu_bar->parent_window = this;
3102 menu_bar->top_level = this->top_level;
3103 menu_bar->initialize();
3107 BC_WindowBase* BC_WindowBase::add_popup(BC_WindowBase *window)
3109 //printf("BC_WindowBase::add_popup window=%p win=%p\n", window, window->win);
3110 if(this != top_level) return top_level->add_popup(window);
3111 popups.append(window);
3115 void BC_WindowBase::remove_popup(BC_WindowBase *window)
3117 //printf("BC_WindowBase::remove_popup %d size=%d window=%p win=%p\n", __LINE__, popups.size(), window, window->win);
3118 if(this != top_level)
3119 top_level->remove_popup(window);
3121 popups.remove(window);
3122 //printf("BC_WindowBase::remove_popup %d size=%d window=%p win=%p\n", __LINE__, popups.size(), window, window->win);
3126 BC_WindowBase* BC_WindowBase::add_subwindow(BC_WindowBase *subwindow)
3128 subwindows->append(subwindow);
3130 if(subwindow->bg_color == -1) subwindow->bg_color = this->bg_color;
3132 // parent window must be set before the subwindow initialization
3133 subwindow->parent_window = this;
3134 subwindow->top_level = this->top_level;
3136 // Execute derived initialization
3137 subwindow->initialize();
3142 BC_WindowBase* BC_WindowBase::add_tool(BC_WindowBase *subwindow)
3144 return add_subwindow(subwindow);
3147 int BC_WindowBase::flash(int x, int y, int w, int h, int flush)
3149 //printf("BC_WindowBase::flash %d %d %d %d %d\n", __LINE__, w, h, this->w, this->h);
3151 XSetWindowBackgroundPixmap(top_level->display, win, pixmap->opaque_pixmap);
3154 XClearArea(top_level->display, win, x, y, w, h, 0);
3158 XClearWindow(top_level->display, win);
3166 int BC_WindowBase::flash(int flush)
3168 flash(-1, -1, -1, -1, flush);
3172 void BC_WindowBase::flush()
3174 //if(!get_window_lock())
3175 // printf("BC_WindowBase::flush %s not locked\n", top_level->title);
3176 // X gets hosed if Flush/Sync are not user locked (at libX11-1.1.5 / libxcb-1.1.91)
3177 // _XReply deadlocks in condition_wait waiting for xlib lock when waiters!=-1
3178 int locked = get_window_lock();
3179 if( !locked ) lock_window("BC_WindowBase::flush");
3180 XFlush(top_level->display);
3181 if( !locked ) unlock_window();
3184 void BC_WindowBase::sync_display()
3186 int locked = get_window_lock();
3187 if( !locked ) lock_window("BC_WindowBase::sync_display");
3188 XSync(top_level->display, False);
3189 if( !locked ) unlock_window();
3192 int BC_WindowBase::get_window_lock()
3194 #ifdef SINGLE_THREAD
3195 return BC_Display::display_global->get_display_locked();
3197 return top_level->window_lock;
3201 int BC_WindowBase::lock_window(const char *location)
3203 if(top_level && top_level != this)
3205 top_level->lock_window(location);
3210 SET_LOCK(this, title, location);
3211 #ifdef SINGLE_THREAD
3212 BC_Display::lock_display(location);
3214 XLockDisplay(top_level->display);
3215 top_level->display_lock_owner = pthread_self();
3218 ++top_level->window_lock;
3222 printf("BC_WindowBase::lock_window top_level NULL\n");
3227 int BC_WindowBase::unlock_window()
3229 if(top_level && top_level != this)
3231 top_level->unlock_window();
3238 // if(!top_level->window_lock)
3240 // printf("BC_WindowBase::unlock_window %d %s already unlocked\n",
3244 if( top_level->window_lock > 0 )
3245 if( --top_level->window_lock == 0 )
3246 top_level->display_lock_owner = 0;
3247 #ifdef SINGLE_THREAD
3248 BC_Display::unlock_display();
3250 XUnlockDisplay(top_level->display);
3255 printf("BC_WindowBase::unlock_window top_level NULL\n");
3260 void BC_WindowBase::set_done(int return_value)
3262 if(done_set) return;
3264 if(window_type != MAIN_WINDOW)
3265 top_level->set_done(return_value);
3268 #ifdef SINGLE_THREAD
3269 this->return_value = return_value;
3270 BC_Display::display_global->arm_completion(this);
3271 completion_lock->unlock();
3272 #else // SINGLE_THREAD
3274 if( !event_thread ) return;
3275 XEvent *event = new XEvent;
3276 XClientMessageEvent *ptr = (XClientMessageEvent*)event;
3277 event->type = ClientMessage;
3278 ptr->message_type = SetDoneXAtom;
3280 this->return_value = return_value;
3281 // May lock up here because XSendEvent doesn't work too well
3282 // asynchronous with XNextEvent.
3283 // This causes BC_WindowEvents to forward a copy of the event to run_window where
3285 // Deletion of event_thread is done at the end of BC_WindowBase::run_window() - by calling the destructor
3291 void BC_WindowBase::close(int return_value)
3293 hide_window(); flush();
3294 set_done(return_value);
3297 int BC_WindowBase::get_w()
3302 int BC_WindowBase::get_h()
3307 int BC_WindowBase::get_x()
3312 int BC_WindowBase::get_y()
3318 // WidthOfScreen/HeightOfScreen of XDefaultScreenOfDisplay
3319 // this is the bounding box of all the screens
3321 int BC_WindowBase::get_root_w(int lock_display)
3323 if(lock_display) lock_window("BC_WindowBase::get_root_w");
3324 Screen *def_screen = XDefaultScreenOfDisplay(top_level->display);
3325 int result = WidthOfScreen(def_screen);
3326 if(lock_display) unlock_window();
3330 int BC_WindowBase::get_root_h(int lock_display)
3332 if(lock_display) lock_window("BC_WindowBase::get_root_h");
3333 Screen *def_screen = XDefaultScreenOfDisplay(top_level->display);
3334 int result = HeightOfScreen(def_screen);
3335 if(lock_display) unlock_window();
3339 XineramaScreenInfo *
3340 BC_WindowBase::get_xinerama_info(int screen)
3342 if( !xinerama_info || !xinerama_screens ) return 0;
3344 for( int i=0; i<xinerama_screens; ++i )
3345 if( xinerama_info[i].screen_number == screen )
3346 return &xinerama_info[i];
3349 int top_x = get_x(), top_y = get_y();
3350 for( int i=0; i<xinerama_screens; ++i ) {
3351 int scr_y = top_y - xinerama_info[i].y_org;
3352 if( scr_y < 0 || scr_y >= xinerama_info[i].height ) continue;
3353 int scr_x = top_x - xinerama_info[i].x_org;
3354 if( scr_x >= 0 && scr_x < xinerama_info[i].width )
3355 return &xinerama_info[i];
3360 int BC_WindowBase::get_screen_x(int lock_display, int screen)
3363 if(lock_display) lock_window("BC_WindowBase::get_screen_x");
3364 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3367 int root_w = get_root_w(0);
3368 int root_h = get_root_h(0);
3369 // Shift X based on position of current window if dual head
3370 if( (float)root_w/root_h > 1.8 ) {
3371 root_w = get_screen_w(0, 0);
3372 if( top_level->get_x() >= root_w )
3377 result = info->x_org;
3378 if(lock_display) unlock_window();
3382 int BC_WindowBase::get_screen_y(int lock_display, int screen)
3384 if(lock_display) lock_window("BC_WindowBase::get_screen_y");
3385 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3386 int result = !info ? 0 : info->y_org;
3387 if(lock_display) unlock_window();
3391 int BC_WindowBase::get_screen_w(int lock_display, int screen)
3394 if(lock_display) lock_window("BC_WindowBase::get_screen_w");
3395 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3397 int width = get_root_w(0);
3398 int height = get_root_h(0);
3399 if( (float)width/height > 1.8 ) {
3400 // If dual head, the screen width is > 16x9
3401 // but we only want to fill one screen
3402 // this code assumes the "big" screen is on the right
3403 int scr_w0 = width / 2;
3405 case 600: scr_w0 = 800; break;
3406 case 720: scr_w0 = 1280; break;
3407 case 1024: scr_w0 = 1280; break;
3408 case 1200: scr_w0 = 1600; break;
3409 case 1080: scr_w0 = 1920; break;
3411 int scr_w1 = width - scr_w0;
3412 result = screen > 0 ? scr_w1 :
3413 screen == 0 ? scr_w0 :
3414 top_level->get_x() < scr_w0 ? scr_w0 : scr_w1;
3420 result = info->width;
3421 if(lock_display) unlock_window();
3425 int BC_WindowBase::get_screen_h(int lock_display, int screen)
3427 if(lock_display) lock_window("BC_WindowBase::get_screen_h");
3428 XineramaScreenInfo *info = top_level->get_xinerama_info(screen);
3429 int result = info ? info->height : get_root_h(0);
3430 if(lock_display) unlock_window();
3434 // Bottom right corner
3435 int BC_WindowBase::get_x2()
3440 int BC_WindowBase::get_y2()
3445 int BC_WindowBase::get_video_on()
3450 int BC_WindowBase::get_hidden()
3452 return top_level->hidden;
3455 int BC_WindowBase::cursor_inside()
3457 return (top_level->cursor_x >= 0 &&
3458 top_level->cursor_y >= 0 &&
3459 top_level->cursor_x < w &&
3460 top_level->cursor_y < h);
3463 BC_WindowBase* BC_WindowBase::get_top_level()
3468 BC_WindowBase* BC_WindowBase::get_parent()
3470 return parent_window;
3473 int BC_WindowBase::get_color_model()
3475 return top_level->color_model;
3478 BC_Resources* BC_WindowBase::get_resources()
3480 return &BC_WindowBase::resources;
3483 BC_Synchronous* BC_WindowBase::get_synchronous()
3485 return BC_WindowBase::resources.get_synchronous();
3488 int BC_WindowBase::get_bg_color()
3493 void BC_WindowBase::set_bg_color(int color)
3495 this->bg_color = color;
3498 BC_Pixmap* BC_WindowBase::get_bg_pixmap()
3503 void BC_WindowBase::set_active_subwindow(BC_WindowBase *subwindow)
3505 top_level->active_subwindow = subwindow;
3508 int BC_WindowBase::activate()
3513 int BC_WindowBase::deactivate()
3515 if(window_type == MAIN_WINDOW)
3517 if(top_level->active_menubar) top_level->active_menubar->deactivate();
3518 if(top_level->active_popup_menu) top_level->active_popup_menu->deactivate();
3519 if(top_level->active_subwindow) top_level->active_subwindow->deactivate();
3521 top_level->active_menubar = 0;
3522 top_level->active_popup_menu = 0;
3523 top_level->active_subwindow = 0;
3528 int BC_WindowBase::cycle_textboxes(int amount)
3531 BC_WindowBase *new_textbox = 0;
3535 BC_WindowBase *first_textbox = 0;
3536 find_next_textbox(&first_textbox, &new_textbox, result);
3537 if(!new_textbox) new_textbox = first_textbox;
3543 BC_WindowBase *last_textbox = 0;
3544 find_prev_textbox(&last_textbox, &new_textbox, result);
3545 if(!new_textbox) new_textbox = last_textbox;
3549 if(new_textbox != active_subwindow)
3552 new_textbox->activate();
3558 int BC_WindowBase::find_next_textbox(BC_WindowBase **first_textbox, BC_WindowBase **next_textbox, int &result)
3560 // Search subwindows for textbox
3561 for(int i = 0; i < subwindows->total && result < 2; i++)
3563 BC_WindowBase *test_subwindow = subwindows->values[i];
3564 test_subwindow->find_next_textbox(first_textbox, next_textbox, result);
3571 if(!*first_textbox) *first_textbox = this;
3575 if(top_level->active_subwindow == this)
3581 *next_textbox = this;
3588 int BC_WindowBase::find_prev_textbox(BC_WindowBase **last_textbox, BC_WindowBase **prev_textbox, int &result)
3594 if(!*last_textbox) *last_textbox = this;
3598 if(top_level->active_subwindow == this)
3604 *prev_textbox = this;
3609 // Search subwindows for textbox
3610 for(int i = subwindows->total - 1; i >= 0 && result < 2; i--)
3612 BC_WindowBase *test_subwindow = subwindows->values[i];
3613 test_subwindow->find_prev_textbox(last_textbox, prev_textbox, result);
3618 BC_Clipboard* BC_WindowBase::get_clipboard()
3620 #ifdef SINGLE_THREAD
3621 return BC_Display::display_global->clipboard;
3623 return top_level->clipboard;
3627 int BC_WindowBase::get_relative_cursor_x()
3629 int abs_x, abs_y, x, y, win_x, win_y;
3630 unsigned int temp_mask;
3633 XQueryPointer(top_level->display, top_level->win,
3634 &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y,
3637 XTranslateCoordinates(top_level->display, top_level->rootwin,
3638 win, abs_x, abs_y, &x, &y, &temp_win);
3643 int BC_WindowBase::get_relative_cursor_y()
3645 int abs_x, abs_y, x, y, win_x, win_y;
3646 unsigned int temp_mask;
3649 XQueryPointer(top_level->display, top_level->win,
3650 &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y,
3653 XTranslateCoordinates(top_level->display,
3654 top_level->rootwin, win, abs_x, abs_y, &x, &y, &temp_win);
3659 int BC_WindowBase::get_abs_cursor_x(int lock_window)
3661 int abs_x, abs_y, win_x, win_y;
3662 unsigned int temp_mask;
3665 if(lock_window) this->lock_window("BC_WindowBase::get_abs_cursor_x");
3666 XQueryPointer(top_level->display, top_level->win,
3667 &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y,
3669 if(lock_window) this->unlock_window();
3673 int BC_WindowBase::get_abs_cursor_y(int lock_window)
3675 int abs_x, abs_y, win_x, win_y;
3676 unsigned int temp_mask;
3679 if(lock_window) this->lock_window("BC_WindowBase::get_abs_cursor_y");
3680 XQueryPointer(top_level->display, top_level->win,
3681 &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y,
3683 if(lock_window) this->unlock_window();
3687 int BC_WindowBase::match_window(Window win)
3689 if (this->win == win) return 1;
3691 for(int i = 0; i < subwindows->total; i++) {
3692 result = subwindows->values[i]->match_window(win);
3693 if (result) return result;
3699 int BC_WindowBase::get_cursor_over_window()
3701 if(top_level != this) return top_level->get_cursor_over_window();
3703 int abs_x, abs_y, win_x, win_y;
3704 unsigned int temp_mask;
3705 Window root_return, child_return;
3707 int ret = XQueryPointer(display, win,
3708 &root_return, &child_return, &abs_x, &abs_y,
3709 &win_x, &win_y, &temp_mask);
3710 //printf("BC_WindowBase::get_cursor_over_window %d %s 0x%x %d 0x%x\n",
3711 // __LINE__, title, win, ret, child_return);
3713 int result = !ret || child_return == None ? 0 :
3714 match_window(child_return);
3718 int BC_WindowBase::cursor_above()
3720 int rx = get_relative_cursor_x();
3721 if( rx < 0 || rx >= get_w() ) return 0;
3722 int ry = get_relative_cursor_y();
3723 if( ry < 0 || ry >= get_h() ) return 0;
3727 int BC_WindowBase::get_drag_x()
3729 return top_level->drag_x;
3732 int BC_WindowBase::get_drag_y()
3734 return top_level->drag_y;
3737 int BC_WindowBase::get_cursor_x()
3739 return top_level->cursor_x;
3742 int BC_WindowBase::get_cursor_y()
3744 return top_level->cursor_y;
3747 int BC_WindowBase::dump_windows()
3749 printf("\tBC_WindowBase::dump_windows window=%p win=%p\n",
3750 this, (void*)this->win);
3751 for(int i = 0; i < subwindows->size(); i++)
3752 subwindows->get(i)->dump_windows();
3753 for(int i = 0; i < popups.size(); i++)
3754 printf("\tBC_WindowBase::dump_windows popup=%p win=%p\n",
3755 popups.get(i), (void*)popups.get(i)->win);
3759 int BC_WindowBase::is_event_win()
3761 return this->win == top_level->event_win;
3764 void BC_WindowBase::set_dragging(int value)
3766 is_dragging = value;
3769 int BC_WindowBase::get_dragging()
3774 int BC_WindowBase::get_buttonpress()
3776 return top_level->button_number;
3779 int BC_WindowBase::get_button_down()
3781 return top_level->button_down;
3784 int BC_WindowBase::alt_down()
3786 return top_level->alt_mask;
3789 int BC_WindowBase::shift_down()
3791 return top_level->shift_mask;
3794 int BC_WindowBase::ctrl_down()
3796 return top_level->ctrl_mask;
3799 wchar_t* BC_WindowBase::get_wkeystring(int *length)
3802 *length = top_level->wkey_string_length;
3803 return top_level->wkey_string;
3806 #ifdef X_HAVE_UTF8_STRING
3807 char* BC_WindowBase::get_keypress_utf8()
3809 return top_level->key_pressed_utf8;
3814 int BC_WindowBase::get_keypress()
3816 return top_level->key_pressed;
3819 int BC_WindowBase::get_double_click()
3821 return top_level->double_click;
3824 int BC_WindowBase::get_triple_click()
3826 return top_level->triple_click;
3829 int BC_WindowBase::get_bgcolor()
3834 int BC_WindowBase::resize_window(int w, int h)
3836 if(this->w == w && this->h == h) return 0;
3838 if(window_type == MAIN_WINDOW && !allow_resize)
3840 XSizeHints size_hints;
3841 size_hints.flags = PSize | PMinSize | PMaxSize;
3842 size_hints.width = w;
3843 size_hints.height = h;
3844 size_hints.min_width = w;
3845 size_hints.max_width = w;
3846 size_hints.min_height = h;
3847 size_hints.max_height = h;
3848 XSetNormalHints(top_level->display, win, &size_hints);
3850 XResizeWindow(top_level->display, win, w, h);
3855 pixmap = new BC_Pixmap(this, w, h);
3857 // Propagate to menubar
3858 for(int i = 0; i < subwindows->total; i++)
3860 subwindows->values[i]->dispatch_resize_event(w, h);
3863 draw_background(0, 0, w, h);
3864 if(top_level == this && get_resources()->recursive_resizing)
3865 resize_history.append(new BC_ResizeCall(w, h));
3869 // The only way for resize events to be propagated is by updating the internal w and h
3870 int BC_WindowBase::resize_event(int w, int h)
3872 if(window_type == MAIN_WINDOW)
3880 int BC_WindowBase::reposition_window(int x, int y)
3882 reposition_window(x, y, -1, -1);
3887 int BC_WindowBase::reposition_window(int x, int y, int w, int h)
3891 // Some tools set their own dimensions before calling this, causing the
3892 // resize check to skip.
3896 if(w > 0 && w != this->w)
3902 if(h > 0 && h != this->h)
3908 //printf("BC_WindowBase::reposition_window %d %d %d\n", translation_count, x_correction, y_correction);
3911 printf("BC_WindowBase::reposition_window this->w == %d\n", this->w);
3913 printf("BC_WindowBase::reposition_window this->h == %d\n", this->h);
3915 if(translation_count && window_type == MAIN_WINDOW)
3917 // KDE shifts window right and down.
3918 // FVWM leaves window alone and adds border around it.
3919 XMoveResizeWindow(top_level->display,
3921 x - BC_DisplayInfo::auto_reposition_x,
3922 y - BC_DisplayInfo::auto_reposition_y,
3928 XMoveResizeWindow(top_level->display,
3939 pixmap = new BC_Pixmap(this, this->w, this->h);
3940 // Propagate to menubar
3941 for(int i = 0; i < subwindows->total; i++)
3943 subwindows->values[i]->dispatch_resize_event(this->w, this->h);
3946 // draw_background(0, 0, w, h);
3952 int BC_WindowBase::reposition_window_relative(int dx, int dy, int w, int h)
3954 return reposition_window(get_x()+dx, get_y()+dy, w, h);
3957 int BC_WindowBase::reposition_window_relative(int dx, int dy)
3959 return reposition_window_relative(dx, dy, -1, -1);
3962 void BC_WindowBase::set_tooltips(int v)
3964 get_resources()->tooltips_enabled = v;
3967 void BC_WindowBase::set_force_tooltip(int v)
3972 int BC_WindowBase::raise_window(int do_flush)
3974 XRaiseWindow(top_level->display, win);
3975 if(do_flush) XFlush(top_level->display);
3979 int BC_WindowBase::lower_window(int do_flush)
3981 XLowerWindow(top_level->display, win);
3982 if(do_flush) XFlush(top_level->display);
3986 void BC_WindowBase::set_background(VFrame *bitmap)
3988 if(bg_pixmap && !shared_bg_pixmap) delete bg_pixmap;
3990 bg_pixmap = new BC_Pixmap(this,
3993 shared_bg_pixmap = 0;
3994 draw_background(0, 0, w, h);
3997 void BC_WindowBase::set_title(const char *text)
3999 XTextProperty titleprop;
4002 strcpy(this->title, _(text));
4003 txlist[0] = this->title;
4006 XmbTextListToTextProperty(top_level->display, txlist, 1,
4007 XStdICCTextStyle, &titleprop);
4008 XSetWMName(top_level->display, top_level->win, &titleprop);
4009 XSetWMIconName(top_level->display, top_level->win, &titleprop);
4010 XFree(titleprop.value);
4015 void BC_WindowBase::set_utf8title(const char *text)
4017 XTextProperty titleprop;
4020 strcpy(this->title, text);
4021 txlist[0] = this->title;
4024 Xutf8TextListToTextProperty(top_level->display, txlist, 1,
4025 XUTF8StringStyle, &titleprop);
4026 XSetWMName(top_level->display, top_level->win, &titleprop);
4027 XSetWMIconName(top_level->display, top_level->win, &titleprop);
4028 XFree(titleprop.value);
4033 const char *BC_WindowBase::get_title()
4038 int BC_WindowBase::get_toggle_value()
4040 return toggle_value;
4043 int BC_WindowBase::get_toggle_drag()
4048 int BC_WindowBase::set_icon(VFrame *data)
4050 if(icon_pixmap) delete icon_pixmap;
4051 icon_pixmap = new BC_Pixmap(top_level,
4056 if(icon_window) delete icon_window;
4057 icon_window = new BC_Popup(this,
4060 icon_pixmap->get_w(),
4061 icon_pixmap->get_h(),
4063 1, // All windows are hidden initially
4067 wm_hints.flags = WindowGroupHint | IconPixmapHint | IconMaskHint | IconWindowHint;
4068 wm_hints.icon_pixmap = icon_pixmap->get_pixmap();
4069 wm_hints.icon_mask = icon_pixmap->get_alpha();
4070 wm_hints.icon_window = icon_window->win;
4071 wm_hints.window_group = XGroupLeader;
4073 // for(int i = 0; i < 1000; i++)
4074 // printf("02x ", icon_pixmap->get_alpha()->get_row_pointers()[0][i]);
4077 XSetWMHints(top_level->display, top_level->win, &wm_hints);
4078 XSync(top_level->display, 0);
4082 int BC_WindowBase::set_w(int w)
4088 int BC_WindowBase::set_h(int h)
4094 int BC_WindowBase::load_defaults(BC_Hash *defaults)
4096 BC_Resources *resources = get_resources();
4097 char string[BCTEXTLEN];
4098 int newest_id = - 1;
4099 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
4101 sprintf(string, "FILEBOX_HISTORY_PATH%d", i);
4102 resources->filebox_history[i].path[0] = 0;
4103 defaults->get(string, resources->filebox_history[i].path);
4104 sprintf(string, "FILEBOX_HISTORY_ID%d", i);
4105 resources->filebox_history[i].id = defaults->get(string, resources->get_id());
4106 if(resources->filebox_history[i].id > newest_id)
4107 newest_id = resources->filebox_history[i].id;
4110 resources->filebox_id = newest_id + 1;
4111 resources->filebox_mode = defaults->get("FILEBOX_MODE", get_resources()->filebox_mode);
4112 resources->filebox_w = defaults->get("FILEBOX_W", get_resources()->filebox_w);
4113 resources->filebox_h = defaults->get("FILEBOX_H", get_resources()->filebox_h);
4114 resources->filebox_columntype[0] = defaults->get("FILEBOX_TYPE0", resources->filebox_columntype[0]);
4115 resources->filebox_columntype[1] = defaults->get("FILEBOX_TYPE1", resources->filebox_columntype[1]);
4116 resources->filebox_columntype[2] = defaults->get("FILEBOX_TYPE2", resources->filebox_columntype[2]);
4117 resources->filebox_columntype[3] = defaults->get("FILEBOX_TYPE3", resources->filebox_columntype[3]);
4118 resources->filebox_columnwidth[0] = defaults->get("FILEBOX_WIDTH0", resources->filebox_columnwidth[0]);
4119 resources->filebox_columnwidth[1] = defaults->get("FILEBOX_WIDTH1", resources->filebox_columnwidth[1]);
4120 resources->filebox_columnwidth[2] = defaults->get("FILEBOX_WIDTH2", resources->filebox_columnwidth[2]);
4121 resources->filebox_columnwidth[3] = defaults->get("FILEBOX_WIDTH3", resources->filebox_columnwidth[3]);
4122 defaults->get("FILEBOX_FILTER", resources->filebox_filter);
4126 int BC_WindowBase::save_defaults(BC_Hash *defaults)
4128 BC_Resources *resources = get_resources();
4129 char string[BCTEXTLEN];
4130 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
4132 sprintf(string, "FILEBOX_HISTORY_PATH%d", i);
4133 defaults->update(string, resources->filebox_history[i].path);
4134 sprintf(string, "FILEBOX_HISTORY_ID%d", i);
4135 defaults->update(string, resources->filebox_history[i].id);
4137 defaults->update("FILEBOX_MODE", resources->filebox_mode);
4138 defaults->update("FILEBOX_W", resources->filebox_w);
4139 defaults->update("FILEBOX_H", resources->filebox_h);
4140 defaults->update("FILEBOX_TYPE0", resources->filebox_columntype[0]);
4141 defaults->update("FILEBOX_TYPE1", resources->filebox_columntype[1]);
4142 defaults->update("FILEBOX_TYPE2", resources->filebox_columntype[2]);
4143 defaults->update("FILEBOX_TYPE3", resources->filebox_columntype[3]);
4144 defaults->update("FILEBOX_WIDTH0", resources->filebox_columnwidth[0]);
4145 defaults->update("FILEBOX_WIDTH1", resources->filebox_columnwidth[1]);
4146 defaults->update("FILEBOX_WIDTH2", resources->filebox_columnwidth[2]);
4147 defaults->update("FILEBOX_WIDTH3", resources->filebox_columnwidth[3]);
4148 defaults->update("FILEBOX_FILTER", resources->filebox_filter);
4154 // For some reason XTranslateCoordinates can take a long time to return.
4155 // We work around this by only calling it when the event windows are different.
4156 void BC_WindowBase::translate_coordinates(Window src_w,
4168 *dest_x_return = src_x;
4169 *dest_y_return = src_y;
4173 XTranslateCoordinates(top_level->display,
4181 //printf("BC_WindowBase::translate_coordinates 1 %lld\n", timer.get_difference());
4191 #ifdef HAVE_LIBXXF86VM
4192 void BC_WindowBase::closest_vm(int *vm, int *width, int *height)
4196 if(XF86VidModeQueryExtension(top_level->display,&foo,&bar)) {
4198 XF86VidModeModeInfo **vm_modelines;
4199 XF86VidModeGetAllModeLines(top_level->display,XDefaultScreen(top_level->display),&vm_count,&vm_modelines);
4200 for (i = 0; i < vm_count; i++) {
4201 if (vm_modelines[i]->hdisplay < vm_modelines[*vm]->hdisplay && vm_modelines[i]->hdisplay >= *width)
4204 display = top_level->display;
4205 if (vm_modelines[*vm]->hdisplay == *width)
4209 *width = vm_modelines[*vm]->hdisplay;
4210 *height = vm_modelines[*vm]->vdisplay;
4215 void BC_WindowBase::scale_vm(int vm)
4217 int foo,bar,dotclock;
4218 if(XF86VidModeQueryExtension(top_level->display,&foo,&bar))
4221 XF86VidModeModeInfo **vm_modelines;
4222 XF86VidModeModeLine vml;
4223 XF86VidModeGetAllModeLines(top_level->display,XDefaultScreen(top_level->display),&vm_count,&vm_modelines);
4224 XF86VidModeGetModeLine(top_level->display,XDefaultScreen(top_level->display),&dotclock,&vml);
4225 orig_modeline.dotclock = dotclock;
4226 orig_modeline.hdisplay = vml.hdisplay;
4227 orig_modeline.hsyncstart = vml.hsyncstart;
4228 orig_modeline.hsyncend = vml.hsyncend;
4229 orig_modeline.htotal = vml.htotal;
4230 orig_modeline.vdisplay = vml.vdisplay;
4231 orig_modeline.vsyncstart = vml.vsyncstart;
4232 orig_modeline.vsyncend = vml.vsyncend;
4233 orig_modeline.vtotal = vml.vtotal;
4234 orig_modeline.flags = vml.flags;
4235 orig_modeline.privsize = vml.privsize;
4236 // orig_modeline.private = vml.private;
4237 XF86VidModeSwitchToMode(top_level->display,XDefaultScreen(top_level->display),vm_modelines[vm]);
4238 XF86VidModeSetViewPort(top_level->display,XDefaultScreen(top_level->display),0,0);
4239 XFlush(top_level->display);
4243 void BC_WindowBase::restore_vm()
4245 XF86VidModeSwitchToMode(top_level->display,XDefaultScreen(top_level->display),&orig_modeline);
4246 XFlush(top_level->display);
4269 #ifndef SINGLE_THREAD
4270 int BC_WindowBase::get_event_count()
4272 event_lock->lock("BC_WindowBase::get_event_count");
4273 int result = common_events.total;
4274 event_lock->unlock();
4278 XEvent* BC_WindowBase::get_event()
4281 while(!done && !result)
4283 event_condition->lock("BC_WindowBase::get_event");
4284 event_lock->lock("BC_WindowBase::get_event");
4286 if(common_events.total && !done)
4288 result = common_events.values[0];
4289 common_events.remove_number(0);
4292 event_lock->unlock();
4297 void BC_WindowBase::put_event(XEvent *event)
4299 event_lock->lock("BC_WindowBase::put_event");
4300 common_events.append(event);
4301 event_lock->unlock();
4302 event_condition->unlock();
4305 #endif // SINGLE_THREAD
4307 int BC_WindowBase::get_id()
4313 BC_Pixmap *BC_WindowBase::create_pixmap(VFrame *vframe)
4315 int w = vframe->get_w(), h = vframe->get_h();
4316 BC_Pixmap *icon = new BC_Pixmap(this, w, h);
4317 icon->draw_vframe(vframe, 0,0, w,h, 0,0);