Prosíme přihlašte se nebo zaregistrujte.

Přihlašte se svým uživatelským jménem a heslem.
Vaše pomoc je stále potřeba!

Autor Téma: TinyWM na DISPLAY 1 nefunguje  (Přečteno 1803 krát)

Samms

  • Aktivní člen
  • *
  • Příspěvků: 297
TinyWM na DISPLAY 1 nefunguje
« kdy: 18 Července 2014, 09:22:13 »
Dobrý den,
jen jsem trochu upravil TinyWM, ale stejně mi to nikdy nešlo:

Kód: [Vybrat]
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <cstdio>

#define MAX(a, b) ((a) > (b) ? (a) : (b))

extern struct _IO_FILE *stdin; // Standard input stream
extern struct _IO_FILE *stdout; // Standard output stream
extern struct _IO_FILE *stderr; // Standard error output stream

int main()
{
Display *currentDisplay = XOpenDisplay(NULL);

if(!currentDisplay)
{
fprintf(stderr, "Fatal error -> Can't open display!");
return 1;
}

Window rootWindow = DefaultRootWindow(currentDisplay);
XWindowAttributes windowAttributes;
XButtonEvent mouseButton;
int offsetX, offsetY;
XEvent systemEvent;

XGrabKey
(
currentDisplay,
XKeysymToKeycode(currentDisplay, XK_F1),
Mod1Mask,
rootWindow,
True,
GrabModeAsync,
GrabModeAsync
);
XGrabButton
(
currentDisplay,
1,
Mod1Mask,
rootWindow,
True,
ButtonPressMask,
GrabModeAsync,
GrabModeAsync,
None,
None
);
XGrabButton
(
currentDisplay,
3,
Mod1Mask,
rootWindow,
True,
ButtonPressMask,
GrabModeAsync,
GrabModeAsync,
None,
None
);

fprintf(stderr, "Welcome in IwroQ!");

while(true)
{
XNextEvent(currentDisplay, &systemEvent);

switch(systemEvent.type)
{
case KeyPress:

if(systemEvent.xkey.subwindow != None)
XRaiseWindow(currentDisplay, systemEvent.xkey.subwindow);

break;

case ButtonPress:

if(systemEvent.xbutton.subwindow != None)
{
XGrabPointer
(
currentDisplay,
systemEvent.xbutton.subwindow,
True,
PointerMotionMask | ButtonReleaseMask,
GrabModeAsync,
GrabModeAsync,
None,
None,
CurrentTime
);

XGetWindowAttributes(currentDisplay, systemEvent.xbutton.subwindow, &windowAttributes);
mouseButton = systemEvent.xbutton;
}

break;

case MotionNotify:

while(XCheckTypedEvent(currentDisplay, MotionNotify, &systemEvent));

offsetX = systemEvent.xbutton.x_root - mouseButton.x_root;
offsetY = systemEvent.xbutton.y_root - mouseButton.y_root;

XMoveResizeWindow
(
currentDisplay,
systemEvent.xmotion.window,
windowAttributes.x + (mouseButton.button == 1 ? offsetX : 0),
windowAttributes.y + (mouseButton.button == 1 ? offsetY : 0),
MAX(1, windowAttributes.width + (mouseButton.button == 3 ? offsetX : 0)),
MAX(1, windowAttributes.height + (mouseButton.button == 3 ? offsetY : 0))
);

break;

case ButtonRelease:

XUngrabPointer(currentDisplay, CurrentTime);

break;
}
}
}

(pouštím z Roxtermu pomocí DISPLAY=: 1)

Abych věděl, zda to vůbec běží, dal jsem tam pro kontrolu ta "fprintf". Běží to, avšak na vstup (jakýkoliv) to absolutně kašle. Neví někdo proč?
Děkuji.

EDIT:
Už vím jistě, že "XNextEvent(currentDisplay, &systemEvent);" čeká na událost, která nepřichází. Ovšem - proč nepřichází? :)
« Poslední změna: 18 Července 2014, 11:36:29 od Samms »

 

Provoz zaštiťuje spolek OpenAlt.