Thank you for the help! I'll start learning Qt.
I solved my problem by using one big while-loop. In the while-loop I've got two if(XPending(display)) for each display. The program is very simple so I approached with a simple answer and I'm quite freshman so I didn't really understand what's going on with the polling. Here's my solution:
while( !Finished ){
//If drawing to display1
if(XPending(dpy)) {
XEvent e;
XNextEvent( dpy, & e ); // Get event
switch( e.type ){
case ButtonPress :
switch( e.xbutton.button ){
case Button1 :
//Start drawing
break;
case Button2 :
case Button3 :
break;
}
break;
case ButtonRelease :
switch( e.xbutton.button ){
case Button1 :
//Draw things
break;
}
break;
case MotionNotify :
if( drawing && (e.xmotion.state & Button1Mask) )
{
//Draw things
}
break;
case Expose :
if( e.xexpose.count == 0 ) {
//Redraw content if current window is resized by user
}
break;
}//switch
}//if
else if(XPending(display2)) { //if drawing to display2
//same things as display1 but changed to display2
}
}//while