Hello, I am trying to write Xlib-program that would produce a window (main 
window) on the screen (root screen) and the subwindow inside the main window. 
To make that, the following Xlib-functions are called (the question is below):

 window = XCreateSimpleWindow ( display,
     RootWindow ( display, screen_number ),
     X, Y,WIDTH,HEIGHT,BORDER_WIDTH,
     BlackPixel ( display, screen_number ),
     WhitePixel ( display, screen_number ) );

 SetWindowManagerHints ( display, PRG_CLASS, argv, argc,
   window, X, Y, WIDTH, HEIGHT, WIDTH_MIN,
   HEIGHT_MIN, TITLE, ICON_TITLE, 0 );

 XSelectInput ( display, window, ExposureMask | KeyPressMask );

 XMapWindow ( display, window );

 window1 = XCreateSimpleWindow ( display,  window,
     (X+5), (Y+5), (int)(WIDTH/3.), (int)(HEIGHT/2.), (int)(BORDER_WIDTH),
     BlackPixel ( display, screen_number ),
     WhitePixel ( display, screen_number ) );

 SetWindowManagerHints ( display, PRG_CLASS, argv, argc,
   window1, (X+5), (Y+5), (int)(WIDTH/3.), (int)(HEIGHT/3.), (int)(WIDTH_MIN),
   (int)(HEIGHT_MIN/3.), TITLE1, ICON_TITLE, 0 );

 XSelectInput ( display, window1, ExposureMask | KeyPressMask );

 XMapWindow ( display, window1 );

These commands produce the main window and the subwindow with the borders 
specified. However, the subwindow can not be moved inside the main window by 
dragging it with a mouse. The windows manager is attached only to the main 
window, and I guess not to the subwindow.

Could anybody help to resolve these problem: that is, how the code should be 
modified in order to achieve moving the subwindow inside the main window ?

I also attach the the example code.

Thank you.

Il'dar
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <stdio.h>
#include <string.h>

#define X 0
#define Y 0
#define WIDTH 400
#define HEIGHT 400
#define WIDTH_MIN 100
#define HEIGHT_MIN 100
#define BORDER_WIDTH 5
#define TITLE "Example"
#define TITLE1 "Sub_example"
#define ICON_TITLE "Example"
#define PRG_CLASS "Example"

static void SetWindowManagerHints ( 
 Display * display, 		
 char * PClass, 		
 char * argv[],   		
 int argc,    			
 Window window,    		
 int x,     			
 int y,	   				
 int win_wdt,			
 int win_hgt,  			
 int win_wdt_min,			
 int win_hgt_min, 		
 char * ptrTitle,  		
 char * ptrITitle,	
 Pixmap pixmap 	
)
{
 XSizeHints size_hints;

 XWMHints wm_hints;
 XClassHint class_hint;
 XTextProperty windowname, iconname;

 if ( !XStringListToTextProperty (&ptrTitle, 1, &windowname ) ||
    !XStringListToTextProperty (&ptrITitle, 1, &iconname ) ) {
  puts ( "No memory!\n");
  exit ( 1 );
}

size_hints.flags = PPosition | PSize | PMinSize;
size_hints.min_width = win_wdt_min;
size_hints.min_height = win_hgt_min;
wm_hints.flags = StateHint | IconPixmapHint | InputHint;
wm_hints.initial_state = NormalState;
wm_hints.input = True;
wm_hints.icon_pixmap= pixmap;
class_hint.res_name = argv[0];
class_hint.res_class = PClass;

XSetWMProperties ( display, window, &windowname,
  &iconname, argv, argc, &size_hints, &wm_hints,
  &class_hint );
}

void main(int argc, char *argv[])
{
 int ii;
 Display * display; 
 int screen_number;
 GC gc,gc1;			
 XEvent report;
 Window window, window1;
  char disp1[]="microsof-70c56f:1.0";

 if ( ( display = XOpenDisplay(disp1) ) == NULL ) {
  puts ("Can not connect to the X server!\n");
  exit ( 1 );
 }

// screen_number = DefaultScreen ( display );

screen_number=0;

 window = XCreateSimpleWindow ( display,
     RootWindow ( display, screen_number ),
     X, Y,WIDTH,HEIGHT,BORDER_WIDTH,
     BlackPixel ( display, screen_number ),
     WhitePixel ( display, screen_number ) );

 SetWindowManagerHints ( display, PRG_CLASS, argv, argc,
   window, X, Y, WIDTH, HEIGHT, WIDTH_MIN,
   HEIGHT_MIN, TITLE, ICON_TITLE, 0 );

 XSelectInput ( display, window, ExposureMask | KeyPressMask );

 XMapWindow ( display, window );



 window1 = XCreateSimpleWindow ( display,
     window,
     (X+5), (Y+5), (int)(WIDTH/3.), (int)(HEIGHT/2.), (int)(BORDER_WIDTH),
     BlackPixel ( display, screen_number ),
     WhitePixel ( display, screen_number ) );

 SetWindowManagerHints ( display, PRG_CLASS, argv, argc,
   window1, (X+5), (Y+5), (int)(WIDTH/3.), (int)(HEIGHT/3.), (int)(WIDTH_MIN),
   (int)(HEIGHT_MIN/3.), TITLE1, ICON_TITLE, 0 );

 XSelectInput ( display, window1, ExposureMask | KeyPressMask );

 XMapWindow ( display, window1 );


while(1)
 {
  XNextEvent ( display, &report );

  switch ( report.type ) {
    case Expose :
     if ( report.xexpose.count != 0 )
      break;

     gc = XCreateGC ( display, window, 0 , NULL );

     XSetForeground ( display, gc, BlackPixel ( display, 0) );


     gc1 = XCreateGC ( display, window1, 0 , NULL );

     XSetForeground ( display, gc1, BlackPixel ( display, 0) );
     
     XDrawString ( display, window, gc, 20,50,
       "Main Window", strlen ( "Main Window" ) );

     XDrawString ( display, window1, gc1, 20,50,
      "Subwindow", strlen ( "Subwindow" ) );


     XFreeGC ( display, gc );
     XFreeGC ( display, gc1 );
     XFlush(display);
     break;

    case KeyPress :
     XCloseDisplay ( display );
     exit ( 0 );
  }
 }
}

_______________________________________________
[email protected]: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: [email protected]

Reply via email to