Changeset 20880

Show
Ignore:
Timestamp:
10/11/07 11:46:13 (1 year ago)
Author:
patrick
Message:

Implement gadget::InputWindowXWin::setHints() using C++ features.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/gadgeteer/gadget/Devices/KeyboardMouseDevice/InputWindowXWin.cpp

    r20879 r20880  
    339339   createEmptyCursor(mXDisplay, mXWindow); 
    340340 
    341    setHints(mXWindow, const_cast<char*>(mInstName.c_str())
    342             const_cast<char*>(mInstName.c_str()) , "VRJInputWindow", "VRJ Input Windows"); 
     341   setHints(mXWindow, mInstName, mInstName, "VRJInputWindow"
     342            "VR Juggler Input Windows"); 
    343343 
    344344   XSelectInput(mXDisplay, mXWindow, event_mask); 
     
    389389} 
    390390 
    391 /* Sets basic window manager hints for a window. */ 
    392 void InputWindowXWin::setHints(Window window, char* window_name, 
    393                                char* icon_name, char* class_name, 
    394                                char* class_type) 
    395 
    396     XTextProperty  w_name; 
    397     XTextProperty  i_name; 
    398     XSizeHints     sizehints; 
    399     XWMHints       wmhints; 
    400     XClassHint     classhints; 
    401     int            status; 
    402  
    403     /* 
    404      * Generate window and icon names. 
    405      */ 
     391void InputWindowXWin::setHints(Window window, const std::string& windowName, 
     392                               const std::string& iconName, 
     393                               const std::string& className, 
     394                               const std::string& classType) 
     395
     396   // NOTE: Below, the char* held by each of the std::string parameters to 
     397   // this method is assigned to a value in an X structure. This is done 
     398   // without copying the bytes; rather the pointer value is simply assigned. 
     399   // This is safe because the X functions that receive the structures make 
     400   // copies of char* input. 
     401 
     402   XTextProperty w_name; 
     403   XTextProperty i_name; 
     404   int status; 
     405 
     406   // Generate window and icon names. 
     407   char* window_name = const_cast<char*>(windowName.c_str()); 
    406408   status = XStringListToTextProperty(&window_name, 1, &w_name); 
    407409 
     
    409411   { 
    410412      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) 
    411          << "Error allocating XString\n" << vprDEBUG_FLUSH; 
    412    } 
    413  
     413         << "Error allocating XTextProperty for window name (" << windowName 
     414         << ")\n" << vprDEBUG_FLUSH; 
     415   } 
     416 
     417   char* icon_name = const_cast<char*>(iconName.c_str()); 
    414418   status = XStringListToTextProperty(&icon_name, 1, &i_name); 
    415419 
     
    417421   { 
    418422      vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL) 
    419          << "Error allocating XString\n" << vprDEBUG_FLUSH; 
    420    } 
    421  
    422    sizehints.width       = mWidth;    /* -- Obsolete in R4 */ 
    423    sizehints.height      = mHeight;   /* -- Obsolete in R4 */ 
    424    sizehints.base_width  = mWidth;    /* -- New in R4 */ 
    425    sizehints.base_height = mHeight;   /* -- New in R4 */ 
    426  
    427    /* Set up flags for all the fields we've filled in. */ 
    428    sizehints.flags = USPosition | USSize | PBaseSize; 
    429  
    430    /*   assume the window starts in "normal" (rather than 
    431     *    iconic) state and wants keyboard input. 
    432     */ 
    433    wmhints.initial_state = NormalState; 
    434    wmhints.input         = True; 
    435    wmhints.flags         = StateHint | InputHint; 
     423         << "Error allocating TextProperty for icon name (" << iconName 
     424         << ")\n" << vprDEBUG_FLUSH; 
     425   } 
     426 
     427   XSizeHints size_hints; 
     428   size_hints.width       = mWidth;    // -- Obsolete in R4 
     429   size_hints.height      = mHeight;   // -- Obsolete in R4 
     430   size_hints.base_width  = mWidth;    // -- New in R4 
     431   size_hints.base_height = mHeight;   // -- New in R4 
     432 
     433   // Set up flags for all the fields we've filled in. 
     434   size_hints.flags = USPosition | USSize | PBaseSize; 
     435 
     436   // Assume that the window starts in "normal" (rather than iconic) state and 
     437   // wants keyboard input. 
     438   XWMHints wm_hints; 
     439   wm_hints.initial_state = NormalState; 
     440   wm_hints.input         = True; 
     441   wm_hints.flags         = StateHint | InputHint; 
    436442 
    437443   /* Fill in class name. */ 
    438    classhints.res_name  = class_name; 
    439    classhints.res_class = class_type; 
    440  
    441    XSetWMProperties(mXDisplay, window, &w_name, &i_name, 
    442                     //argv, argc, /* Note reversed order. */ 
    443                     NULL, 0, 
    444                     &sizehints, &wmhints, &classhints); 
     444   XClassHint class_hints; 
     445   class_hints.res_name  = const_cast<char*>(className.c_str()); 
     446   class_hints.res_class = const_cast<char*>(classType.c_str()); 
     447 
     448   char** argv(NULL); 
     449   int argc(0); 
     450   XSetWMProperties(mXDisplay, window, &w_name, &i_name, argv, argc, 
     451                    &size_hints, &wm_hints, &class_hints); 
    445452 
    446453   XFree(w_name.value); 
  • juggler/trunk/modules/gadgeteer/gadget/Devices/KeyboardMouseDevice/InputWindowXWin.h

    r20356 r20880  
    143143   Window createWindow(Window parent, const unsigned int borderWidth); 
    144144 
    145    void setHints(Window window, char*  window_name, char*  icon_name, 
    146                  char* class_name, char* class_type); 
     145   /** 
     146    * Sets basic window manager hints for this window. 
     147    */ 
     148   void setHints(Window window, const std::string& windowName, 
     149                 const std::string& iconName, const std::string& className, 
     150                 const std::string& classType); 
    147151   //@} 
    148152