01-23-04 10:35 PM
Hi
I'm trying to write a very simple X-windows application and I've run into
a problem with XReparentWindow(). For the moment, all I want is the followin
g:
- when an xterm (or some other application) is started, a new window must
be created (XCreateWindow()) and the xterm must be reparented to that
new window. (note: I start the xterm manually with
xterm -display :1 -geometry +100+100)
- Ideally, the xterm window should be properly resized to fit the newly
created window.
I'm at a point where I can intercept the xterm window being created. I
create my own window and call XReparentWindow(). The result is:
- If the SubstructureRedirectEvent mask is set in my new window, I see the
new window but not the xterm window
- If the SubstructureRedirectEvent mask is not set, then the xterm is visibl
e,
but not necessarily in the correct position. eg. I say
XReparentWindow(dpy, w, parent, 0, 0) but the reparented window does not
move to position 0, 0 relative to the parent.
I'm brand new to this, so any and all help will be appreciated. I've been
going through the Xlib docs but so far I've had no joy. I've included the
code for the program below. It's only the beginning and very incomplete,
but for now, all I need is what is stated above. I attempt the reparent
in the handleCreateNotify() function.
Thanks in advance
kodgehopper
/*******************Main.h************************/
#ifndef _MAIN_H
#define _MAIN_H
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
using namespace std;
class Main
{
public:
Main();
~Main();
int processEvents();
protected:
Display *dpy;
Window root;
int screen;
private:
void init();
void handleCreateNotify(XEvent *);
void handleReparentNotify(XEvent *);
Window leftWin;
};
#endif
/************************Main.cc***********************/
#include "Main.h"
Main::Main()
{
dpy = NULL;
init();
}
Main::~Main()
{
}
void Main::init()
{
dpy=XOpenDisplay(":1");
if (!dpy)
{
cerr << "Failed to open display" << endl;
exit(-1);
}
screen=DefaultScreen(dpy);
root=RootWindow(dpy, screen);
XSelectInput(dpy, root, ButtonPressMask|VisibilityChangeMask|Exp
osureMask|
StructureNotifyMask|EnterWindowMask|Leav
eWindowMask|
SubstructureNotifyMask);
XMapWindow(dpy, root);
XFlush(dpy);
}
void Main::handleCreateNotify(XEvent *ev)
{
Window newWindow;
XCreateWindowEvent e = ev->xcreatewindow;
newWindow=e.window;
if (newWindow == leftWin)
{
return;
}
XSelectInput(dpy, newWindow, StructureNotifyMask);
/* create our own window of size 300x300 */
XSetWindowAttributes attr;
/* WITH THIS STATEMENT, I SEE A BLACK BOX BUT NO XTERM WINDOW */
attr. event_mask=SubstructureNotifyMask|Substr
uctureRedirectMask;
/* IF I USE THE STATEMENT BELOW INSTEAD, I SEE A BLACK BOX, WITH AN
INCORRECTLY PLACED XTERM WINDOW */
//attr.event_mask=SubstructureNotifyMask;
leftWin = XCreateWindow(dpy, root, 0, 0, 300, 300, 0, CopyFromParent,
InputOutput, CopyFromParent, CWEventMask, &attr);
XSetWindowBackground(dpy, leftWin, 0);
/* reparent */
XReparentWindow(dpy, newWindow, leftWin, 0, 0);
XMapWindow(dpy, leftWin);
}
void Main::handleReparentNotify(XEvent *ev)
{
// XReparentEvent e=ev->xreparent;
// Window currWindow = e.window;
}
int Main::processEvents()
{
while (1)
{
XEvent e;
XNextEvent(dpy, &e);
switch (e.type)
{
case CreateNotify:
{
handleCreateNotify(&e);
}
break;
case ReparentNotify:
{
handleReparentNotify(&e);
}
break;
case ConfigureRequest:
{
cout << "got configure request" << endl;
}
break;
case KeyPress:
case KeyRelease:
case ButtonRelease:
case MotionNotify:
case ButtonPress:
{
cout << "Other Event" << endl;
}
break;
}
}
}
int main(int argc, char *argv[])
{
Main m;
m.processEvents();
return 0;
}
[ Post a follow-up to this message ]
|