26 #define VERBOSE_COMM 0 // VERY verbose thread communication logging
38 #define YUILogComponent "ui"
42 #include "YUILoader.h"
43 #include "YUISymbols.h"
45 #include "YApplication.h"
47 #include "YButtonBox.h"
49 #include "YBuiltinCaller.h"
55 #define ENV_BUTTON_ORDER "Y2_BUTTON_ORDER"
64 static bool uiDeleted =
false;
66 extern void * start_ui_thread(
void * yui );
70 : _withThreads( withThreads )
73 , _terminate_ui_thread( false )
74 , _eventsBlocked( false )
76 yuiMilestone() <<
"This is libyui " << VERSION << std::endl;
77 yuiMilestone() <<
"Creating UI " << ( withThreads ?
"with" :
"without" ) <<
" threads" << endl;
88 yuiError() <<
"shutdownThreads() was never called!" << endl;
89 yuiError() <<
"shutting down now - this might segfault" << endl;
135 YUI_CHECK_PTR( factory );
150 YUI_CHECK_PTR( factory );
165 YUI_CHECK_PTR( app );
204 if ( fcntl(
pipe_to_ui[0], F_SETFL, arg | O_NONBLOCK ) < 0 )
206 yuiError() <<
"Couldn't set O_NONBLOCK: errno: " << errno <<
" " << strerror( errno ) << endl;
216 yuiDebug() <<
"Inter-thread communication pipes set up" << endl;
224 yuiError() <<
"pipe() failed: errno: " << errno <<
" " << strerror( errno ) << endl;
230 yuiMilestone() <<
"Running without threads" << endl;
238 pthread_attr_init( & attr );
239 int ret = pthread_create( &
_uiThread, & attr, start_ui_thread,
this );
242 yuiError() <<
"pthread_create() failed: " << errno <<
" " << strerror( errno ) << endl;
248 yuiDebug() <<
"Sending shutdown message to UI thread" << endl;
255 yuiDebug() <<
"UI thread shut down correctly" << endl;
275 static char arbitrary = 42;
276 if ( write (
pipe_to_ui[1], & arbitrary, 1 ) == -1 )
277 yuiError() <<
"Writing byte to UI thread failed" << endl;
280 yuiDebug() <<
"Wrote byte to UI thread" << endl;
292 yuiDebug() <<
"Waiting for ui thread..." << endl;
297 if ( errno == EINTR || errno == EAGAIN )
300 yuiError() <<
"waitForUIThread: errno: " << errno <<
" " << strerror( errno ) << endl;
302 }
while ( result == 0 );
305 yuiDebug() <<
"Read byte from ui thread" << endl;
315 static char arbitrary;
317 yuiError() <<
"Writing byte to YCP thread failed" << endl;
320 yuiDebug() <<
"Wrote byte to YCP thread" << endl;
332 yuiDebug() <<
"Waiting for YCP thread..." << endl;
334 result = read(
pipe_to_ui[0], & arbitrary, 1 );
337 if ( errno == EINTR || errno == EAGAIN )
340 yuiError() <<
"waitForYCPThread: errno: " << errno <<
" " << strerror( errno ) << endl;
342 }
while ( result == 0 );
345 yuiDebug() <<
"Read byte from YCP thread" << endl;
372 yuiDebug() <<
"Shutting down UI main loop" << endl;
379 yuiError() <<
"No builtinCaller set" << endl;
389 YButtonOrder oldButtonOrder = buttonOrder;
397 YEnvVar env(
"DESKTOP_SESSION" );
398 yuiDebug() << env << endl;
403 buttonOrder = YKDEButtonOrder;
406 else if ( env ==
"gnome" )
408 buttonOrder = YGnomeButtonOrder;
416 env =
YEnvVar(
"WINDOWMANAGER" );
417 yuiDebug() << env << endl;
421 buttonOrder = YGnomeButtonOrder;
426 buttonOrder = YKDEButtonOrder;
435 env =
YEnvVar( ENV_BUTTON_ORDER );
436 yuiDebug() << env << endl;
438 if ( env ==
"gnome" )
440 buttonOrder = YGnomeButtonOrder;
443 else if ( env ==
"kde" )
445 buttonOrder = YKDEButtonOrder;
448 else if ( ! env.
value().empty() )
450 yuiWarning() <<
"Ignoring unknown value of " << env << endl;
454 if ( buttonOrder != oldButtonOrder )
456 std::string buttonOrderStr;
458 switch ( buttonOrder )
460 case YKDEButtonOrder:
461 buttonOrderStr =
"KDE";
465 case YGnomeButtonOrder:
466 buttonOrderStr =
"GNOME";
473 yuiMilestone() <<
"Switching to " << buttonOrderStr
474 <<
" button order because of " << lastEnv
484 void * start_ui_thread(
void * yui )
489 yuiDebug() <<
"Starting UI thread" << endl;
525 yuiMilestone() <<
"Shutting down UI" << endl;
void setButtonOrderFromEnvironment()
static YWidgetFactory * widgetFactory()
virtual YApplication * createApplication()=0
void topmostConstructorHasFinished()
static void deletePlayer()
static void ensureUICreated()
virtual YOptionalWidgetFactory * createOptionalWidgetFactory()=0
virtual void uiThreadDestructor()
static void deleteAllDialogs()
static YOptionalWidgetFactory * optionalWidgetFactory()
std::string value() const
static int openDialogsCount()
static YApplication * app()
virtual YWidgetFactory * createWidgetFactory()=0
bool _terminate_ui_thread
virtual void idleLoop(int fd_ycp)=0
static void loadUI(bool withThreads=false)
static void deleteRecorder()
static std::stack< YDialog * > _dialogStack
YBuiltinCaller * _builtinCaller
bool contains(const std::string &str, bool caseSensitive=false) const