2
// C++ Implementation: embedwidget
7
// Author: Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de>, (C) 2009
9
// Copyright: See COPYING file that comes with this distribution
12
#include "x2goclientconfig.h"
17
#include "x2gologdebug.h"
19
#include "embedwidget.h"
20
#include "onmainwindow.h"
25
// #include <QX11EmbedWidget>
26
#include <QX11EmbedContainer>
29
#include <X11/Xutil.h>
35
EmbedWidget::EmbedWidget ()
37
oldParentSize=QSize ( 0,0 );
40
oldParentPos=QPoint ( 0,0 );
46
EmbedWidget::~EmbedWidget()
50
void EmbedWidget::initWidgets()
53
/* qx11embedWidget=new QX11EmbedWidget;
54
mainLay=new QVBoxLayout ( qx11embedWidget );
55
mainLay->setContentsMargins ( 0,0,0,0 );
56
( ( ONMainWindow* ) this )->setParent ( qx11embedWidget );
58
mainLay->addWidget ( ( ONMainWindow* ) this );
60
qx11embedWidget->connect ( qx11embedWidget,
61
SIGNAL ( containerClosed () ),
62
( ONMainWindow* ) this,
65
embedContainer=new QX11EmbedContainer (
66
( ( ONMainWindow* ) this )->mainWidget() );
67
( ( ONMainWindow* ) this )->connect (
69
SIGNAL ( clientClosed() ),
70
( ONMainWindow* ) this,
71
SLOT ( slotDetachProxyWindow() ) );
73
embedContainer->connect (
75
SIGNAL ( clientClosed() ),
80
embedContainer=new QWidget (
81
( ( ONMainWindow* ) this )->mainWidget() );
83
embedContainer->hide();
84
( ( ONMainWindow* ) this )->mainLayout()->addWidget (
89
/*void EmbedWidget::embedInto ( long winId )
92
oldParentSize=getWindowSize ( parentId );
94
qx11embedWidget->embedInto ( winId );
95
QTimer::singleShot ( 100, qx11embedWidget, SLOT ( show() ) );
96
qx11embedWidget->move ( 0,0 );
97
qx11embedWidget->resize ( oldParentSize );
98
x2goDebug<<"embed window id: "<<qx11embedWidget->winId();
100
QTextStream ( &title ) <<"x2goembedded "<<winId;
101
qx11embedWidget->setWindowTitle ( title );
105
( HWND ) ( ( ONMainWindow* ) this )->winId(),
107
// wapiHideFromTaskBar(( HWND ) ( ( ONMainWindow* ) this )->winId());
108
QTimer::singleShot ( 50, ( ( ONMainWindow* ) this ), SLOT ( show() ) );
109
QTimer::singleShot ( 100, ( ONMainWindow* ) this,
110
SLOT ( slotUpdateEmbed() ) );
112
updateTimer = new QTimer ( ( ONMainWindow* ) this );
113
( ( ONMainWindow* ) this )->connect ( updateTimer, SIGNAL ( timeout() ),
114
( ONMainWindow* ) this,
115
SLOT ( slotUpdateEmbed() ) );
116
updateTimer->start ( 500 );
120
void EmbedWidget::slotUpdateEmbed()
122
QSize sz=getWindowSize ( parentId );
123
if ( sz!=oldParentSize )
127
qx11embedWidget->resize ( oldParentSize );
131
( ( ONMainWindow* ) this )->resize ( oldParentSize );
135
if ( sz==QSize ( 0,0 ) )
138
if ( !wapiClientRect ( ( HWND ) parentId,rec ) )
140
//parent not exist, close x2goclient;
141
x2goDebug<<"slotUpdateEmbed: parent closed\n";
142
( ( ONMainWindow* ) this )->close();
145
if ( ( ( ONMainWindow* ) this )->pos() !=oldParentPos )
148
( ( ONMainWindow* ) this )->resize ( oldParentSize );
153
if ( !wapiWindowRect ( ( HWND ) childId,rec ) )
155
x2goDebug<<"slotUpdateEmbed: child closed\n";
159
if ( ( embedContainer->size() != oldContainerSize ) ||
160
( rec.topLeft() !=oldChildPos ) )
162
moveEmbedChild ( 0,0 );
164
wapiUpdateWindow ( ( HWND ) childId );
166
// wapiUpdateWindow ( ( HWND ) ( ( ONMainWindow* ) this )->winId() );
167
( ( ONMainWindow* ) this )->update();
171
QSize EmbedWidget::getWindowSize ( long winId )
175
XWindowAttributes atr;
176
if ( XGetWindowAttributes ( QX11Info::display(),winId,&atr ) )
177
return QSize ( atr.width,atr.height );
178
return QSize ( 0,0 );
182
if ( wapiClientRect ( ( HWND ) winId,rec ) )
185
return QSize ( 0,0 );
190
void EmbedWidget::moveEmbed ( int x, int y )
196
if ( wapiGetBorders ( ( HWND ) ( ( ONMainWindow* ) this )->winId(),
197
vBorder, hBorder, barHeight ) )
199
oldParentPos.setX ( x-hBorder );
200
oldParentPos.setY ( y-vBorder-barHeight );
201
( ( ONMainWindow* ) this )->move ( oldParentPos.x(),
206
void EmbedWidget::moveEmbedChild ( int x, int y )
211
oldContainerSize=embedContainer->size();
213
if ( wapiGetBorders ( ( HWND ) childId,
214
vBorder, hBorder, barHeight ) )
217
oldChildPos.setX ( x-hBorder );
218
oldChildPos.setY ( y-vBorder-barHeight );
219
wapiMoveWindow ( ( HWND ) childId,oldChildPos.x(),
221
oldContainerSize.width() +2*hBorder,
222
oldContainerSize.height() +2*vBorder+barHeight,
230
long EmbedWidget::X11FindWindow ( QString text, long rootWin )
238
rootWin= XDefaultRootWindow ( QX11Info::display() );
240
if ( XQueryTree ( QX11Info::display(),rootWin,&wRoot,&wParent,
241
&child_list,&nChildren ) )
243
for ( uint i=0;i<nChildren;++i )
246
if ( XFetchName ( QX11Info::display(),
247
child_list[i],&wname ) )
249
QString title ( wname );
253
proxyId=child_list[i];
257
proxyId=X11FindWindow ( text, child_list[i] );
261
XFree ( child_list );
267
long EmbedWidget::findWindow ( QString text )
270
return X11FindWindow ( text );
273
return ( long ) wapiFindWindow ( 0,text.utf16() );
278
void EmbedWidget::embedWindow ( long wndId )
281
embedContainer->show();
283
embedContainer->embedClient ( wndId );
286
wapiSetParent ( ( HWND ) childId,
287
( HWND ) ( embedContainer->winId() ) );
288
oldContainerSize=QSize ( 0,0 );
289
oldChildPos=QPoint ( 0,0 );
290
// slotUpdateEmbed();
295
void EmbedWidget::detachClient()
298
if ( embedContainer )
300
embedContainer->discardClient();
304
wapiSetParent ( ( HWND ) childId, ( HWND ) 0 );
305
( ( ONMainWindow* ) this )->slotDetachProxyWindow();
308
wapiMoveWindow ( ( HWND ) childId,0,0,
309
oldContainerSize.width(),
310
oldContainerSize.height(),true );
317
void EmbedWidget::closeEmbedWidget()
320
if ( qx11embedWidget )
322
qx11embedWidget->close();
328
#endif //(Q_OS_DARWIN)