1 /* dndelement.cc
2  * This file belongs to Worker, a file manager for UN*X/X11.
3  * Copyright (C) 2001-2017 Ralf Hoffmann.
4  * You can contact me at: ralf@boomerangsworld.de
5  *   or http://www.boomerangsworld.de/worker
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #include "dndelement.h"
23 #include "aguix.h"
24 #include "guielement.h"
25 #include "awindow.h"
26 
DNDElement(AGUIX * parent)27 DNDElement::DNDElement( AGUIX *parent )
28 {
29   aguix=parent;
30   Display *dsp=aguix->getDisplay();
31   int scr=aguix->getScreen();
32   Visual *vis=DefaultVisual(dsp,scr);
33   unsigned long mask=CWEventMask|CWBackPixel|CWOverrideRedirect|CWSaveUnder;
34   XSetWindowAttributes attr;
35   attr.event_mask=ExposureMask|ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|PointerMotionHintMask|KeyReleaseMask;
36   attr.background_pixel=0;
37   attr.override_redirect=true;
38   attr.save_under=true;
39 
40   int xw,yw,xr,yr;
41   Window root,child;
42   unsigned int keys_button;
43   XQueryPointer(dsp,RootWindow(dsp,scr),&root,&child,&xr,&yr,&xw,&yw,&keys_button);
44 
45   win=XCreateWindow(dsp,RootWindow(dsp,scr),xr,yr,1,1,0,aguix->getDepth(),InputOutput,vis,mask,&attr);
46   XClearWindow(dsp,win);
47   XFlush(dsp);
48 
49   delx=0;
50   dely=0;
51 
52   created = false;
53 }
54 
~DNDElement()55 DNDElement::~DNDElement()
56 {
57   close();
58 }
59 
handler(Message * msg)60 void DNDElement::handler( Message *msg )
61 {
62   int tx, ty;
63   if ( created == false ) {
64     create();
65   }
66   if ( msg->type == MotionNotify ) {
67     aguix->queryRootPointer( &tx, &ty );
68     XMoveWindow( aguix->getDisplay(), win, delx + tx, dely + ty );
69     aguix->Flush();
70   } else if ( msg->type == Expose ) {
71     if ( msg->window == win ) redraw();
72   }
73 }
74 
redraw()75 void DNDElement::redraw()
76 {
77 }
78 
close()79 void DNDElement::close()
80 {
81   if(win!=0) XDestroyWindow(aguix->getDisplay(),win);
82   win=0;
83 }
84 
create()85 void DNDElement::create()
86 {
87   XMapRaised(aguix->getDisplay(),win);
88   created = true;
89 }
90