2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
2 |
/*
|
|
3 |
* Copyright (C) 2011 Canonical Ltd
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
3294.3.1
by Andrea Azzarone
Show XdndCollectionWindow only during dnd operation. |
17 |
* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
18 |
*/
|
19 |
||
20 |
#include "XdndCollectionWindowImp.h" |
|
2898.4.14
by Andrea Azzarone
Some fixes suggested by Marco. |
21 |
#include "unity-shared/UScreen.h" |
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
22 |
#include "unity-shared/WindowManager.h" |
23 |
||
24 |
namespace unity { |
|
25 |
namespace { |
|
26 |
||
27 |
class PrivateWindow : public nux::BaseWindow |
|
28 |
{
|
|
29 |
public: |
|
30 |
PrivateWindow(XdndCollectionWindowImp* parent) |
|
31 |
: nux::BaseWindow("") |
|
32 |
, parent_(parent) |
|
33 |
{
|
|
34 |
// Make it invisible...
|
|
2898.4.17
by Andrea Azzarone
Use nux::color::Transparent. |
35 |
SetBackgroundColor(nux::color::Transparent); |
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
36 |
SetOpacity(0.0f); |
37 |
// ... and as big as the whole screen.
|
|
2898.4.14
by Andrea Azzarone
Some fixes suggested by Marco. |
38 |
auto uscreen = UScreen::GetDefault(); |
39 |
SetGeometry(uscreen->GetScreenGeometry()); |
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
40 |
|
2985.3.21
by Sam Spilsbury
Added a note about ShowWindow removal |
41 |
// We are not calling ShowWindow () as this window
|
42 |
// isn't really visible
|
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
43 |
PushToBack(); |
3180.2.1
by Marco Trevisan (Treviño)
Dash, Hud, Panel: don't use input-windows when not in embedded mode |
44 |
|
45 |
if (nux::GetWindowThread()->IsEmbeddedWindow()) |
|
46 |
{
|
|
47 |
// Hack to create the X Window as soon as possible.
|
|
48 |
EnableInputWindow(true, "XdndCollectionWindowImp"); |
|
49 |
EnableInputWindow(false, "XdndCollectionWindowImp"); |
|
50 |
}
|
|
51 |
||
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
52 |
SetDndEnabled(false, true); |
53 |
||
2898.4.14
by Andrea Azzarone
Some fixes suggested by Marco. |
54 |
uscreen->changed.connect(sigc::mem_fun(this, &PrivateWindow::OnScreenChanged)); |
55 |
WindowManager::Default().window_moved.connect(sigc::mem_fun(this, &PrivateWindow::OnWindowMoved)); |
|
56 |
}
|
|
57 |
||
3680.1.76
by Marco Trevisan (Treviño)
UScreen: use better API, const methods and remove useless includes |
58 |
void OnScreenChanged(int /*primary*/, std::vector<nux::Geometry> const& /*monitors*/) |
2898.4.14
by Andrea Azzarone
Some fixes suggested by Marco. |
59 |
{
|
60 |
auto uscreen = UScreen::GetDefault(); |
|
61 |
SetGeometry(uscreen->GetScreenGeometry()); |
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
62 |
}
|
63 |
||
64 |
/**
|
|
65 |
* EnableInputWindow doesn't show the window immediately.
|
|
66 |
* Since nux::EnableInputWindow uses XMoveResizeWindow the best way to know if
|
|
67 |
* the X Window is really on/off screen is receiving WindowManager::window_moved
|
|
68 |
* signal. Please don't hate me!
|
|
69 |
**/
|
|
70 |
void OnWindowMoved(Window window_id) |
|
71 |
{
|
|
2898.4.14
by Andrea Azzarone
Some fixes suggested by Marco. |
72 |
if (G_LIKELY(window_id != GetInputWindowId())) |
73 |
return; |
|
74 |
||
75 |
// Create a fake mouse move because sometimes an extra one is required.
|
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
76 |
auto display = nux::GetGraphicsDisplay()->GetX11Display(); |
2898.4.14
by Andrea Azzarone
Some fixes suggested by Marco. |
77 |
XWarpPointer(display, None, None, 0, 0, 0, 0, 0, 0); |
78 |
XFlush(display); |
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
79 |
}
|
80 |
||
81 |
void ProcessDndMove(int x, int y, std::list<char*> mimes) |
|
82 |
{
|
|
83 |
// Hide the window as soon as possible.
|
|
84 |
PushToBack(); |
|
85 |
EnableInputWindow(false, "XdndCollectionWindowImp"); |
|
86 |
||
87 |
std::vector<std::string> data; |
|
88 |
for (auto mime : mimes) |
|
2898.4.15
by Andrea Azzarone
Prevent crashes. |
89 |
if (mime) data.push_back(mime); |
3566.3.20
by Marco Trevisan (Treviño)
XdndCollectionWindow: add a GetData method to fetch dnd data from GraphicDisplay |
90 |
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
91 |
parent_->collected.emit(data); |
92 |
}
|
|
93 |
||
94 |
XdndCollectionWindowImp* parent_; |
|
95 |
};
|
|
96 |
||
97 |
}
|
|
98 |
||
99 |
XdndCollectionWindowImp::XdndCollectionWindowImp() |
|
100 |
: window_(new PrivateWindow(this)) |
|
101 |
{}
|
|
102 |
||
103 |
void XdndCollectionWindowImp::Collect() |
|
104 |
{
|
|
105 |
// Using PushToFront we're sure that the window is shown over the panel window,
|
|
106 |
// the launcher window and the dash window. Don't forget to call PushToBack as
|
|
107 |
// soon as possible.
|
|
3294.3.1
by Andrea Azzarone
Show XdndCollectionWindow only during dnd operation. |
108 |
window_->ShowWindow(true); |
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
109 |
window_->PushToFront(); |
3180.2.1
by Marco Trevisan (Treviño)
Dash, Hud, Panel: don't use input-windows when not in embedded mode |
110 |
|
111 |
if (nux::GetWindowThread()->IsEmbeddedWindow()) |
|
112 |
window_->EnableInputWindow(true, "XdndCollectionWindowImp"); |
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
113 |
}
|
114 |
||
115 |
void XdndCollectionWindowImp::Deactivate() |
|
116 |
{
|
|
3294.3.1
by Andrea Azzarone
Show XdndCollectionWindow only during dnd operation. |
117 |
window_->ShowWindow(false); |
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
118 |
window_->PushToBack(); |
3180.2.1
by Marco Trevisan (Treviño)
Dash, Hud, Panel: don't use input-windows when not in embedded mode |
119 |
|
120 |
if (nux::GetWindowThread()->IsEmbeddedWindow()) |
|
121 |
window_->EnableInputWindow(false, "XdndCollectionWindowImp"); |
|
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
122 |
}
|
3566.3.20
by Marco Trevisan (Treviño)
XdndCollectionWindow: add a GetData method to fetch dnd data from GraphicDisplay |
123 |
|
124 |
std::string XdndCollectionWindowImp::GetData(std::string const& type) |
|
125 |
{
|
|
126 |
auto& gp_display = nux::GetWindowThread()->GetGraphicsDisplay(); |
|
127 |
return glib::String(gp_display.GetDndData(const_cast<char*>(type.c_str()))).Str(); |
|
128 |
}
|
|
129 |
||
2898.4.1
by Andrea Azzarone
Rename DNDCollectionWindow to XdndCollectionWinodw*. Partial refactor too. |
130 |
}
|