X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1950b38c35e4bed8cd2660d2178036b1b9e1b9bf..c9f8e0e22e0cb2a82233e9076da7414315df062d:/src/gtk/utilsgtk.cpp diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 2befc47dc3..331b2e9cea 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -30,6 +30,11 @@ #include #include +#include +#include +#include + +#include "gdk/gdkx.h" // GDK_DISPLAY #ifdef __SVR4__ #include @@ -50,42 +55,45 @@ extern "C" void wxBell(void) { - gdk_beep(); -}; + gdk_beep(); +} void wxSleep(int nSecs) { - sleep(nSecs); -}; + sleep(nSecs); +} int wxKill(long pid, int sig) { - return kill(pid, sig); -}; + return kill(pid, sig); +} void wxDisplaySize( int *width, int *height ) { - if (width) *width = gdk_screen_width(); - if (height) *height = gdk_screen_height(); + if (width) *width = gdk_screen_width(); + if (height) *height = gdk_screen_height(); } void wxGetMousePosition( int* x, int* y ) { - wxFAIL_MSG( "GetMousePosition not yet implemented" ); - if (x) *x = 0; - if (y) *y = 0; -}; + Window dumw; + int dumi; + unsigned int dumu; + + XQueryPointer( GDK_DISPLAY(),GDK_ROOT_WINDOW(), + &dumw,&dumw,x,y,&dumi,&dumi,&dumu ); +} bool wxColourDisplay(void) { - wxFAIL_MSG( "wxColourDisplay always returns TRUE" ); - return TRUE; + wxFAIL_MSG( "wxColourDisplay always returns TRUE" ); + return TRUE; } int wxDisplayDepth(void) { - wxFAIL_MSG( "wxDisplayDepth always returns 8" ); - return 8; + wxFAIL_MSG( "wxDisplayDepth always returns 8" ); + return 8; } //------------------------------------------------------------------------ @@ -94,34 +102,40 @@ int wxDisplayDepth(void) const char* wxGetHomeDir( wxString *home ) { - *home = wxGetUserHome( wxString() ); - if (home->IsNull()) *home = "/"; - return *home; -}; + *home = wxGetUserHome( wxString() ); + if (home->IsNull()) *home = "/"; + return *home; +} char *wxGetUserHome( const wxString &user ) { - struct passwd *who = (struct passwd *) NULL; + struct passwd *who = (struct passwd *) NULL; - if (user.IsNull() || (user== "")) - { + if (user.IsNull() || (user== "")) + { register char *ptr; if ((ptr = getenv("HOME")) != NULL) + { return ptr; - if ((ptr = getenv("USER")) != NULL - || (ptr = getenv("LOGNAME")) != NULL) { + } + if ((ptr = getenv("USER")) != NULL || (ptr = getenv("LOGNAME")) != NULL) + { who = getpwnam(ptr); } // We now make sure the the user exists! if (who == NULL) + { who = getpwuid(getuid()); - } - else - who = getpwnam (user); + } + } + else + { + who = getpwnam (user); + } - return who ? who->pw_dir : (char*)NULL; -}; + return who ? who->pw_dir : (char*)NULL; +} //------------------------------------------------------------------------ // id routines @@ -147,15 +161,15 @@ bool wxGetHostName(char *buf, int sz) // strncpy(buf, (h=gethostbyname(name))!=NULL ? h->h_name : name, sz-1); if((unsigned)sz > strlen(name)+strlen(domain)+1) { - strcpy(buf, name); - if(strcmp(domain,"(none)") == 0) // standalone machine - { - strcat(buf,"."); - strcat(buf,domain); - } + strcpy(buf, name); + if(strcmp(domain,"(none)") == 0) // standalone machine + { + strcat(buf,"."); + strcat(buf,domain); + } } else - return FALSE; + return FALSE; return TRUE; #endif } @@ -198,7 +212,7 @@ void wxDebugMsg( const char *format, ... ) vfprintf( stderr, format, ap ); fflush( stderr ); va_end(ap); -}; +} void wxError( const wxString &msg, const wxString &title ) { @@ -206,7 +220,7 @@ void wxError( const wxString &msg, const wxString &title ) if (!title.IsNull()) fprintf( stderr, "%s ", WXSTRINGCAST(title) ); if (!msg.IsNull()) fprintf( stderr, ": %s", WXSTRINGCAST(msg) ); fprintf( stderr, ".\n" ); -}; +} void wxFatalError( const wxString &msg, const wxString &title ) { @@ -215,7 +229,7 @@ void wxFatalError( const wxString &msg, const wxString &title ) if (!msg.IsNull()) fprintf( stderr, ": %s", WXSTRINGCAST(msg) ); fprintf( stderr, ".\n" ); exit(3); // the same exit code as for abort() -}; +} //------------------------------------------------------------------------ // directory routines @@ -223,11 +237,11 @@ void wxFatalError( const wxString &msg, const wxString &title ) bool wxDirExists( const wxString& dir ) { - char buf[500]; - strcpy( buf, WXSTRINGCAST(dir) ); - struct stat sbuf; - return ((stat(buf, &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE); -}; + char buf[500]; + strcpy( buf, WXSTRINGCAST(dir) ); + struct stat sbuf; + return ((stat(buf, &sbuf) != -1) && S_ISDIR(sbuf.st_mode) ? TRUE : FALSE); +} //------------------------------------------------------------------------ // subprocess routines @@ -266,7 +280,7 @@ static void GTK_EndProcessDetector(gpointer data, gint source, delete proc_data; else proc_data->pid = 0; -}; +} long wxExecute( char **argv, bool sync, wxProcess *process ) { @@ -295,6 +309,14 @@ long wxExecute( char **argv, bool sync, wxProcess *process ) else if (pid == 0) { // we're in child close(end_proc_detect[0]); // close reading side + // These three lines close the open file descriptors to + // to avoid any input/output which might block the process + // or irritate the user. If one wants proper IO for the sub- + // process, the "right thing to do" is to start an xterm executing + // it. + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); #ifdef _AIX execvp ((const char *)*argv, (const char **)argv); @@ -329,7 +351,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process ) // failed! return pid; } -}; +} long wxExecute( const wxString& command, bool sync, wxProcess *process ) { @@ -351,4 +373,4 @@ long wxExecute( const wxString& command, bool sync, wxProcess *process ) delete [] tmp; return lRc; -}; +}