X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbcwindowbase.C;h=f9eb98f20b18ee5d22609326afcc0382f7283125;hp=ec7507683bf04eef3136f014b3e88f169b4564b1;hb=2540fb803c017aefc97be227d8f910507787f366;hpb=b5c58822be78c8820692c916e296a2230bb2b9e2 diff --git a/cinelerra-5.1/guicast/bcwindowbase.C b/cinelerra-5.1/guicast/bcwindowbase.C index ec750768..f9eb98f2 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.C +++ b/cinelerra-5.1/guicast/bcwindowbase.C @@ -36,7 +36,7 @@ #include "bcwindowbase.h" #include "bcwindowevents.h" #include "bccmodels.h" -#include "colors.h" +#include "bccolors.h" #include "condition.h" #include "cursors.h" #include "bchash.h" @@ -85,9 +85,8 @@ Window XGroupLeader = 0; Mutex BC_KeyboardHandlerLock::keyboard_listener_mutex("keyboard_listener",0); ArrayList BC_KeyboardHandler::listeners; -BC_WindowBase::BC_WindowBase(int opts) +BC_WindowBase::BC_WindowBase() { - this->options = opts; //printf("BC_WindowBase::BC_WindowBase 1\n"); BC_WindowBase::initialize(); } @@ -147,13 +146,13 @@ BC_WindowBase::~BC_WindowBase() delete pixmap; +//printf("delete glx=%08x, win=%08x %s\n", (unsigned)glx_win, (unsigned)win, title); #ifdef HAVE_GL - if( get_resources()->get_synchronous() && - (top_level->options & GLX_WINDOW) && glx_win != 0 ) + if( get_resources()->get_synchronous() && glx_win != 0 ) { get_resources()->get_synchronous()->delete_window(this); - else + } #endif - XDestroyWindow(top_level->display, win); + XDestroyWindow(top_level->display, win); if(bg_pixmap && !shared_bg_pixmap) delete bg_pixmap; if(icon_pixmap) delete icon_pixmap; @@ -177,6 +176,7 @@ BC_WindowBase::~BC_WindowBase() &BC_WindowBase::mediumfont, &BC_WindowBase::largefont, &BC_WindowBase::bigfont, + &BC_WindowBase::clockfont, }; for( int i=sizeof(xfont)/sizeof(xfont[0]); --i>=0; ) XFreeFont(display, this->*xfont[i]); @@ -193,6 +193,7 @@ BC_WindowBase::~BC_WindowBase() &BC_WindowBase::bold_smallfont_xft, &BC_WindowBase::bold_mediumfont_xft, &BC_WindowBase::bold_largefont_xft, + &BC_WindowBase::clockfont_xft, }; for( int i=sizeof(xft_font)/sizeof(xft_font[0]); --i>=0; ) { XftFont *xft = (XftFont *)(this->*xft_font[i]); @@ -211,23 +212,15 @@ BC_WindowBase::~BC_WindowBase() XvUngrabPort(display, xvideo_port_id, CurrentTime); unlock_window(); -// Can't close display if another thread is waiting for events. -// Synchronous thread must delete display it owns a GLX_WINDOW // Must be last reference to display. -#ifndef SINGLE_THREAD -#ifdef HAVE_GL - if( (options & GLX_DISPLAY) != 0 && get_resources()->get_synchronous() ) { - printf(_("BC_WindowBase::~BC_WindowBase window deleted but opengl deletion is not\n" - "implemented for BC_Pixmap.\n")); - get_resources()->get_synchronous()->delete_display(this); - } - else -#endif - XCloseDisplay(display); +// _XftDisplayInfo needs a lock. + get_resources()->create_window_lock->lock("BC_WindowBase::~BC_WindowBase"); + XCloseDisplay(display); + get_resources()->create_window_lock->unlock(); + // clipboard uses a different display connection clipboard->stop_clipboard(); delete clipboard; -#endif // SINGLE_THREAD } resize_history.remove_all_objects(); @@ -326,16 +319,24 @@ int BC_WindowBase::initialize() #ifdef HAVE_LIBXXF86VM vm_switched = 0; #endif - smallfont_xft = 0; - bold_largefont_xft = 0; - bold_mediumfont_xft = 0; - bold_smallfont_xft = 0; input_method = 0; input_context = 0; + smallfont = 0; + mediumfont = 0; + largefont = 0; + bigfont = 0; + clockfont = 0; + + smallfont_xft = 0; mediumfont_xft = 0; largefont_xft = 0; bigfont_xft = 0; + clockfont_xft = 0; + + bold_smallfont_xft = 0; + bold_mediumfont_xft = 0; + bold_largefont_xft = 0; #ifdef SINGLE_THREAD completion_lock = new Condition(0, "BC_WindowBase::completion_lock"); #else @@ -372,22 +373,10 @@ int BC_WindowBase::initialize() FocusChangeMask -int BC_WindowBase::create_window(BC_WindowBase *parent_window, - const char *title, - int x, - int y, - int w, - int h, - int minw, - int minh, - int allow_resize, - int private_color, - int hide, - int bg_color, - const char *display_name, - int window_type, - BC_Pixmap *bg_pixmap, - int group_it) +int BC_WindowBase::create_window(BC_WindowBase *parent_window, const char *title, + int x, int y, int w, int h, int minw, int minh, int allow_resize, + int private_color, int hide, int bg_color, const char *display_name, + int window_type, BC_Pixmap *bg_pixmap, int group_it) { XSetWindowAttributes attr; unsigned long mask; @@ -428,7 +417,7 @@ int BC_WindowBase::create_window(BC_WindowBase *parent_window, else this->display_name[0] = 0; - put_title(_(title)); + put_title(title); if(bg_pixmap) shared_bg_pixmap = 1; subwindows = new BC_SubWindowList; @@ -1030,6 +1019,10 @@ locking_message = event->xclient.message_type; break; case ButtonPress: + if(motion_events) + { + dispatch_motion_event(); + } get_key_masks(event->xbutton.state); cursor_x = event->xbutton.x; cursor_y = event->xbutton.y; @@ -1074,6 +1067,10 @@ locking_message = event->xclient.message_type; break; case ButtonRelease: + if(motion_events) + { + dispatch_motion_event(); + } get_key_masks(event->xbutton.state); button_number = event->xbutton.button; event_win = event->xany.window; @@ -1811,7 +1808,7 @@ int BC_WindowBase::show_tooltip(const char *text, int x, int y, int w, int h) if( wy >= (y1-=h) ) wy = y1; // avoid tip under cursor (flickers) int abs_x, abs_y; - get_abs_cursor_xy(abs_x,abs_y, 0); + get_abs_cursor(abs_x,abs_y, 0); if( wx < abs_x && abs_x < wx+w && wy < abs_y && abs_y < wy+h ) { if( wx-abs_x < wy-abs_y ) wx = abs_x+1; @@ -2298,6 +2295,10 @@ int BC_WindowBase::init_fonts() if( !(bigfont = XLoadQueryFont(display, _(resources.big_font2))) ) bigfont = XLoadQueryFont(display, "fixed"); + if((clockfont = XLoadQueryFont(display, _(resources.clock_font))) == NULL) + if((clockfont = XLoadQueryFont(display, _(resources.clock_font2))) == NULL) + clockfont = XLoadQueryFont(display, "fixed"); + init_xft(); if(get_resources()->use_fontset) { @@ -2316,8 +2317,11 @@ int BC_WindowBase::init_fonts() largefontset = XCreateFontSet(display, "fixed,*", &m, &n, &d); bigfontset = XCreateFontSet(display, resources.big_fontset, &m, &n, &d); if( !bigfontset ) - largefontset = XCreateFontSet(display, "fixed,*", &m, &n, &d); - if(bigfontset && largefontset && mediumfontset && smallfontset) { + bigfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d); + clockfontset = XCreateFontSet(display, resources.clock_fontset, &m, &n, &d); + if( !clockfontset ) + clockfontset = XCreateFontSet(display, "fixed,*", &m, &n, &d); + if(clockfontset && bigfontset && largefontset && mediumfontset && smallfontset) { curr_fontset = mediumfontset; get_resources()->use_fontset = 1; } @@ -2334,6 +2338,9 @@ void BC_WindowBase::init_xft() { #ifdef HAVE_XFT if( !get_resources()->use_xft ) return; +// apparently, xft is not reentrant, more than this is needed +static Mutex xft_init_lock("BC_WindowBase::xft_init_lock", 0); +xft_init_lock.lock("BC_WindowBase::init_xft"); if(!(smallfont_xft = (resources.small_font_xft[0] == '-' ? XftFontOpenXlfd(display, screen, resources.small_font_xft) : @@ -2362,6 +2369,12 @@ void BC_WindowBase::init_xft() if(!(bigfont_xft = XftFontOpenXlfd(display, screen, resources.big_font_xft2))) bigfont_xft = XftFontOpenXlfd(display, screen, "fixed"); + if(!(clockfont_xft = + (resources.clock_font_xft[0] == '-' ? + XftFontOpenXlfd(display, screen, resources.clock_font_xft) : + XftFontOpenName(display, screen, resources.clock_font_xft))) ) + clockfont_xft = XftFontOpenXlfd(display, screen, "fixed"); + if(!(bold_smallfont_xft = (resources.small_b_font_xft[0] == '-' ? @@ -2379,21 +2392,25 @@ void BC_WindowBase::init_xft() XftFontOpenName(display, screen, resources.large_b_font_xft))) ) bold_largefont_xft = XftFontOpenXlfd(display, screen, "fixed"); -// Extension failed to locate fonts if( !smallfont_xft || !mediumfont_xft || !largefont_xft || !bigfont_xft || - !bold_largefont_xft || !bold_mediumfont_xft || !bold_largefont_xft ) { + !bold_largefont_xft || !bold_mediumfont_xft || !bold_largefont_xft || + !clockfont_xft ) { printf("BC_WindowBase::init_fonts: no xft fonts found:" - " %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n", + " %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n %s=%p\n", resources.small_font_xft, smallfont_xft, resources.medium_font_xft, mediumfont_xft, resources.large_font_xft, largefont_xft, resources.big_font_xft, bigfont_xft, + resources.clock_font_xft, clockfont_xft, resources.small_b_font_xft, bold_smallfont_xft, resources.medium_b_font_xft, bold_mediumfont_xft, resources.large_b_font_xft, bold_largefont_xft); get_resources()->use_xft = 0; exit(1); } +// _XftDisplayInfo needs a lock. + XftDefaultHasRender(display); +xft_init_lock.unlock(); #endif // HAVE_XFT } @@ -2744,6 +2761,7 @@ XFontStruct* BC_WindowBase::get_font_struct(int font) case MEDIUMFONT: return top_level->mediumfont; break; case LARGEFONT: return top_level->largefont; break; case BIGFONT: return top_level->bigfont; break; + case CLOCKFONT: return top_level->clockfont; break; } return 0; } @@ -2759,6 +2777,7 @@ XFontSet BC_WindowBase::get_fontset(int font) case MEDIUMFONT: fs = top_level->mediumfontset; break; case LARGEFONT: fs = top_level->largefontset; break; case BIGFONT: fs = top_level->bigfontset; break; + case CLOCKFONT: fs = top_level->clockfontset; break; } } @@ -2773,6 +2792,7 @@ XftFont* BC_WindowBase::get_xft_struct(int font) case MEDIUMFONT: return (XftFont*)top_level->mediumfont_xft; case LARGEFONT: return (XftFont*)top_level->largefont_xft; case BIGFONT: return (XftFont*)top_level->bigfont_xft; + case CLOCKFONT: return (XftFont*)top_level->clockfont_xft; case MEDIUMFONT_3D: return (XftFont*)top_level->bold_mediumfont_xft; case SMALLFONT_3D: return (XftFont*)top_level->bold_smallfont_xft; case LARGEFONT_3D: return (XftFont*)top_level->bold_largefont_xft; @@ -2783,13 +2803,6 @@ XftFont* BC_WindowBase::get_xft_struct(int font) #endif - - - - - - - int BC_WindowBase::get_current_font() { return top_level->current_font; @@ -2825,6 +2838,7 @@ void BC_WindowBase::set_fontset(int font) case MEDIUMFONT: fs = top_level->mediumfontset; break; case LARGEFONT: fs = top_level->largefontset; break; case BIGFONT: fs = top_level->bigfontset; break; + case CLOCKFONT: fs = top_level->clockfontset; break; } } @@ -3347,6 +3361,14 @@ int BC_WindowBase::ungrab(BC_WindowBase *window) this->grab_active = 0; return 1; } +int BC_WindowBase::grab_event_count() +{ + int result = 0; +#ifndef SINGLE_THREAD + result = grab_active->get_event_count(); +#endif + return result; +} int BC_WindowBase::grab_buttons() { XSync(top_level->display, False); @@ -3409,6 +3431,8 @@ BC_WindowBase::get_xinerama_info(int screen) return 0; } int top_x = get_x(), top_y = get_y(); + if( BC_DisplayInfo::left_border >= 0 ) top_x += BC_DisplayInfo::left_border; + if( BC_DisplayInfo::top_border >= 0 ) top_y += BC_DisplayInfo::top_border; for( int i=0; i= xinerama_info[i].height ) continue; @@ -3726,13 +3750,13 @@ int BC_WindowBase::dispatch_selection_clear() } -void BC_WindowBase::get_relative_cursor_xy(int &x, int &y, int lock_window) +void BC_WindowBase::get_relative_cursor(int &x, int &y, int lock_window) { int abs_x, abs_y, win_x, win_y; unsigned int temp_mask; Window temp_win; - if(lock_window) this->lock_window("BC_WindowBase::get_relative_cursor_xy"); + if(lock_window) this->lock_window("BC_WindowBase::get_relative_cursor"); XQueryPointer(top_level->display, top_level->win, &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y, &temp_mask); @@ -3744,23 +3768,23 @@ void BC_WindowBase::get_relative_cursor_xy(int &x, int &y, int lock_window) int BC_WindowBase::get_relative_cursor_x(int lock_window) { int x, y; - get_relative_cursor_xy(x, y, lock_window); + get_relative_cursor(x, y, lock_window); return x; } int BC_WindowBase::get_relative_cursor_y(int lock_window) { int x, y; - get_relative_cursor_xy(x, y, lock_window); + get_relative_cursor(x, y, lock_window); return y; } -void BC_WindowBase::get_abs_cursor_xy(int &abs_x, int &abs_y, int lock_window) +void BC_WindowBase::get_abs_cursor(int &abs_x, int &abs_y, int lock_window) { int win_x, win_y; unsigned int temp_mask; Window temp_win; - if(lock_window) this->lock_window("BC_WindowBase::get_abs_cursor_xy"); + if(lock_window) this->lock_window("BC_WindowBase::get_abs_cursor"); XQueryPointer(top_level->display, top_level->win, &temp_win, &temp_win, &abs_x, &abs_y, &win_x, &win_y, &temp_mask); @@ -3769,20 +3793,20 @@ void BC_WindowBase::get_abs_cursor_xy(int &abs_x, int &abs_y, int lock_window) int BC_WindowBase::get_abs_cursor_x(int lock_window) { int abs_x, abs_y; - get_abs_cursor_xy(abs_x, abs_y, lock_window); + get_abs_cursor(abs_x, abs_y, lock_window); return abs_x; } int BC_WindowBase::get_abs_cursor_y(int lock_window) { int abs_x, abs_y; - get_abs_cursor_xy(abs_x, abs_y, lock_window); + get_abs_cursor(abs_x, abs_y, lock_window); return abs_y; } -void BC_WindowBase::get_pop_cursor_xy(int &px, int &py, int lock_window) +void BC_WindowBase::get_pop_cursor(int &px, int &py, int lock_window) { int margin = 100; - get_abs_cursor_xy(px, py, lock_window); + get_abs_cursor(px, py, lock_window); if( px < margin ) px = margin; if( py < margin ) py = margin; int wd = get_screen_w(lock_window,-1) - margin; @@ -3793,13 +3817,13 @@ void BC_WindowBase::get_pop_cursor_xy(int &px, int &py, int lock_window) int BC_WindowBase::get_pop_cursor_x(int lock_window) { int px, py; - get_pop_cursor_xy(px, py, lock_window); + get_pop_cursor(px, py, lock_window); return px; } int BC_WindowBase::get_pop_cursor_y(int lock_window) { int px, py; - get_pop_cursor_xy(px, py, lock_window); + get_pop_cursor(px, py, lock_window); return py; } @@ -3817,27 +3841,34 @@ int BC_WindowBase::match_window(Window win) int BC_WindowBase::get_cursor_over_window() { - if(top_level != this) return top_level->get_cursor_over_window(); - int abs_x, abs_y, win_x, win_y; - unsigned int temp_mask; + unsigned int mask_return; Window root_return, child_return; - int ret = XQueryPointer(display, win, + int ret = XQueryPointer(top_level->display, top_level->rootwin, &root_return, &child_return, &abs_x, &abs_y, - &win_x, &win_y, &temp_mask); -//printf("BC_WindowBase::get_cursor_over_window %d %s 0x%x %d 0x%x\n", -// __LINE__, title, win, ret, child_return); - - int result = !ret || child_return == None ? 0 : - match_window(child_return); - return result; + &win_x, &win_y, &mask_return); + if( ret && child_return == None ) ret = 0; + if( ret && win != child_return ) + ret = top_level->match_window(child_return); +// query pointer can return a window manager window with this top_level as a child +// for kde this can be two levels deep + unsigned int nchildren_return = 0; + Window parent_return, *children_return = 0; + Window top_win = top_level->win; + while( !ret && top_win != top_level->rootwin && top_win != root_return && + XQueryTree(top_level->display, top_win, &root_return, + &parent_return, &children_return, &nchildren_return) ) { + if( children_return ) XFree(children_return); + if( (top_win=parent_return) == child_return ) ret = 1; + } + return ret; } int BC_WindowBase::cursor_above() { int rx, ry; - get_relative_cursor_xy(rx, ry); + get_relative_cursor(rx, ry); return rx < 0 || rx >= get_w() || ry < 0 || ry >= get_h() ? 0 : 1; } @@ -4124,7 +4155,7 @@ void BC_WindowBase::put_title(const char *text) void BC_WindowBase::set_title(const char *text, int utf8) { // utf8>0: wm + net_wm, utf8=0: wm only, utf<0: net_wm only - put_title(_(text)); + put_title(text); const unsigned char *wm_title = (const unsigned char *)title; int title_len = strlen((const char *)title); if( utf8 >= 0 ) { @@ -4234,6 +4265,7 @@ int BC_WindowBase::load_defaults(BC_Hash *defaults) resources->filebox_columnwidth[1] = defaults->get("FILEBOX_WIDTH1", resources->filebox_columnwidth[1]); resources->filebox_columnwidth[2] = defaults->get("FILEBOX_WIDTH2", resources->filebox_columnwidth[2]); resources->filebox_columnwidth[3] = defaults->get("FILEBOX_WIDTH3", resources->filebox_columnwidth[3]); + resources->filebox_size_format = defaults->get("FILEBOX_SIZE_FORMAT", get_resources()->filebox_size_format); defaults->get("FILEBOX_FILTER", resources->filebox_filter); return 0; } @@ -4261,6 +4293,7 @@ int BC_WindowBase::save_defaults(BC_Hash *defaults) defaults->update("FILEBOX_WIDTH2", resources->filebox_columnwidth[2]); defaults->update("FILEBOX_WIDTH3", resources->filebox_columnwidth[3]); defaults->update("FILEBOX_FILTER", resources->filebox_filter); + defaults->update("FILEBOX_SIZE_FORMAT", get_resources()->filebox_size_format); return 0; }