Merge lp:~3v1n0/unity/panel-p-cleanup into lp:unity
- panel-p-cleanup
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Didier Roche-Tolomelli |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2242 |
Proposed branch: | lp:~3v1n0/unity/panel-p-cleanup |
Merge into: | lp:unity |
Diff against target: |
7874 lines (+3128/-2131) 28 files modified
UnityCore/Variant.cpp (+31/-2) UnityCore/Variant.h (+6/-1) plugins/unityshell/src/DashController.cpp (+5/-3) plugins/unityshell/src/DashController.h (+1/-0) plugins/unityshell/src/LauncherController.cpp (+51/-8) plugins/unityshell/src/PanelController.cpp (+27/-20) plugins/unityshell/src/PanelController.h (+2/-4) plugins/unityshell/src/PanelIndicatorEntryView.cpp (+440/-347) plugins/unityshell/src/PanelIndicatorEntryView.h (+69/-45) plugins/unityshell/src/PanelIndicatorsView.cpp (+103/-42) plugins/unityshell/src/PanelIndicatorsView.h (+27/-18) plugins/unityshell/src/PanelMenuView.cpp (+934/-859) plugins/unityshell/src/PanelMenuView.h (+78/-90) plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp (+125/-13) plugins/unityshell/src/PanelTitlebarGrabAreaView.h (+27/-6) plugins/unityshell/src/PanelTray.cpp (+92/-115) plugins/unityshell/src/PanelTray.h (+21/-24) plugins/unityshell/src/PanelView.cpp (+123/-149) plugins/unityshell/src/PanelView.h (+40/-45) plugins/unityshell/src/PluginAdapter.cpp (+158/-24) plugins/unityshell/src/PluginAdapter.h (+12/-3) plugins/unityshell/src/SwitcherController.cpp (+9/-2) plugins/unityshell/src/UBusMessages.h (+1/-0) plugins/unityshell/src/WindowButtons.cpp (+587/-220) plugins/unityshell/src/WindowButtons.h (+33/-12) plugins/unityshell/src/WindowManager.cpp (+38/-10) plugins/unityshell/src/WindowManager.h (+12/-6) plugins/unityshell/src/unityshell.cpp (+76/-63) |
To merge this branch: | bzr merge lp:~3v1n0/unity/panel-p-cleanup |
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Approve | ||
Review via email: mp+99950@code.launchpad.net |
Commit message
A lot of panel fixes with code cleanup and improvements to the panel code.
This branch introduces a lot of code cleanup and improvements to the panel code.
A part the linked bugs fixed, this changes:
- PanelStyle: used now to check all the panel related settings, including
fonts and DPI. Emitting the changed signal when they get changed (so now
when changing the title font, it gets updated immediately).
Added better support for HighContrast themes and fallback buttons.
Used ti everywhere to remove the "24" height magic number.
- PanelIndicatorE
and modified to be easily extendible in the near future. Also fixed issues
with the indicator entries and Scale/Expo
- PanelMenuView: the layout system has been rewritten and now it works
natively without the workarounds we were using before,
fixed the panel paddings to match design specs;
Optimized the drawing operations, now the title texture is cached and
rebuilt only if really needed.
Fixed the panel title on Expo and Scale.
Improved the detection of the panel used to draw the app title on
multi-monitor (disabled otherwise), and the alt+tab/alt conflict.
Maximized windows list is re-populated on startup or when adding a new
screen.
- PanelTitlebarGr
and clicks over it.
- WindowButtons: rewritten using in a better way the subclass nux::Button
features, factorizing some code for each button into WindowButtons. Also
the handling of the controlled window is now done internally, not by the
PanelMenuView.
Description of the change
A lot of panel fixes... Into one branch, because they should go together, but the single changes are shown on these single code reviews:
1) PanelStyle changes: http://
2) Indicator Entry changes: http://
3) Indicators View changes: http://
4) Window buttons changes: http://
5) Grab area changes: http://
6) Tray changes: http://
7) Window Manager changes: http://
8) Core changes: http://
9) Menu view changes: http://
10) Panel view changes: http://
This branch introduces a lot of code cleanup and improvements to the panel code.
A part the linked bugs fixed, this changes:
- PanelStyle: used now to check all the panel related settings, including
fonts and DPI. Emitting the changed signal when they get changed (so now
when changing the title font, it gets updated immediately).
Added better support for HighContrast themes and fallback buttons.
Used ti everywhere to remove the "24" height magic number.
- PanelIndicatorE
and modified to be easily extendible in the near future. Also fixed issues
with the indicator entries and Scale/Expo
- PanelMenuView: the layout system has been rewritten and now it works
natively without the workarounds we were using before,
fixed the panel paddings to match design specs;
Optimized the drawing operations, now the title texture is cached and
rebuilt only if really needed.
Fixed the panel title on Expo and Scale.
Improved the detection of the panel used to draw the app title on
multi-monitor (disabled otherwise), and the alt+tab/alt conflict.
Maximized windows list is re-populated on startup or when adding a new
screen.
- PanelTitlebarGr
and clicks over it.
- WindowButtons: rewritten using in a better way the subclass nux::Button
features, factorizing some code for each button into WindowButtons. Also
the handling of the controlled window is now done internally, not by the
PanelMenuView.
Testing:
- All the panel items now are introspectable. And this allow AP testing.
- The branch with all the brand new tests for the panel are at:
lp:~3v1n0/unity/panel-p-tests
Tim Penhey (thumper) wrote : | # |
Tim Penhey (thumper) wrote : | # |
Also, in the breakup way, you should be using chained merge proposals using prerequisite branches.
Tim Penhey (thumper) wrote : | # |
Reviews in progress on the others.
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
> Also, in the breakup way, you should be using chained merge proposals using
> prerequisite branches.
Yes, I know, but since I've splitted it later, I didn't want to cause temporary breakage in trunk when merging just partial changes, so I want to keep this top branch updated and make it go into trunk, while the partial changes are here only for reviewing (even if they reflect the reality since I'm updating them using bzr pipeline)
Tim Penhey (thumper) wrote : | # |
You have a lot of bugs linked to this branch. Where are the tests confirming fixes?
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
> You have a lot of bugs linked to this branch. Where are the tests confirming
> fixes?
I'm currently writing them, considering the size of this branch I want to keep the tests in another branches, while this get reviewed.
Brandon Schaefer (brandontschaefer) wrote : | # |
** Note, I couldn't test any bug that dealt with multi monitors. **
Ok, lots of code. Confirmed this branch fixes all of these bugs:
Bug #655184: Top bar - Menus should be condensed to fit panel/overlay of appmenu
Bug #839690: Topbar - window controls for maximised windows in the top bar should conform to Fitts's law
Bug #875932: window selected via ALT+F1 doesn't get focus in unity
Bug #934680: Window management - Dragging down a maximized window from the panel has not predictable results
Bug #936425: Not minimizable windows have an enabled "minimize" button on the unity panel
Bug #939054: HUD maximize button affects Dash
Bug #962410: Menu bar not transparent when invoking dash with super key whilst HUD enabled and vice versa
Bug #963118: Windows controls lost if dash is opened after HUD
Bug #963134: Opening HUD after dash shows window title in the panel
Bug #970420: Super+Tab, super, loses focus
Bug #971947: PanelMenuView causes gtk assertion to fail
Bug #940683: Panel opacity toggle doesn't quite work
When the test are done this branch will be look good :). Awesome work!
Tim Penhey (thumper) wrote : | # |
The test branch landing is coming next, for some reason tarmac gets itself in a twist.
Unity Merger (unity-merger) wrote : | # |
No commit message specified.
Preview Diff
1 | === modified file 'UnityCore/Variant.cpp' | |||
2 | --- UnityCore/Variant.cpp 2012-03-21 12:31:11 +0000 | |||
3 | +++ UnityCore/Variant.cpp 2012-04-05 23:42:20 +0000 | |||
4 | @@ -142,15 +142,44 @@ | |||
5 | 142 | return *this; | 142 | return *this; |
6 | 143 | } | 143 | } |
7 | 144 | 144 | ||
9 | 145 | BuilderWrapper& BuilderWrapper::add(char const* name, unsigned value) | 145 | BuilderWrapper& BuilderWrapper::add(char const* name, long int value) |
10 | 146 | { | ||
11 | 147 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_int64(value)); | ||
12 | 148 | return *this; | ||
13 | 149 | } | ||
14 | 150 | |||
15 | 151 | BuilderWrapper& BuilderWrapper::add(char const* name, long long int value) | ||
16 | 152 | { | ||
17 | 153 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_int64(value)); | ||
18 | 154 | return *this; | ||
19 | 155 | } | ||
20 | 156 | |||
21 | 157 | BuilderWrapper& BuilderWrapper::add(char const* name, unsigned int value) | ||
22 | 146 | { | 158 | { |
23 | 147 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_uint32(value)); | 159 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_uint32(value)); |
24 | 148 | return *this; | 160 | return *this; |
25 | 149 | } | 161 | } |
26 | 150 | 162 | ||
27 | 163 | BuilderWrapper& BuilderWrapper::add(char const* name, long unsigned int value) | ||
28 | 164 | { | ||
29 | 165 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_uint64(value)); | ||
30 | 166 | return *this; | ||
31 | 167 | } | ||
32 | 168 | |||
33 | 169 | BuilderWrapper& BuilderWrapper::add(char const* name, long long unsigned int value) | ||
34 | 170 | { | ||
35 | 171 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_uint64(value)); | ||
36 | 172 | return *this; | ||
37 | 173 | } | ||
38 | 174 | |||
39 | 151 | BuilderWrapper& BuilderWrapper::add(char const* name, float value) | 175 | BuilderWrapper& BuilderWrapper::add(char const* name, float value) |
40 | 152 | { | 176 | { |
42 | 153 | // floats get promoted to doubles automatically | 177 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_double(value)); |
43 | 178 | return *this; | ||
44 | 179 | } | ||
45 | 180 | |||
46 | 181 | BuilderWrapper& BuilderWrapper::add(char const* name, double value) | ||
47 | 182 | { | ||
48 | 154 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_double(value)); | 183 | g_variant_builder_add(builder_, "{sv}", name, g_variant_new_double(value)); |
49 | 155 | return *this; | 184 | return *this; |
50 | 156 | } | 185 | } |
51 | 157 | 186 | ||
52 | === modified file 'UnityCore/Variant.h' | |||
53 | --- UnityCore/Variant.h 2012-03-21 12:31:11 +0000 | |||
54 | +++ UnityCore/Variant.h 2012-04-05 23:42:20 +0000 | |||
55 | @@ -73,8 +73,13 @@ | |||
56 | 73 | BuilderWrapper& add(char const* name, char const* value); | 73 | BuilderWrapper& add(char const* name, char const* value); |
57 | 74 | BuilderWrapper& add(char const* name, std::string const& value); | 74 | BuilderWrapper& add(char const* name, std::string const& value); |
58 | 75 | BuilderWrapper& add(char const* name, int value); | 75 | BuilderWrapper& add(char const* name, int value); |
60 | 76 | BuilderWrapper& add(char const* name, unsigned value); | 76 | BuilderWrapper& add(char const* name, long int value); |
61 | 77 | BuilderWrapper& add(char const* name, long long int value); | ||
62 | 78 | BuilderWrapper& add(char const* name, unsigned int value); | ||
63 | 79 | BuilderWrapper& add(char const* name, long unsigned int value); | ||
64 | 80 | BuilderWrapper& add(char const* name, long long unsigned int value); | ||
65 | 77 | BuilderWrapper& add(char const* name, float value); | 81 | BuilderWrapper& add(char const* name, float value); |
66 | 82 | BuilderWrapper& add(char const* name, double value); | ||
67 | 78 | BuilderWrapper& add(char const* name, GVariant* value); | 83 | BuilderWrapper& add(char const* name, GVariant* value); |
68 | 79 | BuilderWrapper& add(nux::Rect const& value); | 84 | BuilderWrapper& add(nux::Rect const& value); |
69 | 80 | 85 | ||
70 | 81 | 86 | ||
71 | === modified file 'plugins/unityshell/src/DashController.cpp' | |||
72 | --- plugins/unityshell/src/DashController.cpp 2012-03-21 12:31:11 +0000 | |||
73 | +++ plugins/unityshell/src/DashController.cpp 2012-04-05 23:42:20 +0000 | |||
74 | @@ -40,6 +40,7 @@ | |||
75 | 40 | Controller::Controller() | 40 | Controller::Controller() |
76 | 41 | : launcher_width(64) | 41 | : launcher_width(64) |
77 | 42 | , use_primary(false) | 42 | , use_primary(false) |
78 | 43 | , monitor_(0) | ||
79 | 43 | , window_(0) | 44 | , window_(0) |
80 | 44 | , visible_(false) | 45 | , visible_(false) |
81 | 45 | , need_show_(false) | 46 | , need_show_(false) |
82 | @@ -126,7 +127,7 @@ | |||
83 | 126 | g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, &overlay_identity, &can_maximise, &overlay_monitor); | 127 | g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, &overlay_identity, &can_maximise, &overlay_monitor); |
84 | 127 | 128 | ||
85 | 128 | // hide if something else is coming up | 129 | // hide if something else is coming up |
87 | 129 | if (g_strcmp0(overlay_identity, "dash")) | 130 | if (overlay_identity.Str() != "dash") |
88 | 130 | { | 131 | { |
89 | 131 | HideDash(true); | 132 | HideDash(true); |
90 | 132 | } | 133 | } |
91 | @@ -272,7 +273,8 @@ | |||
92 | 272 | 273 | ||
93 | 273 | StartShowHideTimeline(); | 274 | StartShowHideTimeline(); |
94 | 274 | 275 | ||
96 | 275 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE, GetIdealMonitor()); | 276 | monitor_ = GetIdealMonitor(); |
97 | 277 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE, monitor_); | ||
98 | 276 | ubus_manager_.SendMessage(UBUS_OVERLAY_SHOWN, info); | 278 | ubus_manager_.SendMessage(UBUS_OVERLAY_SHOWN, info); |
99 | 277 | } | 279 | } |
100 | 278 | 280 | ||
101 | @@ -298,7 +300,7 @@ | |||
102 | 298 | 300 | ||
103 | 299 | StartShowHideTimeline(); | 301 | StartShowHideTimeline(); |
104 | 300 | 302 | ||
106 | 301 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE, GetIdealMonitor()); | 303 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE, monitor_); |
107 | 302 | ubus_manager_.SendMessage(UBUS_OVERLAY_HIDDEN, info); | 304 | ubus_manager_.SendMessage(UBUS_OVERLAY_HIDDEN, info); |
108 | 303 | } | 305 | } |
109 | 304 | 306 | ||
110 | 305 | 307 | ||
111 | === modified file 'plugins/unityshell/src/DashController.h' | |||
112 | --- plugins/unityshell/src/DashController.h 2012-03-27 22:34:53 +0000 | |||
113 | +++ plugins/unityshell/src/DashController.h 2012-04-05 23:42:20 +0000 | |||
114 | @@ -89,6 +89,7 @@ | |||
115 | 89 | private: | 89 | private: |
116 | 90 | glib::SignalManager sig_manager_; | 90 | glib::SignalManager sig_manager_; |
117 | 91 | UBusManager ubus_manager_; | 91 | UBusManager ubus_manager_; |
118 | 92 | int monitor_; | ||
119 | 92 | 93 | ||
120 | 93 | nux::BaseWindow* window_; | 94 | nux::BaseWindow* window_; |
121 | 94 | bool visible_; | 95 | bool visible_; |
122 | 95 | 96 | ||
123 | === modified file 'plugins/unityshell/src/LauncherController.cpp' | |||
124 | --- plugins/unityshell/src/LauncherController.cpp 2012-04-05 00:32:14 +0000 | |||
125 | +++ plugins/unityshell/src/LauncherController.cpp 2012-04-05 23:42:20 +0000 | |||
126 | @@ -1101,9 +1101,9 @@ | |||
127 | 1101 | void Controller::KeyNavGrab() | 1101 | void Controller::KeyNavGrab() |
128 | 1102 | { | 1102 | { |
129 | 1103 | pimpl->ubus.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); | 1103 | pimpl->ubus.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); |
130 | 1104 | pimpl->launcher_grabbed = true; | ||
131 | 1104 | KeyNavActivate(); | 1105 | KeyNavActivate(); |
132 | 1105 | pimpl->keyboard_launcher_->GrabKeyboard(); | 1106 | pimpl->keyboard_launcher_->GrabKeyboard(); |
133 | 1106 | pimpl->launcher_grabbed = true; | ||
134 | 1107 | 1107 | ||
135 | 1108 | pimpl->launcher_key_press_connection_ = | 1108 | pimpl->launcher_key_press_connection_ = |
136 | 1109 | pimpl->keyboard_launcher_->key_down.connect(sigc::mem_fun(pimpl, &Controller::Impl::ReceiveLauncherKeyPress)); | 1109 | pimpl->keyboard_launcher_->key_down.connect(sigc::mem_fun(pimpl, &Controller::Impl::ReceiveLauncherKeyPress)); |
137 | @@ -1124,18 +1124,50 @@ | |||
138 | 1124 | pimpl->keyboard_launcher_->EnterKeyNavMode(); | 1124 | pimpl->keyboard_launcher_->EnterKeyNavMode(); |
139 | 1125 | pimpl->model_->SetSelection(0); | 1125 | pimpl->model_->SetSelection(0); |
140 | 1126 | 1126 | ||
143 | 1127 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_START_KEY_SWTICHER, g_variant_new_boolean(true)); | 1127 | if (pimpl->launcher_grabbed) |
144 | 1128 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_START_KEY_NAV, NULL); | 1128 | { |
145 | 1129 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_START_KEY_NAV, | ||
146 | 1130 | g_variant_new_int32(pimpl->keyboard_launcher_->monitor)); | ||
147 | 1131 | } | ||
148 | 1132 | else | ||
149 | 1133 | { | ||
150 | 1134 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_START_KEY_SWTICHER, | ||
151 | 1135 | g_variant_new_int32(pimpl->keyboard_launcher_->monitor)); | ||
152 | 1136 | } | ||
153 | 1137 | |||
154 | 1138 | AbstractLauncherIcon::Ptr const& selected = pimpl->model_->Selection(); | ||
155 | 1139 | |||
156 | 1140 | if (selected) | ||
157 | 1141 | { | ||
158 | 1142 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED, | ||
159 | 1143 | g_variant_new_string(selected->tooltip_text().c_str())); | ||
160 | 1144 | } | ||
161 | 1129 | } | 1145 | } |
162 | 1130 | 1146 | ||
163 | 1131 | void Controller::KeyNavNext() | 1147 | void Controller::KeyNavNext() |
164 | 1132 | { | 1148 | { |
165 | 1133 | pimpl->model_->SelectNext(); | 1149 | pimpl->model_->SelectNext(); |
166 | 1150 | |||
167 | 1151 | AbstractLauncherIcon::Ptr const& selected = pimpl->model_->Selection(); | ||
168 | 1152 | |||
169 | 1153 | if (selected) | ||
170 | 1154 | { | ||
171 | 1155 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED, | ||
172 | 1156 | g_variant_new_string(selected->tooltip_text().c_str())); | ||
173 | 1157 | } | ||
174 | 1134 | } | 1158 | } |
175 | 1135 | 1159 | ||
176 | 1136 | void Controller::KeyNavPrevious() | 1160 | void Controller::KeyNavPrevious() |
177 | 1137 | { | 1161 | { |
178 | 1138 | pimpl->model_->SelectPrevious(); | 1162 | pimpl->model_->SelectPrevious(); |
179 | 1163 | |||
180 | 1164 | AbstractLauncherIcon::Ptr const& selected = pimpl->model_->Selection(); | ||
181 | 1165 | |||
182 | 1166 | if (selected) | ||
183 | 1167 | { | ||
184 | 1168 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_SELECTION_CHANGED, | ||
185 | 1169 | g_variant_new_string(selected->tooltip_text().c_str())); | ||
186 | 1170 | } | ||
187 | 1139 | } | 1171 | } |
188 | 1140 | 1172 | ||
189 | 1141 | void Controller::KeyNavTerminate(bool activate) | 1173 | void Controller::KeyNavTerminate(bool activate) |
190 | @@ -1143,13 +1175,28 @@ | |||
191 | 1143 | if (!pimpl->launcher_keynav) | 1175 | if (!pimpl->launcher_keynav) |
192 | 1144 | return; | 1176 | return; |
193 | 1145 | 1177 | ||
194 | 1178 | if (activate && pimpl->keynav_restore_window_) | ||
195 | 1179 | { | ||
196 | 1180 | /* If the selected icon is running, we must not restore the input to the old */ | ||
197 | 1181 | AbstractLauncherIcon::Ptr const& icon = pimpl->model_->Selection(); | ||
198 | 1182 | pimpl->keynav_restore_window_ = !icon->GetQuirk(AbstractLauncherIcon::QUIRK_RUNNING); | ||
199 | 1183 | } | ||
200 | 1184 | |||
201 | 1146 | pimpl->keyboard_launcher_->ExitKeyNavMode(); | 1185 | pimpl->keyboard_launcher_->ExitKeyNavMode(); |
202 | 1186 | |||
203 | 1147 | if (pimpl->launcher_grabbed) | 1187 | if (pimpl->launcher_grabbed) |
204 | 1148 | { | 1188 | { |
205 | 1149 | pimpl->keyboard_launcher_->UnGrabKeyboard(); | 1189 | pimpl->keyboard_launcher_->UnGrabKeyboard(); |
206 | 1150 | pimpl->launcher_key_press_connection_.disconnect(); | 1190 | pimpl->launcher_key_press_connection_.disconnect(); |
207 | 1151 | pimpl->launcher_event_outside_connection_.disconnect(); | 1191 | pimpl->launcher_event_outside_connection_.disconnect(); |
208 | 1152 | pimpl->launcher_grabbed = false; | 1192 | pimpl->launcher_grabbed = false; |
209 | 1193 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV, | ||
210 | 1194 | g_variant_new_boolean(pimpl->keynav_restore_window_)); | ||
211 | 1195 | } | ||
212 | 1196 | else | ||
213 | 1197 | { | ||
214 | 1198 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_END_KEY_SWTICHER, | ||
215 | 1199 | g_variant_new_boolean(pimpl->keynav_restore_window_)); | ||
216 | 1153 | } | 1200 | } |
217 | 1154 | 1201 | ||
218 | 1155 | if (activate) | 1202 | if (activate) |
219 | @@ -1158,9 +1205,6 @@ | |||
220 | 1158 | pimpl->launcher_keynav = false; | 1205 | pimpl->launcher_keynav = false; |
221 | 1159 | if (!pimpl->launcher_open) | 1206 | if (!pimpl->launcher_open) |
222 | 1160 | pimpl->keyboard_launcher_.Release(); | 1207 | pimpl->keyboard_launcher_.Release(); |
223 | 1161 | |||
224 | 1162 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_END_KEY_SWTICHER, g_variant_new_boolean(true)); | ||
225 | 1163 | pimpl->ubus.SendMessage(UBUS_LAUNCHER_END_KEY_NAV, g_variant_new_boolean(pimpl->keynav_restore_window_)); | ||
226 | 1164 | } | 1208 | } |
227 | 1165 | 1209 | ||
228 | 1166 | bool Controller::KeyNavIsActive() const | 1210 | bool Controller::KeyNavIsActive() const |
229 | @@ -1260,8 +1304,7 @@ | |||
230 | 1260 | // <RETURN> (start/activate currently selected icon) | 1304 | // <RETURN> (start/activate currently selected icon) |
231 | 1261 | case NUX_VK_ENTER: | 1305 | case NUX_VK_ENTER: |
232 | 1262 | case NUX_KP_ENTER: | 1306 | case NUX_KP_ENTER: |
235 | 1263 | model_->Selection()->Activate(ActionArg(ActionArg::LAUNCHER, 0)); | 1307 | parent_->KeyNavTerminate(true); |
234 | 1264 | parent_->KeyNavTerminate(false); | ||
236 | 1265 | break; | 1308 | break; |
237 | 1266 | 1309 | ||
238 | 1267 | default: | 1310 | default: |
239 | 1268 | 1311 | ||
240 | === modified file 'plugins/unityshell/src/PanelController.cpp' | |||
241 | --- plugins/unityshell/src/PanelController.cpp 2012-03-22 19:33:10 +0000 | |||
242 | +++ plugins/unityshell/src/PanelController.cpp 2012-04-05 23:42:20 +0000 | |||
243 | @@ -26,6 +26,7 @@ | |||
244 | 26 | 26 | ||
245 | 27 | #include "UScreen.h" | 27 | #include "UScreen.h" |
246 | 28 | #include "PanelView.h" | 28 | #include "PanelView.h" |
247 | 29 | #include "PanelStyle.h" | ||
248 | 29 | 30 | ||
249 | 30 | namespace unity | 31 | namespace unity |
250 | 31 | { | 32 | { |
251 | @@ -46,8 +47,8 @@ | |||
252 | 46 | void FirstMenuShow(); | 47 | void FirstMenuShow(); |
253 | 47 | void QueueRedraw(); | 48 | void QueueRedraw(); |
254 | 48 | 49 | ||
257 | 49 | unsigned int GetTrayXid(); | 50 | std::vector<Window> GetTrayXids() const; |
258 | 50 | std::list <nux::Geometry> GetGeometries(); | 51 | std::vector<nux::Geometry> GetGeometries() const; |
259 | 51 | 52 | ||
260 | 52 | // NOTE: nux::Property maybe? | 53 | // NOTE: nux::Property maybe? |
261 | 53 | void SetOpacity(float opacity); | 54 | void SetOpacity(float opacity); |
262 | @@ -60,7 +61,7 @@ | |||
263 | 60 | 61 | ||
264 | 61 | void OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors, Introspectable *iobj); | 62 | void OnScreenChanged(int primary_monitor, std::vector<nux::Geometry>& monitors, Introspectable *iobj); |
265 | 62 | private: | 63 | private: |
267 | 63 | unity::PanelView* ViewForWindow(nux::BaseWindow* window); | 64 | unity::PanelView* ViewForWindow(nux::BaseWindow* window) const; |
268 | 64 | 65 | ||
269 | 65 | static void WindowConfigureCallback(int window_width, | 66 | static void WindowConfigureCallback(int window_width, |
270 | 66 | int window_height, | 67 | int window_height, |
271 | @@ -98,17 +99,21 @@ | |||
272 | 98 | } | 99 | } |
273 | 99 | } | 100 | } |
274 | 100 | 101 | ||
276 | 101 | unsigned int Controller::Impl::GetTrayXid() | 102 | std::vector<Window> Controller::Impl::GetTrayXids() const |
277 | 102 | { | 103 | { |
282 | 103 | if (!windows_.empty()) | 104 | std::vector<Window> xids; |
283 | 104 | return ViewForWindow(windows_.front())->GetTrayXid(); | 105 | |
284 | 105 | else | 106 | for (auto window: windows_) |
285 | 106 | return 0; | 107 | { |
286 | 108 | xids.push_back(ViewForWindow(window)->GetTrayXid()); | ||
287 | 109 | } | ||
288 | 110 | |||
289 | 111 | return xids; | ||
290 | 107 | } | 112 | } |
291 | 108 | 113 | ||
293 | 109 | std::list<nux::Geometry> Controller::Impl::GetGeometries() | 114 | std::vector<nux::Geometry> Controller::Impl::GetGeometries() const |
294 | 110 | { | 115 | { |
296 | 111 | std::list<nux::Geometry> geometries; | 116 | std::vector<nux::Geometry> geometries; |
297 | 112 | 117 | ||
298 | 113 | for (auto window : windows_) | 118 | for (auto window : windows_) |
299 | 114 | { | 119 | { |
300 | @@ -171,7 +176,7 @@ | |||
301 | 171 | } | 176 | } |
302 | 172 | } | 177 | } |
303 | 173 | 178 | ||
305 | 174 | PanelView* Controller::Impl::ViewForWindow(nux::BaseWindow* window) | 179 | PanelView* Controller::Impl::ViewForWindow(nux::BaseWindow* window) const |
306 | 175 | { | 180 | { |
307 | 176 | nux::Layout* layout = window->GetLayout(); | 181 | nux::Layout* layout = window->GetLayout(); |
308 | 177 | std::list<nux::Area*>::iterator it = layout->GetChildren().begin(); | 182 | std::list<nux::Area*>::iterator it = layout->GetChildren().begin(); |
309 | @@ -198,8 +203,9 @@ | |||
310 | 198 | (*it)->InputWindowEnableStruts(false); | 203 | (*it)->InputWindowEnableStruts(false); |
311 | 199 | 204 | ||
312 | 200 | nux::Geometry geo = monitors[i]; | 205 | nux::Geometry geo = monitors[i]; |
314 | 201 | geo.height = 24; | 206 | geo.height = panel::Style::Instance().panel_height; |
315 | 202 | (*it)->SetGeometry(geo); | 207 | (*it)->SetGeometry(geo); |
316 | 208 | (*it)->SetMinMaxSize(geo.width, geo.height); | ||
317 | 203 | 209 | ||
318 | 204 | view = ViewForWindow(*it); | 210 | view = ViewForWindow(*it); |
319 | 205 | view->SetPrimary(i == primary_monitor); | 211 | view->SetPrimary(i == primary_monitor); |
320 | @@ -224,7 +230,7 @@ | |||
321 | 224 | nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION); | 230 | nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION); |
322 | 225 | 231 | ||
323 | 226 | PanelView* view = new PanelView(); | 232 | PanelView* view = new PanelView(); |
325 | 227 | view->SetMaximumHeight(24); | 233 | view->SetMaximumHeight(panel::Style::Instance().panel_height); |
326 | 228 | view->SetOpacity(opacity_); | 234 | view->SetOpacity(opacity_); |
327 | 229 | view->SetOpacityMaximizedToggle(opacity_maximized_toggle_); | 235 | view->SetOpacityMaximizedToggle(opacity_maximized_toggle_); |
328 | 230 | view->SetMenuShowTimings(menus_fadein_, menus_fadeout_, menus_discovery_, | 236 | view->SetMenuShowTimings(menus_fadein_, menus_fadeout_, menus_discovery_, |
329 | @@ -238,17 +244,18 @@ | |||
330 | 238 | layout->SetHorizontalExternalMargin(0); | 244 | layout->SetHorizontalExternalMargin(0); |
331 | 239 | 245 | ||
332 | 240 | nux::BaseWindow* window = new nux::BaseWindow(""); | 246 | nux::BaseWindow* window = new nux::BaseWindow(""); |
333 | 247 | nux::Geometry geo = monitors[i]; | ||
334 | 248 | geo.height = panel::Style::Instance().panel_height; | ||
335 | 249 | |||
336 | 241 | window->SinkReference(); | 250 | window->SinkReference(); |
337 | 242 | window->SetConfigureNotifyCallback(&Impl::WindowConfigureCallback, window); | 251 | window->SetConfigureNotifyCallback(&Impl::WindowConfigureCallback, window); |
338 | 243 | window->SetLayout(layout); | ||
339 | 244 | window->SetBackgroundColor(nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); | 252 | window->SetBackgroundColor(nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); |
340 | 245 | window->ShowWindow(true); | 253 | window->ShowWindow(true); |
341 | 246 | window->EnableInputWindow(true, "panel", false, false); | 254 | window->EnableInputWindow(true, "panel", false, false); |
342 | 247 | window->InputWindowEnableStruts(true); | 255 | window->InputWindowEnableStruts(true); |
343 | 248 | |||
344 | 249 | nux::Geometry geo = monitors[i]; | ||
345 | 250 | geo.height = 24; | ||
346 | 251 | window->SetGeometry(geo); | 256 | window->SetGeometry(geo); |
347 | 257 | window->SetMinMaxSize(geo.width, geo.height); | ||
348 | 258 | window->SetLayout(layout); | ||
349 | 252 | 259 | ||
350 | 253 | windows_.push_back(window); | 260 | windows_.push_back(window); |
351 | 254 | 261 | ||
352 | @@ -325,12 +332,12 @@ | |||
353 | 325 | pimpl->QueueRedraw(); | 332 | pimpl->QueueRedraw(); |
354 | 326 | } | 333 | } |
355 | 327 | 334 | ||
357 | 328 | unsigned int Controller::GetTrayXid() | 335 | std::vector<Window> Controller::GetTrayXids() const |
358 | 329 | { | 336 | { |
360 | 330 | return pimpl->GetTrayXid(); | 337 | return pimpl->GetTrayXids(); |
361 | 331 | } | 338 | } |
362 | 332 | 339 | ||
364 | 333 | std::list<nux::Geometry> Controller::GetGeometries() | 340 | std::vector<nux::Geometry> Controller::GetGeometries() const |
365 | 334 | { | 341 | { |
366 | 335 | return pimpl->GetGeometries(); | 342 | return pimpl->GetGeometries(); |
367 | 336 | } | 343 | } |
368 | 337 | 344 | ||
369 | === modified file 'plugins/unityshell/src/PanelController.h' | |||
370 | --- plugins/unityshell/src/PanelController.h 2012-03-22 19:33:10 +0000 | |||
371 | +++ plugins/unityshell/src/PanelController.h 2012-04-05 23:42:20 +0000 | |||
372 | @@ -20,9 +20,7 @@ | |||
373 | 20 | #ifndef _PANEL_CONTROLLER_H_ | 20 | #ifndef _PANEL_CONTROLLER_H_ |
374 | 21 | #define _PANEL_CONTROLLER_H_ | 21 | #define _PANEL_CONTROLLER_H_ |
375 | 22 | 22 | ||
376 | 23 | #include <list> | ||
377 | 24 | #include <memory> | 23 | #include <memory> |
378 | 25 | |||
379 | 26 | #include <Nux/Nux.h> | 24 | #include <Nux/Nux.h> |
380 | 27 | 25 | ||
381 | 28 | #include "Introspectable.h" | 26 | #include "Introspectable.h" |
382 | @@ -42,8 +40,8 @@ | |||
383 | 42 | void FirstMenuShow(); | 40 | void FirstMenuShow(); |
384 | 43 | void QueueRedraw(); | 41 | void QueueRedraw(); |
385 | 44 | 42 | ||
388 | 45 | unsigned int GetTrayXid (); | 43 | std::vector<Window> GetTrayXids() const; |
389 | 46 | std::list<nux::Geometry> GetGeometries (); | 44 | std::vector<nux::Geometry> GetGeometries() const; |
390 | 47 | 45 | ||
391 | 48 | // NOTE: nux::Property maybe? | 46 | // NOTE: nux::Property maybe? |
392 | 49 | void SetOpacity(float opacity); | 47 | void SetOpacity(float opacity); |
393 | 50 | 48 | ||
394 | === modified file 'plugins/unityshell/src/PanelIndicatorEntryView.cpp' | |||
395 | --- plugins/unityshell/src/PanelIndicatorEntryView.cpp 2012-04-03 03:40:06 +0000 | |||
396 | +++ plugins/unityshell/src/PanelIndicatorEntryView.cpp 2012-04-05 23:42:20 +0000 | |||
397 | @@ -1,6 +1,6 @@ | |||
398 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
399 | 2 | /* | 2 | /* |
401 | 3 | * Copyright (C) 2010 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
402 | 4 | * | 4 | * |
403 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
404 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
405 | @@ -15,6 +15,7 @@ | |||
406 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
407 | 16 | * | 16 | * |
408 | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
409 | 18 | * Marco Trevisan (Treviño) <3v1n0@ubuntu.com> | ||
410 | 18 | */ | 19 | */ |
411 | 19 | 20 | ||
412 | 20 | #include <Nux/Nux.h> | 21 | #include <Nux/Nux.h> |
413 | @@ -24,22 +25,18 @@ | |||
414 | 24 | #include <NuxGraphics/GLThread.h> | 25 | #include <NuxGraphics/GLThread.h> |
415 | 25 | #include <Nux/BaseWindow.h> | 26 | #include <Nux/BaseWindow.h> |
416 | 26 | #include <Nux/WindowCompositor.h> | 27 | #include <Nux/WindowCompositor.h> |
419 | 27 | 28 | #include <UnityCore/Variant.h> | |
418 | 28 | #include <boost/algorithm/string.hpp> | ||
420 | 29 | 29 | ||
421 | 30 | #include <glib.h> | 30 | #include <glib.h> |
422 | 31 | #include <pango/pangocairo.h> | ||
423 | 32 | #include <gdk-pixbuf/gdk-pixbuf.h> | 31 | #include <gdk-pixbuf/gdk-pixbuf.h> |
424 | 33 | #include <gtk/gtk.h> | 32 | #include <gtk/gtk.h> |
425 | 34 | #include <time.h> | 33 | #include <time.h> |
426 | 34 | #include <boost/algorithm/string.hpp> | ||
427 | 35 | 35 | ||
428 | 36 | #include "CairoTexture.h" | 36 | #include "CairoTexture.h" |
429 | 37 | // TODO: this include should be at the top, but it fails :( | ||
430 | 38 | #include "PanelIndicatorEntryView.h" | 37 | #include "PanelIndicatorEntryView.h" |
431 | 39 | |||
432 | 40 | #include "PanelStyle.h" | 38 | #include "PanelStyle.h" |
435 | 41 | #include <UnityCore/GLibWrapper.h> | 39 | #include "WindowManager.h" |
434 | 42 | #include <UnityCore/Variant.h> | ||
436 | 43 | 40 | ||
437 | 44 | 41 | ||
438 | 45 | namespace unity | 42 | namespace unity |
439 | @@ -47,52 +44,45 @@ | |||
440 | 47 | 44 | ||
441 | 48 | namespace | 45 | namespace |
442 | 49 | { | 46 | { |
447 | 50 | void draw_menu_bg(cairo_t* cr, int width, int height); | 47 | const int DEFAULT_SPACING = 3; |
444 | 51 | GdkPixbuf* make_pixbuf(int image_type, std::string const& image_data, bool dash_showing); | ||
445 | 52 | const int PANEL_HEIGHT = 24; | ||
446 | 53 | const int SPACING = 3; | ||
448 | 54 | } | 48 | } |
449 | 55 | 49 | ||
450 | 50 | using namespace indicator; | ||
451 | 56 | 51 | ||
456 | 57 | PanelIndicatorEntryView::PanelIndicatorEntryView( | 52 | PanelIndicatorEntryView::PanelIndicatorEntryView(Entry::Ptr const& proxy, int padding, |
457 | 58 | indicator::Entry::Ptr const& proxy, | 53 | IndicatorEntryType type) |
454 | 59 | int padding, | ||
455 | 60 | IndicatorEntryType type) | ||
458 | 61 | : TextureArea(NUX_TRACKER_LOCATION) | 54 | : TextureArea(NUX_TRACKER_LOCATION) |
459 | 62 | , proxy_(proxy) | 55 | , proxy_(proxy) |
460 | 56 | , spacing_(DEFAULT_SPACING) | ||
461 | 57 | , left_padding_(padding < 0 ? 0 : padding) | ||
462 | 58 | , right_padding_(left_padding_) | ||
463 | 63 | , type_(type) | 59 | , type_(type) |
467 | 64 | , util_cg_(CAIRO_FORMAT_ARGB32, 1, 1) | 60 | , entry_texture_(nullptr) |
465 | 65 | , texture_layer_(NULL) | ||
466 | 66 | , padding_(padding < 0 ? 0 : padding) | ||
468 | 67 | , opacity_(1.0f) | 61 | , opacity_(1.0f) |
469 | 68 | , draw_active_(false) | 62 | , draw_active_(false) |
471 | 69 | , dash_showing_(false) | 63 | , overlay_showing_(false) |
472 | 70 | , disabled_(false) | 64 | , disabled_(false) |
473 | 65 | , focused_(true) | ||
474 | 71 | { | 66 | { |
479 | 72 | on_indicator_activate_changed_connection_ = proxy_->active_changed.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnActiveChanged)); | 67 | proxy_->active_changed.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnActiveChanged)); |
480 | 73 | on_indicator_updated_connection_ = proxy_->updated.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::Refresh)); | 68 | proxy_->updated.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::Refresh)); |
477 | 74 | |||
478 | 75 | on_font_changed_connection_ = g_signal_connect(gtk_settings_get_default(), "notify::gtk-font-name", (GCallback) &PanelIndicatorEntryView::OnFontChanged, this); | ||
481 | 76 | 69 | ||
482 | 77 | InputArea::mouse_down.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnMouseDown)); | 70 | InputArea::mouse_down.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnMouseDown)); |
483 | 78 | InputArea::mouse_up.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnMouseUp)); | 71 | InputArea::mouse_up.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnMouseUp)); |
484 | 79 | 72 | ||
485 | 80 | InputArea::SetAcceptMouseWheelEvent(true); | 73 | InputArea::SetAcceptMouseWheelEvent(true); |
486 | 74 | |||
487 | 81 | if (type_ != MENU) | 75 | if (type_ != MENU) |
488 | 82 | InputArea::mouse_wheel.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnMouseWheel)); | 76 | InputArea::mouse_wheel.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnMouseWheel)); |
489 | 83 | 77 | ||
491 | 84 | on_panelstyle_changed_connection_ = panel::Style::Instance().changed.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::Refresh)); | 78 | panel::Style::Instance().changed.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::Refresh)); |
492 | 79 | |||
493 | 85 | Refresh(); | 80 | Refresh(); |
494 | 86 | } | 81 | } |
495 | 87 | 82 | ||
496 | 88 | PanelIndicatorEntryView::~PanelIndicatorEntryView() | 83 | PanelIndicatorEntryView::~PanelIndicatorEntryView() |
497 | 89 | { | 84 | { |
504 | 90 | on_indicator_activate_changed_connection_.disconnect(); | 85 | // Nothing to do... |
499 | 91 | on_indicator_updated_connection_.disconnect(); | ||
500 | 92 | on_panelstyle_changed_connection_.disconnect(); | ||
501 | 93 | g_signal_handler_disconnect(gtk_settings_get_default(), on_font_changed_connection_); | ||
502 | 94 | if (texture_layer_) | ||
503 | 95 | delete texture_layer_; | ||
505 | 96 | } | 86 | } |
506 | 97 | 87 | ||
507 | 98 | void PanelIndicatorEntryView::OnActiveChanged(bool is_active) | 88 | void PanelIndicatorEntryView::OnActiveChanged(bool is_active) |
508 | @@ -108,10 +98,15 @@ | |||
509 | 108 | 98 | ||
510 | 109 | void PanelIndicatorEntryView::ShowMenu(int button) | 99 | void PanelIndicatorEntryView::ShowMenu(int button) |
511 | 110 | { | 100 | { |
516 | 111 | proxy_->ShowMenu(GetAbsoluteX(), | 101 | auto wm = WindowManager::Default(); |
517 | 112 | GetAbsoluteY() + PANEL_HEIGHT, | 102 | |
518 | 113 | button, | 103 | if (!wm->IsExpoActive() && !wm->IsScaleActive()) |
519 | 114 | time(NULL)); | 104 | { |
520 | 105 | proxy_->ShowMenu(GetAbsoluteX(), | ||
521 | 106 | GetAbsoluteY() + panel::Style::Instance().panel_height, | ||
522 | 107 | button, | ||
523 | 108 | time(nullptr)); | ||
524 | 109 | } | ||
525 | 115 | } | 110 | } |
526 | 116 | 111 | ||
527 | 117 | void PanelIndicatorEntryView::OnMouseDown(int x, int y, long button_flags, long key_flags) | 112 | void PanelIndicatorEntryView::OnMouseDown(int x, int y, long button_flags, long key_flags) |
528 | @@ -119,8 +114,8 @@ | |||
529 | 119 | if (proxy_->active() || IsDisabled()) | 114 | if (proxy_->active() || IsDisabled()) |
530 | 120 | return; | 115 | return; |
531 | 121 | 116 | ||
534 | 122 | if (((proxy_->label_visible() && proxy_->label_sensitive()) || | 117 | if (((IsLabelVisible() && IsLabelSensitive()) || |
535 | 123 | (proxy_->image_visible() && proxy_->image_sensitive()))) | 118 | (IsIconVisible() && IsIconSensitive()))) |
536 | 124 | { | 119 | { |
537 | 125 | int button = nux::GetEventButton(button_flags); | 120 | int button = nux::GetEventButton(button_flags); |
538 | 126 | 121 | ||
539 | @@ -144,12 +139,12 @@ | |||
540 | 144 | int px = geo.x + x; | 139 | int px = geo.x + x; |
541 | 145 | int py = geo.y + y; | 140 | int py = geo.y + y; |
542 | 146 | 141 | ||
546 | 147 | if (((proxy_->label_visible() && proxy_->label_sensitive()) || | 142 | if (((IsLabelVisible() && IsLabelSensitive()) || |
547 | 148 | (proxy_->image_visible() && proxy_->image_sensitive())) && | 143 | (IsIconVisible() && IsIconSensitive())) && |
548 | 149 | button == 2 && type_ == INDICATOR) | 144 | button == 2 && type_ == INDICATOR) |
549 | 150 | { | 145 | { |
550 | 151 | if (geo.IsPointInside(px, py)) | 146 | if (geo.IsPointInside(px, py)) |
552 | 152 | proxy_->SecondaryActivate(time(NULL)); | 147 | proxy_->SecondaryActivate(time(nullptr)); |
553 | 153 | 148 | ||
554 | 154 | SetOpacity(1.0f); | 149 | SetOpacity(1.0f); |
555 | 155 | } | 150 | } |
556 | @@ -187,78 +182,290 @@ | |||
557 | 187 | } | 182 | } |
558 | 188 | } | 183 | } |
559 | 189 | 184 | ||
560 | 185 | glib::Object<GdkPixbuf> PanelIndicatorEntryView::MakePixbuf() | ||
561 | 186 | { | ||
562 | 187 | glib::Object<GdkPixbuf> pixbuf; | ||
563 | 188 | GtkIconTheme* theme = gtk_icon_theme_get_default(); | ||
564 | 189 | int image_type = proxy_->image_type(); | ||
565 | 190 | |||
566 | 191 | if (image_type == GTK_IMAGE_PIXBUF) | ||
567 | 192 | { | ||
568 | 193 | gsize len = 0; | ||
569 | 194 | guchar* decoded = g_base64_decode(proxy_->image_data().c_str(), &len); | ||
570 | 195 | |||
571 | 196 | glib::Object<GInputStream> stream(g_memory_input_stream_new_from_data(decoded, | ||
572 | 197 | len, | ||
573 | 198 | nullptr)); | ||
574 | 199 | |||
575 | 200 | pixbuf = gdk_pixbuf_new_from_stream(stream, nullptr, nullptr); | ||
576 | 201 | |||
577 | 202 | g_free(decoded); | ||
578 | 203 | g_input_stream_close(stream, nullptr, nullptr); | ||
579 | 204 | } | ||
580 | 205 | else if (image_type == GTK_IMAGE_STOCK || | ||
581 | 206 | image_type == GTK_IMAGE_ICON_NAME) | ||
582 | 207 | { | ||
583 | 208 | pixbuf = gtk_icon_theme_load_icon(theme, proxy_->image_data().c_str(), 22, | ||
584 | 209 | (GtkIconLookupFlags)0, nullptr); | ||
585 | 210 | } | ||
586 | 211 | else if (image_type == GTK_IMAGE_GICON) | ||
587 | 212 | { | ||
588 | 213 | glib::Object<GIcon> icon(g_icon_new_for_string(proxy_->image_data().c_str(), nullptr)); | ||
589 | 214 | |||
590 | 215 | GtkIconInfo* info = gtk_icon_theme_lookup_by_gicon(theme, icon, 22, | ||
591 | 216 | (GtkIconLookupFlags)0); | ||
592 | 217 | if (info) | ||
593 | 218 | { | ||
594 | 219 | pixbuf = gtk_icon_info_load_icon(info, nullptr); | ||
595 | 220 | gtk_icon_info_free(info); | ||
596 | 221 | } | ||
597 | 222 | } | ||
598 | 223 | |||
599 | 224 | return pixbuf; | ||
600 | 225 | } | ||
601 | 226 | |||
602 | 227 | void PanelIndicatorEntryView::DrawEntryPrelight(cairo_t* cr, unsigned int width, unsigned int height) | ||
603 | 228 | { | ||
604 | 229 | GtkStyleContext* style_context = panel::Style::Instance().GetStyleContext(); | ||
605 | 230 | |||
606 | 231 | gtk_style_context_save(style_context); | ||
607 | 232 | |||
608 | 233 | GtkWidgetPath* widget_path = gtk_widget_path_new(); | ||
609 | 234 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | ||
610 | 235 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); | ||
611 | 236 | gtk_widget_path_iter_set_name(widget_path, -1 , "UnityPanelWidget"); | ||
612 | 237 | |||
613 | 238 | gtk_style_context_set_path(style_context, widget_path); | ||
614 | 239 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); | ||
615 | 240 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); | ||
616 | 241 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_PRELIGHT); | ||
617 | 242 | |||
618 | 243 | gtk_render_background(style_context, cr, 0, 0, width, height); | ||
619 | 244 | gtk_render_frame(style_context, cr, 0, 0, width, height); | ||
620 | 245 | |||
621 | 246 | gtk_widget_path_free(widget_path); | ||
622 | 247 | |||
623 | 248 | gtk_style_context_restore(style_context); | ||
624 | 249 | } | ||
625 | 250 | |||
626 | 251 | void PanelIndicatorEntryView::DrawEntryContent(cairo_t *cr, unsigned int width, unsigned int height, glib::Object<GdkPixbuf> const& pixbuf, glib::Object<PangoLayout> const& layout) | ||
627 | 252 | { | ||
628 | 253 | int x = left_padding_; | ||
629 | 254 | |||
630 | 255 | if (IsActive()) | ||
631 | 256 | DrawEntryPrelight(cr, width, height); | ||
632 | 257 | |||
633 | 258 | if (pixbuf && IsIconVisible()) | ||
634 | 259 | { | ||
635 | 260 | GtkStyleContext* style_context = panel::Style::Instance().GetStyleContext(); | ||
636 | 261 | unsigned int icon_width = gdk_pixbuf_get_width(pixbuf); | ||
637 | 262 | |||
638 | 263 | gtk_style_context_save(style_context); | ||
639 | 264 | |||
640 | 265 | GtkWidgetPath* widget_path = gtk_widget_path_new(); | ||
641 | 266 | gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | ||
642 | 267 | pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); | ||
643 | 268 | gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); | ||
644 | 269 | |||
645 | 270 | gtk_style_context_set_path(style_context, widget_path); | ||
646 | 271 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); | ||
647 | 272 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); | ||
648 | 273 | |||
649 | 274 | if (!IsFocused()) | ||
650 | 275 | { | ||
651 | 276 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_BACKDROP); | ||
652 | 277 | } | ||
653 | 278 | else if (IsActive()) | ||
654 | 279 | { | ||
655 | 280 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_PRELIGHT); | ||
656 | 281 | } | ||
657 | 282 | |||
658 | 283 | int y = (int)((height - gdk_pixbuf_get_height(pixbuf)) / 2); | ||
659 | 284 | if (overlay_showing_ && !IsActive()) | ||
660 | 285 | { | ||
661 | 286 | /* Most of the images we get are straight pixbufs (annoyingly), so when | ||
662 | 287 | * the Overlay opens, we use the pixbuf as a mask to punch out an icon from | ||
663 | 288 | * a white square. It works surprisingly well for most symbolic-type | ||
664 | 289 | * icon themes/icons. | ||
665 | 290 | */ | ||
666 | 291 | cairo_save(cr); | ||
667 | 292 | |||
668 | 293 | cairo_push_group(cr); | ||
669 | 294 | gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | ||
670 | 295 | cairo_paint_with_alpha(cr, (IsIconSensitive() && IsFocused()) ? 1.0 : 0.5); | ||
671 | 296 | |||
672 | 297 | cairo_pattern_t* pat = cairo_pop_group(cr); | ||
673 | 298 | |||
674 | 299 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); | ||
675 | 300 | cairo_rectangle(cr, x, y, width, height); | ||
676 | 301 | cairo_mask(cr, pat); | ||
677 | 302 | |||
678 | 303 | cairo_pattern_destroy(pat); | ||
679 | 304 | cairo_restore(cr); | ||
680 | 305 | } | ||
681 | 306 | else | ||
682 | 307 | { | ||
683 | 308 | cairo_push_group(cr); | ||
684 | 309 | gtk_render_icon(style_context, cr, pixbuf, x, y); | ||
685 | 310 | cairo_pop_group_to_source(cr); | ||
686 | 311 | cairo_paint_with_alpha(cr, (IsIconSensitive() && IsFocused()) ? 1.0 : 0.5); | ||
687 | 312 | } | ||
688 | 313 | |||
689 | 314 | gtk_widget_path_free(widget_path); | ||
690 | 315 | |||
691 | 316 | gtk_style_context_restore(style_context); | ||
692 | 317 | |||
693 | 318 | x += icon_width + spacing_; | ||
694 | 319 | } | ||
695 | 320 | |||
696 | 321 | if (layout) | ||
697 | 322 | { | ||
698 | 323 | PangoRectangle log_rect; | ||
699 | 324 | pango_layout_get_extents(layout, nullptr, &log_rect); | ||
700 | 325 | unsigned int text_height = log_rect.height / PANGO_SCALE; | ||
701 | 326 | unsigned int text_width = log_rect.width / PANGO_SCALE; | ||
702 | 327 | |||
703 | 328 | pango_cairo_update_layout(cr, layout); | ||
704 | 329 | |||
705 | 330 | GtkStyleContext* style_context = panel::Style::Instance().GetStyleContext(); | ||
706 | 331 | |||
707 | 332 | gtk_style_context_save(style_context); | ||
708 | 333 | |||
709 | 334 | GtkWidgetPath* widget_path = gtk_widget_path_new(); | ||
710 | 335 | gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | ||
711 | 336 | pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); | ||
712 | 337 | gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); | ||
713 | 338 | |||
714 | 339 | gtk_style_context_set_path(style_context, widget_path); | ||
715 | 340 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); | ||
716 | 341 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); | ||
717 | 342 | |||
718 | 343 | if (!IsFocused()) | ||
719 | 344 | { | ||
720 | 345 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_BACKDROP); | ||
721 | 346 | } | ||
722 | 347 | else if (IsActive()) | ||
723 | 348 | { | ||
724 | 349 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_PRELIGHT); | ||
725 | 350 | } | ||
726 | 351 | |||
727 | 352 | int y = (height - text_height) / 2; | ||
728 | 353 | |||
729 | 354 | |||
730 | 355 | unsigned int text_space = GetMaximumWidth() - x - right_padding_; | ||
731 | 356 | |||
732 | 357 | if (text_width > text_space) | ||
733 | 358 | { | ||
734 | 359 | cairo_pattern_t* linpat; | ||
735 | 360 | int out_pixels = text_width - text_space; | ||
736 | 361 | const int fading_pixels = 15; | ||
737 | 362 | |||
738 | 363 | int fading_width = out_pixels < fading_pixels ? out_pixels : fading_pixels; | ||
739 | 364 | |||
740 | 365 | cairo_push_group(cr); | ||
741 | 366 | if (overlay_showing_) | ||
742 | 367 | { | ||
743 | 368 | cairo_move_to(cr, x, y); | ||
744 | 369 | cairo_set_source_rgb(cr, 1.0f, 1.0f, 1.0f); | ||
745 | 370 | pango_cairo_show_layout(cr, layout); | ||
746 | 371 | } | ||
747 | 372 | else | ||
748 | 373 | { | ||
749 | 374 | gtk_render_layout(style_context, cr, x, y, layout); | ||
750 | 375 | } | ||
751 | 376 | cairo_pop_group_to_source(cr); | ||
752 | 377 | |||
753 | 378 | int right_margin = width - right_padding_; | ||
754 | 379 | linpat = cairo_pattern_create_linear(right_margin - fading_width, y, right_margin, y); | ||
755 | 380 | cairo_pattern_add_color_stop_rgba(linpat, 0, 0, 0, 0, 1); | ||
756 | 381 | cairo_pattern_add_color_stop_rgba(linpat, 1, 0, 0, 0, 0); | ||
757 | 382 | cairo_mask(cr, linpat); | ||
758 | 383 | cairo_pattern_destroy(linpat); | ||
759 | 384 | } | ||
760 | 385 | else | ||
761 | 386 | { | ||
762 | 387 | if (overlay_showing_) | ||
763 | 388 | { | ||
764 | 389 | cairo_move_to(cr, x, y); | ||
765 | 390 | cairo_set_source_rgb(cr, 1.0f, 1.0f, 1.0f); | ||
766 | 391 | pango_cairo_show_layout(cr, layout); | ||
767 | 392 | } | ||
768 | 393 | else | ||
769 | 394 | { | ||
770 | 395 | gtk_render_layout(style_context, cr, x, y, layout); | ||
771 | 396 | } | ||
772 | 397 | } | ||
773 | 398 | |||
774 | 399 | gtk_widget_path_free(widget_path); | ||
775 | 400 | gtk_style_context_restore(style_context); | ||
776 | 401 | } | ||
777 | 402 | } | ||
778 | 403 | |||
779 | 190 | // We need to do a couple of things here: | 404 | // We need to do a couple of things here: |
780 | 191 | // 1. Figure out our width | 405 | // 1. Figure out our width |
781 | 192 | // 2. Figure out if we're active | 406 | // 2. Figure out if we're active |
782 | 193 | // 3. Paint something | 407 | // 3. Paint something |
783 | 194 | void PanelIndicatorEntryView::Refresh() | 408 | void PanelIndicatorEntryView::Refresh() |
784 | 195 | { | 409 | { |
786 | 196 | if (!IsVisible()) | 410 | if (!proxy_->visible()) |
787 | 197 | { | 411 | { |
788 | 198 | SetVisible(false); | 412 | SetVisible(false); |
789 | 413 | // This will destroy the object texture. No need to manually delete the pointer | ||
790 | 414 | entry_texture_ = nullptr; | ||
791 | 415 | SetColor(nux::color::Transparent); | ||
792 | 416 | |||
793 | 417 | QueueDraw(); | ||
794 | 418 | refreshed.emit(this); | ||
795 | 419 | |||
796 | 199 | return; | 420 | return; |
797 | 200 | } | 421 | } |
798 | 201 | 422 | ||
837 | 202 | SetVisible(true); | 423 | glib::Object<PangoLayout> layout; |
838 | 203 | 424 | cairo_t* cr; | |
839 | 204 | PangoLayout* layout = NULL; | 425 | |
840 | 205 | PangoFontDescription* desc = NULL; | 426 | std::string label = GetLabel(); |
841 | 206 | PangoAttrList* attrs = NULL; | 427 | glib::Object<GdkPixbuf> const& pixbuf = MakePixbuf(); |
842 | 207 | GtkSettings* settings = gtk_settings_get_default(); | 428 | |
843 | 208 | cairo_t* cr; | 429 | unsigned int width = 0; |
844 | 209 | char* font_description = NULL; | 430 | unsigned int icon_width = 0; |
845 | 210 | GdkScreen* screen = gdk_screen_get_default(); | 431 | unsigned int height = panel::Style::Instance().panel_height; |
846 | 211 | int dpi = 0; | 432 | unsigned int text_width = 0; |
809 | 212 | |||
810 | 213 | std::string label = proxy_->label(); | ||
811 | 214 | glib::Object<GdkPixbuf> pixbuf(make_pixbuf(proxy_->image_type(), | ||
812 | 215 | proxy_->image_data(), | ||
813 | 216 | dash_showing_)); | ||
814 | 217 | |||
815 | 218 | |||
816 | 219 | int x = 0; | ||
817 | 220 | int width = 0; | ||
818 | 221 | int height = PANEL_HEIGHT; | ||
819 | 222 | int icon_width = 0; | ||
820 | 223 | int text_width = 0; | ||
821 | 224 | int text_height = 0; | ||
822 | 225 | |||
823 | 226 | if (proxy_->show_now()) | ||
824 | 227 | { | ||
825 | 228 | if (!pango_parse_markup(label.c_str(), | ||
826 | 229 | -1, | ||
827 | 230 | '_', | ||
828 | 231 | &attrs, | ||
829 | 232 | NULL, | ||
830 | 233 | NULL, | ||
831 | 234 | NULL)) | ||
832 | 235 | { | ||
833 | 236 | g_debug("pango_parse_markup failed"); | ||
834 | 237 | } | ||
835 | 238 | } | ||
836 | 239 | boost::erase_all(label, "_"); | ||
847 | 240 | 433 | ||
848 | 241 | // First lets figure out our size | 434 | // First lets figure out our size |
850 | 242 | if (pixbuf && proxy_->image_visible()) | 435 | if (pixbuf && IsIconVisible()) |
851 | 243 | { | 436 | { |
852 | 244 | width = gdk_pixbuf_get_width(pixbuf); | 437 | width = gdk_pixbuf_get_width(pixbuf); |
853 | 245 | icon_width = width; | 438 | icon_width = width; |
854 | 246 | } | 439 | } |
855 | 247 | 440 | ||
857 | 248 | if (!label.empty() && proxy_->label_visible()) | 441 | if (!label.empty() && IsLabelVisible()) |
858 | 249 | { | 442 | { |
859 | 443 | using namespace panel; | ||
860 | 250 | PangoContext* cxt; | 444 | PangoContext* cxt; |
861 | 445 | PangoAttrList* attrs = nullptr; | ||
862 | 251 | PangoRectangle log_rect; | 446 | PangoRectangle log_rect; |
871 | 252 | 447 | GdkScreen* screen = gdk_screen_get_default(); | |
872 | 253 | cr = util_cg_.GetContext(); | 448 | PangoFontDescription* desc = nullptr; |
873 | 254 | 449 | PanelItem panel_item = (type_ == MENU) ? PanelItem::MENU : PanelItem::INDICATOR; | |
874 | 255 | g_object_get(settings, | 450 | |
875 | 256 | "gtk-font-name", &font_description, | 451 | Style& panel_style = Style::Instance(); |
876 | 257 | "gtk-xft-dpi", &dpi, | 452 | std::string const& font_description = panel_style.GetFontDescription(panel_item); |
877 | 258 | NULL); | 453 | int dpi = panel_style.GetTextDPI(); |
878 | 259 | desc = pango_font_description_from_string(font_description); | 454 | |
879 | 455 | if (proxy_->show_now()) | ||
880 | 456 | { | ||
881 | 457 | if (!pango_parse_markup(label.c_str(), -1, '_', &attrs, nullptr, nullptr, nullptr)) | ||
882 | 458 | { | ||
883 | 459 | g_debug("pango_parse_markup failed"); | ||
884 | 460 | } | ||
885 | 461 | } | ||
886 | 462 | |||
887 | 463 | desc = pango_font_description_from_string(font_description.c_str()); | ||
888 | 260 | pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); | 464 | pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); |
889 | 261 | 465 | ||
890 | 466 | nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, 1, 1); | ||
891 | 467 | cr = cairo_graphics.GetContext(); | ||
892 | 468 | |||
893 | 262 | layout = pango_cairo_create_layout(cr); | 469 | layout = pango_cairo_create_layout(cr); |
894 | 263 | if (attrs) | 470 | if (attrs) |
895 | 264 | { | 471 | { |
896 | @@ -267,198 +474,90 @@ | |||
897 | 267 | } | 474 | } |
898 | 268 | 475 | ||
899 | 269 | pango_layout_set_font_description(layout, desc); | 476 | pango_layout_set_font_description(layout, desc); |
900 | 477 | |||
901 | 478 | boost::erase_all(label, "_"); | ||
902 | 270 | pango_layout_set_text(layout, label.c_str(), -1); | 479 | pango_layout_set_text(layout, label.c_str(), -1); |
903 | 271 | 480 | ||
904 | 272 | cxt = pango_layout_get_context(layout); | 481 | cxt = pango_layout_get_context(layout); |
905 | 273 | pango_cairo_context_set_font_options(cxt, gdk_screen_get_font_options(screen)); | 482 | pango_cairo_context_set_font_options(cxt, gdk_screen_get_font_options(screen)); |
907 | 274 | pango_cairo_context_set_resolution(cxt, (float)dpi / (float)PANGO_SCALE); | 483 | pango_cairo_context_set_resolution(cxt, dpi / static_cast<float>(PANGO_SCALE)); |
908 | 275 | pango_layout_context_changed(layout); | 484 | pango_layout_context_changed(layout); |
909 | 276 | 485 | ||
911 | 277 | pango_layout_get_extents(layout, NULL, &log_rect); | 486 | pango_layout_get_extents(layout, nullptr, &log_rect); |
912 | 278 | text_width = log_rect.width / PANGO_SCALE; | 487 | text_width = log_rect.width / PANGO_SCALE; |
913 | 279 | text_height = log_rect.height / PANGO_SCALE; | ||
914 | 280 | 488 | ||
915 | 281 | if (icon_width) | 489 | if (icon_width) |
917 | 282 | width += SPACING; | 490 | width += spacing_; |
918 | 283 | width += text_width; | 491 | width += text_width; |
919 | 284 | 492 | ||
920 | 285 | pango_font_description_free(desc); | 493 | pango_font_description_free(desc); |
921 | 286 | g_free(font_description); | ||
922 | 287 | cairo_destroy(cr); | 494 | cairo_destroy(cr); |
923 | 288 | } | 495 | } |
924 | 289 | 496 | ||
925 | 290 | if (width) | 497 | if (width) |
927 | 291 | width += padding_ * 2; | 498 | width += left_padding_ + right_padding_; |
928 | 292 | 499 | ||
929 | 500 | width = std::min<int>(width, GetMaximumWidth()); | ||
930 | 293 | SetMinimumWidth(width); | 501 | SetMinimumWidth(width); |
931 | 294 | 502 | ||
934 | 295 | nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height); | 503 | nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height); |
935 | 296 | cr = cairo_graphics.GetContext(); | 504 | cr = cg.GetContext(); |
936 | 297 | cairo_set_line_width(cr, 1); | 505 | cairo_set_line_width(cr, 1); |
937 | 298 | |||
938 | 299 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); | 506 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
939 | 300 | cairo_paint(cr); | 507 | cairo_paint(cr); |
940 | 301 | 508 | ||
941 | 302 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | 509 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1041 | 303 | 510 | DrawEntryContent(cr, width, height, pixbuf, layout); | |
1042 | 304 | if (IsActive()) | 511 | |
1043 | 305 | draw_menu_bg(cr, width, height); | 512 | entry_texture_ = texture_from_cairo_graphics(cg); |
1044 | 306 | 513 | SetTexture(entry_texture_); | |
946 | 307 | x = padding_; | ||
947 | 308 | |||
948 | 309 | if (pixbuf && proxy_->image_visible()) | ||
949 | 310 | { | ||
950 | 311 | GtkStyleContext* style_context = panel::Style::Instance().GetStyleContext(); | ||
951 | 312 | |||
952 | 313 | gtk_style_context_save(style_context); | ||
953 | 314 | |||
954 | 315 | GtkWidgetPath* widget_path = gtk_widget_path_new(); | ||
955 | 316 | gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | ||
956 | 317 | pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); | ||
957 | 318 | gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); | ||
958 | 319 | |||
959 | 320 | gtk_style_context_set_path(style_context, widget_path); | ||
960 | 321 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); | ||
961 | 322 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); | ||
962 | 323 | |||
963 | 324 | if (IsActive()) | ||
964 | 325 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_PRELIGHT); | ||
965 | 326 | |||
966 | 327 | int y = (int)((height - gdk_pixbuf_get_height(pixbuf)) / 2); | ||
967 | 328 | if (dash_showing_ && !IsActive()) | ||
968 | 329 | { | ||
969 | 330 | /* Most of the images we get are straight pixbufs (annoyingly), so when | ||
970 | 331 | * the Dash opens, we use the pixbuf as a mask to punch out an icon from | ||
971 | 332 | * a white square. It works surprisingly well for most symbolic-type | ||
972 | 333 | * icon themes/icons. | ||
973 | 334 | */ | ||
974 | 335 | cairo_save(cr); | ||
975 | 336 | |||
976 | 337 | cairo_push_group(cr); | ||
977 | 338 | gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | ||
978 | 339 | cairo_paint_with_alpha(cr, proxy_->image_sensitive() ? 1.0 : 0.5); | ||
979 | 340 | |||
980 | 341 | cairo_pattern_t* pat = cairo_pop_group(cr); | ||
981 | 342 | |||
982 | 343 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); | ||
983 | 344 | cairo_rectangle(cr, x, y, width, height); | ||
984 | 345 | cairo_mask(cr, pat); | ||
985 | 346 | |||
986 | 347 | cairo_pattern_destroy(pat); | ||
987 | 348 | cairo_restore(cr); | ||
988 | 349 | } | ||
989 | 350 | else | ||
990 | 351 | { | ||
991 | 352 | cairo_push_group(cr); | ||
992 | 353 | gtk_render_icon(style_context, cr, pixbuf, x, y); | ||
993 | 354 | cairo_pop_group_to_source(cr); | ||
994 | 355 | cairo_paint_with_alpha(cr, proxy_->image_sensitive() ? 1.0 : 0.5); | ||
995 | 356 | } | ||
996 | 357 | |||
997 | 358 | gtk_widget_path_free(widget_path); | ||
998 | 359 | |||
999 | 360 | gtk_style_context_restore(style_context); | ||
1000 | 361 | |||
1001 | 362 | x += icon_width + SPACING; | ||
1002 | 363 | } | ||
1003 | 364 | |||
1004 | 365 | if (!label.empty() && proxy_->label_visible()) | ||
1005 | 366 | { | ||
1006 | 367 | pango_cairo_update_layout(cr, layout); | ||
1007 | 368 | |||
1008 | 369 | GtkStyleContext* style_context = panel::Style::Instance().GetStyleContext(); | ||
1009 | 370 | |||
1010 | 371 | gtk_style_context_save(style_context); | ||
1011 | 372 | |||
1012 | 373 | GtkWidgetPath* widget_path = gtk_widget_path_new(); | ||
1013 | 374 | gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | ||
1014 | 375 | pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); | ||
1015 | 376 | gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); | ||
1016 | 377 | |||
1017 | 378 | gtk_style_context_set_path(style_context, widget_path); | ||
1018 | 379 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); | ||
1019 | 380 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); | ||
1020 | 381 | |||
1021 | 382 | if (IsActive()) | ||
1022 | 383 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_PRELIGHT); | ||
1023 | 384 | |||
1024 | 385 | int y = (int)((height - text_height) / 2); | ||
1025 | 386 | if (dash_showing_) | ||
1026 | 387 | { | ||
1027 | 388 | cairo_move_to(cr, x, y); | ||
1028 | 389 | cairo_set_source_rgb(cr, 1.0f, 1.0f, 1.0f); | ||
1029 | 390 | pango_cairo_show_layout(cr, layout); | ||
1030 | 391 | } | ||
1031 | 392 | else | ||
1032 | 393 | { | ||
1033 | 394 | gtk_render_layout(style_context, cr, x, y, layout); | ||
1034 | 395 | } | ||
1035 | 396 | |||
1036 | 397 | gtk_widget_path_free(widget_path); | ||
1037 | 398 | |||
1038 | 399 | gtk_style_context_restore(style_context); | ||
1039 | 400 | } | ||
1040 | 401 | |||
1045 | 402 | cairo_destroy(cr); | 514 | cairo_destroy(cr); |
1071 | 403 | if (layout) | 515 | |
1072 | 404 | g_object_unref(layout); | 516 | SetVisible(true); |
1048 | 405 | |||
1049 | 406 | nux::BaseTexture* texture2D = texture_from_cairo_graphics(cairo_graphics); | ||
1050 | 407 | |||
1051 | 408 | nux::TexCoordXForm texxform; | ||
1052 | 409 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); | ||
1053 | 410 | texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); | ||
1054 | 411 | |||
1055 | 412 | nux::ROPConfig rop; | ||
1056 | 413 | rop.Blend = true; | ||
1057 | 414 | rop.SrcBlend = GL_ONE; | ||
1058 | 415 | rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; | ||
1059 | 416 | |||
1060 | 417 | if (texture_layer_) | ||
1061 | 418 | delete texture_layer_; | ||
1062 | 419 | |||
1063 | 420 | texture_layer_ = new nux::TextureLayer(texture2D->GetDeviceTexture(), texxform, | ||
1064 | 421 | nux::color::White, true, rop); | ||
1065 | 422 | SetPaintLayer(texture_layer_); | ||
1066 | 423 | |||
1067 | 424 | texture2D->UnReference(); | ||
1068 | 425 | |||
1069 | 426 | NeedRedraw(); | ||
1070 | 427 | |||
1073 | 428 | refreshed.emit(this); | 517 | refreshed.emit(this); |
1074 | 518 | QueueDraw(); | ||
1075 | 429 | } | 519 | } |
1076 | 430 | 520 | ||
1077 | 431 | void PanelIndicatorEntryView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | 521 | void PanelIndicatorEntryView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) |
1078 | 432 | { | 522 | { |
1086 | 433 | if (opacity_ == 1.0f) | 523 | nux::Geometry const& geo = GetGeometry(); |
1080 | 434 | { | ||
1081 | 435 | TextureArea::Draw(GfxContext, force_draw); | ||
1082 | 436 | return; | ||
1083 | 437 | } | ||
1084 | 438 | |||
1085 | 439 | auto geo = GetGeometry(); | ||
1087 | 440 | GfxContext.PushClippingRectangle(geo); | 524 | GfxContext.PushClippingRectangle(geo); |
1088 | 441 | 525 | ||
1091 | 442 | if (texture_layer_) | 526 | if (cached_geo_ != geo) |
1092 | 443 | { | 527 | { |
1093 | 528 | Refresh(); | ||
1094 | 529 | cached_geo_ = geo; | ||
1095 | 530 | } | ||
1096 | 531 | |||
1097 | 532 | if (entry_texture_ && opacity_ > 0.0f) | ||
1098 | 533 | { | ||
1099 | 534 | /* "Clear" out the background */ | ||
1100 | 535 | nux::ROPConfig rop; | ||
1101 | 536 | rop.Blend = true; | ||
1102 | 537 | rop.SrcBlend = GL_ONE; | ||
1103 | 538 | rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; | ||
1104 | 539 | |||
1105 | 540 | nux::ColorLayer layer(nux::color::Transparent, true, rop); | ||
1106 | 541 | nux::GetPainter().PushDrawLayer(GfxContext, geo, &layer); | ||
1107 | 542 | |||
1108 | 444 | nux::TexCoordXForm texxform; | 543 | nux::TexCoordXForm texxform; |
1109 | 445 | GfxContext.QRP_1Tex(geo.x, geo.y, geo.width, geo.height, | 544 | GfxContext.QRP_1Tex(geo.x, geo.y, geo.width, geo.height, |
1111 | 446 | texture_layer_->GetDeviceTexture(), texxform, | 545 | entry_texture_->GetDeviceTexture(), texxform, |
1112 | 447 | nux::color::White * opacity_); | 546 | nux::color::White * opacity_); |
1113 | 448 | } | 547 | } |
1114 | 449 | 548 | ||
1115 | 450 | GfxContext.PopClippingRectangle(); | 549 | GfxContext.PopClippingRectangle(); |
1116 | 451 | } | 550 | } |
1117 | 452 | 551 | ||
1119 | 453 | void PanelIndicatorEntryView::DashShown() | 552 | void PanelIndicatorEntryView::OverlayShown() |
1120 | 454 | { | 553 | { |
1122 | 455 | dash_showing_ = true; | 554 | overlay_showing_ = true; |
1123 | 456 | Refresh(); | 555 | Refresh(); |
1124 | 457 | } | 556 | } |
1125 | 458 | 557 | ||
1127 | 459 | void PanelIndicatorEntryView::DashHidden() | 558 | void PanelIndicatorEntryView::OverlayHidden() |
1128 | 460 | { | 559 | { |
1130 | 461 | dash_showing_ = false; | 560 | overlay_showing_ = false; |
1131 | 462 | Refresh(); | 561 | Refresh(); |
1132 | 463 | } | 562 | } |
1133 | 464 | 563 | ||
1134 | @@ -478,60 +577,131 @@ | |||
1135 | 478 | return opacity_; | 577 | return opacity_; |
1136 | 479 | } | 578 | } |
1137 | 480 | 579 | ||
1138 | 580 | PanelIndicatorEntryView::IndicatorEntryType PanelIndicatorEntryView::GetType() const | ||
1139 | 581 | { | ||
1140 | 582 | return type_; | ||
1141 | 583 | } | ||
1142 | 584 | |||
1143 | 585 | std::string PanelIndicatorEntryView::GetLabel() const | ||
1144 | 586 | { | ||
1145 | 587 | if (proxy_.get()) | ||
1146 | 588 | { | ||
1147 | 589 | return proxy_->label(); | ||
1148 | 590 | } | ||
1149 | 591 | |||
1150 | 592 | return ""; | ||
1151 | 593 | } | ||
1152 | 594 | |||
1153 | 595 | bool PanelIndicatorEntryView::IsLabelVisible() const | ||
1154 | 596 | { | ||
1155 | 597 | if (proxy_.get()) | ||
1156 | 598 | { | ||
1157 | 599 | return proxy_->label_visible(); | ||
1158 | 600 | } | ||
1159 | 601 | |||
1160 | 602 | return false; | ||
1161 | 603 | } | ||
1162 | 604 | |||
1163 | 605 | bool PanelIndicatorEntryView::IsLabelSensitive() const | ||
1164 | 606 | { | ||
1165 | 607 | if (proxy_.get()) | ||
1166 | 608 | { | ||
1167 | 609 | return proxy_->label_sensitive(); | ||
1168 | 610 | } | ||
1169 | 611 | |||
1170 | 612 | return false; | ||
1171 | 613 | } | ||
1172 | 614 | |||
1173 | 615 | bool PanelIndicatorEntryView::IsIconVisible() const | ||
1174 | 616 | { | ||
1175 | 617 | if (proxy_.get()) | ||
1176 | 618 | { | ||
1177 | 619 | return proxy_->image_visible(); | ||
1178 | 620 | } | ||
1179 | 621 | |||
1180 | 622 | return false; | ||
1181 | 623 | } | ||
1182 | 624 | |||
1183 | 625 | bool PanelIndicatorEntryView::IsIconSensitive() const | ||
1184 | 626 | { | ||
1185 | 627 | if (proxy_.get()) | ||
1186 | 628 | { | ||
1187 | 629 | return proxy_->image_sensitive(); | ||
1188 | 630 | } | ||
1189 | 631 | |||
1190 | 632 | return false; | ||
1191 | 633 | } | ||
1192 | 634 | |||
1193 | 481 | std::string PanelIndicatorEntryView::GetName() const | 635 | std::string PanelIndicatorEntryView::GetName() const |
1194 | 482 | { | 636 | { |
1196 | 483 | return proxy_->id(); | 637 | return "IndicatorEntry"; |
1197 | 484 | } | 638 | } |
1198 | 485 | 639 | ||
1199 | 486 | void PanelIndicatorEntryView::AddProperties(GVariantBuilder* builder) | 640 | void PanelIndicatorEntryView::AddProperties(GVariantBuilder* builder) |
1200 | 487 | { | 641 | { |
1201 | 488 | variant::BuilderWrapper(builder) | 642 | variant::BuilderWrapper(builder) |
1202 | 489 | .add(GetGeometry()) | 643 | .add(GetGeometry()) |
1208 | 490 | .add("label", proxy_->label()) | 644 | .add("id", GetEntryID()) |
1209 | 491 | .add("label_sensitive", proxy_->label_sensitive()) | 645 | .add("name_hint", proxy_->name_hint()) |
1210 | 492 | .add("label_visible", proxy_->label_visible()) | 646 | .add("type", GetType()) |
1211 | 493 | .add("icon_sensitive", proxy_->image_sensitive()) | 647 | .add("label", GetLabel()) |
1212 | 494 | .add("icon_visible", proxy_->image_visible()) | 648 | .add("label_sensitive", IsLabelSensitive()) |
1213 | 649 | .add("label_visible", IsLabelVisible()) | ||
1214 | 650 | .add("icon_sensitive", IsIconSensitive()) | ||
1215 | 651 | .add("icon_visible", IsIconVisible()) | ||
1216 | 652 | .add("entry_visible", IsVisible()) | ||
1217 | 495 | .add("active", proxy_->active()) | 653 | .add("active", proxy_->active()) |
1219 | 496 | .add("priority", proxy_->priority()); | 654 | .add("priority", proxy_->priority()) |
1220 | 655 | .add("focused", IsFocused()); | ||
1221 | 497 | } | 656 | } |
1222 | 498 | 657 | ||
1224 | 499 | bool PanelIndicatorEntryView::GetShowNow() | 658 | bool PanelIndicatorEntryView::GetShowNow() const |
1225 | 500 | { | 659 | { |
1226 | 501 | return proxy_.get() ? proxy_->show_now() : false; | 660 | return proxy_.get() ? proxy_->show_now() : false; |
1227 | 502 | } | 661 | } |
1228 | 503 | 662 | ||
1230 | 504 | void PanelIndicatorEntryView::GetGeometryForSync(indicator::EntryLocationMap& locations) | 663 | void PanelIndicatorEntryView::GetGeometryForSync(EntryLocationMap& locations) |
1231 | 505 | { | 664 | { |
1232 | 506 | if (!IsVisible()) | 665 | if (!IsVisible()) |
1233 | 507 | return; | 666 | return; |
1234 | 508 | 667 | ||
1245 | 509 | locations[proxy_->id()] = GetAbsoluteGeometry(); | 668 | locations[GetEntryID()] = GetAbsoluteGeometry(); |
1236 | 510 | } | ||
1237 | 511 | |||
1238 | 512 | bool PanelIndicatorEntryView::IsEntryValid() const | ||
1239 | 513 | { | ||
1240 | 514 | if (proxy_.get()) | ||
1241 | 515 | { | ||
1242 | 516 | return proxy_->image_visible() || proxy_->label_visible(); | ||
1243 | 517 | } | ||
1244 | 518 | return false; | ||
1246 | 519 | } | 669 | } |
1247 | 520 | 670 | ||
1248 | 521 | bool PanelIndicatorEntryView::IsSensitive() const | 671 | bool PanelIndicatorEntryView::IsSensitive() const |
1249 | 522 | { | 672 | { |
1250 | 523 | if (proxy_.get()) | 673 | if (proxy_.get()) |
1251 | 524 | { | 674 | { |
1253 | 525 | return proxy_->image_sensitive() || proxy_->label_sensitive(); | 675 | return IsIconSensitive() || IsLabelSensitive(); |
1254 | 526 | } | 676 | } |
1255 | 527 | return false; | 677 | return false; |
1256 | 528 | } | 678 | } |
1257 | 529 | 679 | ||
1258 | 680 | bool PanelIndicatorEntryView::IsVisible() | ||
1259 | 681 | { | ||
1260 | 682 | if (proxy_.get()) | ||
1261 | 683 | { | ||
1262 | 684 | return TextureArea::IsVisible() && proxy_->visible(); | ||
1263 | 685 | } | ||
1264 | 686 | |||
1265 | 687 | return TextureArea::IsVisible(); | ||
1266 | 688 | } | ||
1267 | 689 | |||
1268 | 530 | bool PanelIndicatorEntryView::IsActive() const | 690 | bool PanelIndicatorEntryView::IsActive() const |
1269 | 531 | { | 691 | { |
1270 | 532 | return draw_active_; | 692 | return draw_active_; |
1271 | 533 | } | 693 | } |
1272 | 534 | 694 | ||
1273 | 695 | std::string PanelIndicatorEntryView::GetEntryID() const | ||
1274 | 696 | { | ||
1275 | 697 | if (proxy_.get()) | ||
1276 | 698 | { | ||
1277 | 699 | return proxy_->id(); | ||
1278 | 700 | } | ||
1279 | 701 | |||
1280 | 702 | return ""; | ||
1281 | 703 | } | ||
1282 | 704 | |||
1283 | 535 | int PanelIndicatorEntryView::GetEntryPriority() const | 705 | int PanelIndicatorEntryView::GetEntryPriority() const |
1284 | 536 | { | 706 | { |
1285 | 537 | if (proxy_.get()) | 707 | if (proxy_.get()) |
1286 | @@ -551,95 +721,18 @@ | |||
1287 | 551 | return (disabled_ || !proxy_.get() || !IsSensitive()); | 721 | return (disabled_ || !proxy_.get() || !IsSensitive()); |
1288 | 552 | } | 722 | } |
1289 | 553 | 723 | ||
1380 | 554 | bool PanelIndicatorEntryView::IsVisible() | 724 | void PanelIndicatorEntryView::SetFocusedState(bool focused) |
1381 | 555 | { | 725 | { |
1382 | 556 | if (proxy_.get()) | 726 | if (focused_ != focused) |
1383 | 557 | { | 727 | { |
1384 | 558 | return proxy_->visible(); | 728 | focused_ = focused; |
1385 | 559 | } | 729 | Refresh(); |
1386 | 560 | return false; | 730 | } |
1387 | 561 | } | 731 | } |
1388 | 562 | 732 | ||
1389 | 563 | void PanelIndicatorEntryView::OnFontChanged(GObject* gobject, GParamSpec* pspec, | 733 | bool PanelIndicatorEntryView::IsFocused() const |
1390 | 564 | gpointer data) | 734 | { |
1391 | 565 | { | 735 | return focused_; |
1392 | 566 | PanelIndicatorEntryView* self = reinterpret_cast<PanelIndicatorEntryView*>(data); | 736 | } |
1303 | 567 | self->Refresh(); | ||
1304 | 568 | } | ||
1305 | 569 | |||
1306 | 570 | namespace | ||
1307 | 571 | { | ||
1308 | 572 | |||
1309 | 573 | void draw_menu_bg(cairo_t* cr, int width, int height) | ||
1310 | 574 | { | ||
1311 | 575 | GtkStyleContext* style_context = panel::Style::Instance().GetStyleContext(); | ||
1312 | 576 | |||
1313 | 577 | gtk_style_context_save(style_context); | ||
1314 | 578 | |||
1315 | 579 | GtkWidgetPath* widget_path = gtk_widget_path_new(); | ||
1316 | 580 | gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW); | ||
1317 | 581 | gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); | ||
1318 | 582 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | ||
1319 | 583 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); | ||
1320 | 584 | |||
1321 | 585 | gtk_style_context_set_path(style_context, widget_path); | ||
1322 | 586 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); | ||
1323 | 587 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); | ||
1324 | 588 | gtk_style_context_set_state(style_context, GTK_STATE_FLAG_PRELIGHT); | ||
1325 | 589 | |||
1326 | 590 | gtk_render_background(style_context, cr, 0, 0, width, height); | ||
1327 | 591 | gtk_render_frame(style_context, cr, 0, 0, width, height); | ||
1328 | 592 | |||
1329 | 593 | gtk_widget_path_free(widget_path); | ||
1330 | 594 | |||
1331 | 595 | gtk_style_context_restore(style_context); | ||
1332 | 596 | } | ||
1333 | 597 | |||
1334 | 598 | GdkPixbuf* make_pixbuf(int image_type, std::string const& image_data, bool dash_showing) | ||
1335 | 599 | { | ||
1336 | 600 | GdkPixbuf* ret = NULL; | ||
1337 | 601 | GtkIconTheme* theme = gtk_icon_theme_get_default(); | ||
1338 | 602 | |||
1339 | 603 | if (image_type == GTK_IMAGE_PIXBUF) | ||
1340 | 604 | { | ||
1341 | 605 | gsize len = 0; | ||
1342 | 606 | guchar* decoded = g_base64_decode(image_data.c_str(), &len); | ||
1343 | 607 | |||
1344 | 608 | GInputStream* stream = g_memory_input_stream_new_from_data(decoded, | ||
1345 | 609 | len, NULL); | ||
1346 | 610 | |||
1347 | 611 | ret = gdk_pixbuf_new_from_stream(stream, NULL, NULL); | ||
1348 | 612 | |||
1349 | 613 | g_free(decoded); | ||
1350 | 614 | g_input_stream_close(stream, NULL, NULL); | ||
1351 | 615 | g_object_unref(stream); | ||
1352 | 616 | } | ||
1353 | 617 | else if (image_type == GTK_IMAGE_STOCK || | ||
1354 | 618 | image_type == GTK_IMAGE_ICON_NAME) | ||
1355 | 619 | { | ||
1356 | 620 | ret = gtk_icon_theme_load_icon(theme, | ||
1357 | 621 | image_data.c_str(), | ||
1358 | 622 | 22, | ||
1359 | 623 | (GtkIconLookupFlags)0, | ||
1360 | 624 | NULL); | ||
1361 | 625 | } | ||
1362 | 626 | else if (image_type == GTK_IMAGE_GICON) | ||
1363 | 627 | { | ||
1364 | 628 | glib::Object<GIcon> icon(g_icon_new_for_string(image_data.c_str(), NULL)); | ||
1365 | 629 | |||
1366 | 630 | GtkIconInfo* info = gtk_icon_theme_lookup_by_gicon( | ||
1367 | 631 | theme, icon, 22, (GtkIconLookupFlags)0); | ||
1368 | 632 | if (info) | ||
1369 | 633 | { | ||
1370 | 634 | ret = gtk_icon_info_load_icon(info, NULL); | ||
1371 | 635 | gtk_icon_info_free(info); | ||
1372 | 636 | } | ||
1373 | 637 | } | ||
1374 | 638 | |||
1375 | 639 | return ret; | ||
1376 | 640 | } | ||
1377 | 641 | |||
1378 | 642 | } // anon namespace | ||
1379 | 643 | |||
1393 | 644 | 737 | ||
1394 | 645 | } // namespace unity | 738 | } // namespace unity |
1395 | 646 | 739 | ||
1396 | === modified file 'plugins/unityshell/src/PanelIndicatorEntryView.h' | |||
1397 | --- plugins/unityshell/src/PanelIndicatorEntryView.h 2012-03-21 12:31:11 +0000 | |||
1398 | +++ plugins/unityshell/src/PanelIndicatorEntryView.h 2012-04-05 23:42:20 +0000 | |||
1399 | @@ -1,6 +1,6 @@ | |||
1400 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1401 | 2 | /* | 2 | /* |
1403 | 3 | * Copyright (C) 2010 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
1404 | 4 | * | 4 | * |
1405 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
1406 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
1407 | @@ -15,6 +15,7 @@ | |||
1408 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1409 | 16 | * | 16 | * |
1410 | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
1411 | 18 | * Marco Trevisan (Treviño) <3v1n0@ubuntu.com> | ||
1412 | 18 | */ | 19 | */ |
1413 | 19 | 20 | ||
1414 | 20 | #ifndef PANEL_INDICATOR_OBJECT_ENTRY_VIEW_H | 21 | #ifndef PANEL_INDICATOR_OBJECT_ENTRY_VIEW_H |
1415 | @@ -26,78 +27,101 @@ | |||
1416 | 26 | #include <NuxGraphics/GraphicsEngine.h> | 27 | #include <NuxGraphics/GraphicsEngine.h> |
1417 | 27 | 28 | ||
1418 | 28 | #include <UnityCore/IndicatorEntry.h> | 29 | #include <UnityCore/IndicatorEntry.h> |
1419 | 30 | #include <UnityCore/GLibWrapper.h> | ||
1420 | 31 | #include <UnityCore/GLibSignal.h> | ||
1421 | 32 | |||
1422 | 33 | #include <gtk/gtk.h> | ||
1423 | 29 | 34 | ||
1424 | 30 | #include "Introspectable.h" | 35 | #include "Introspectable.h" |
1425 | 31 | 36 | ||
1426 | 32 | 37 | ||
1427 | 33 | namespace unity | 38 | namespace unity |
1428 | 34 | { | 39 | { |
1431 | 35 | 40 | class PanelIndicatorEntryView : public nux::TextureArea, public debug::Introspectable | |
1430 | 36 | class PanelIndicatorEntryView : public nux::TextureArea, public unity::debug::Introspectable | ||
1432 | 37 | { | 41 | { |
1433 | 38 | public: | 42 | public: |
1435 | 39 | typedef enum { | 43 | enum IndicatorEntryType { |
1436 | 40 | INDICATOR, | 44 | INDICATOR, |
1437 | 41 | MENU, | 45 | MENU, |
1438 | 42 | OTHER | 46 | OTHER |
1440 | 43 | } IndicatorEntryType; | 47 | }; |
1441 | 44 | 48 | ||
1442 | 45 | PanelIndicatorEntryView(indicator::Entry::Ptr const& proxy, int padding = 5, | 49 | PanelIndicatorEntryView(indicator::Entry::Ptr const& proxy, int padding = 5, |
1443 | 46 | IndicatorEntryType type = INDICATOR); | 50 | IndicatorEntryType type = INDICATOR); |
1451 | 47 | ~PanelIndicatorEntryView(); | 51 | |
1452 | 48 | 52 | virtual ~PanelIndicatorEntryView(); | |
1453 | 49 | void Refresh(); | 53 | |
1454 | 50 | 54 | IndicatorEntryType GetType() const; | |
1455 | 51 | void Activate(int button = 1); | 55 | std::string GetEntryID() const; |
1456 | 52 | void Unactivate(); | 56 | int GetEntryPriority() const; |
1457 | 53 | bool GetShowNow(); | 57 | |
1458 | 58 | virtual std::string GetLabel() const; | ||
1459 | 59 | virtual bool IsLabelVisible() const; | ||
1460 | 60 | virtual bool IsLabelSensitive() const; | ||
1461 | 61 | |||
1462 | 62 | virtual bool IsIconVisible() const; | ||
1463 | 63 | virtual bool IsIconSensitive() const; | ||
1464 | 64 | |||
1465 | 65 | virtual void Activate(int button = 1); | ||
1466 | 66 | virtual void Unactivate(); | ||
1467 | 67 | |||
1468 | 68 | virtual void GetGeometryForSync(indicator::EntryLocationMap& locations); | ||
1469 | 69 | |||
1470 | 70 | bool GetShowNow() const; | ||
1471 | 71 | bool IsSensitive() const; | ||
1472 | 72 | bool IsActive() const; | ||
1473 | 73 | bool IsVisible(); | ||
1474 | 74 | |||
1475 | 54 | void SetDisabled(bool disabled); | 75 | void SetDisabled(bool disabled); |
1476 | 55 | bool IsDisabled(); | 76 | bool IsDisabled(); |
1477 | 77 | |||
1478 | 56 | void SetOpacity(double alpha); | 78 | void SetOpacity(double alpha); |
1479 | 57 | double GetOpacity(); | 79 | double GetOpacity(); |
1480 | 58 | 80 | ||
1491 | 59 | void GetGeometryForSync(indicator::EntryLocationMap& locations); | 81 | void SetFocusedState(bool focused); |
1492 | 60 | bool IsEntryValid() const; | 82 | bool IsFocused() const; |
1493 | 61 | bool IsSensitive() const; | 83 | |
1494 | 62 | bool IsActive() const; | 84 | void OverlayShown(); |
1495 | 63 | bool IsVisible(); | 85 | void OverlayHidden(); |
1496 | 64 | int GetEntryPriority() const; | 86 | |
1497 | 65 | 87 | sigc::signal<void, PanelIndicatorEntryView*, bool> active_changed; | |
1498 | 66 | void DashShown(); | 88 | sigc::signal<void, PanelIndicatorEntryView*> refreshed; |
1499 | 67 | void DashHidden(); | 89 | |
1500 | 68 | 90 | protected: | |
1501 | 69 | std::string GetName() const; | 91 | std::string GetName() const; |
1503 | 70 | void AddProperties(GVariantBuilder* builder); | 92 | void AddProperties(GVariantBuilder* builder); |
1504 | 71 | 93 | ||
1505 | 72 | virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); | 94 | virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); |
1509 | 73 | 95 | virtual void DrawEntryPrelight(cairo_t* cr, unsigned int w, unsigned int h); | |
1510 | 74 | sigc::signal<void, PanelIndicatorEntryView*, bool> active_changed; | 96 | virtual void DrawEntryContent(cairo_t* cr, unsigned int width, unsigned int height, |
1511 | 75 | sigc::signal<void, PanelIndicatorEntryView*> refreshed; | 97 | glib::Object<GdkPixbuf> const& pixbuf, |
1512 | 98 | glib::Object<PangoLayout> const& layout); | ||
1513 | 99 | |||
1514 | 100 | void Refresh(); | ||
1515 | 101 | void SetActiveState(bool active, int button); | ||
1516 | 102 | virtual void ShowMenu(int button = 1); | ||
1517 | 103 | |||
1518 | 104 | indicator::Entry::Ptr proxy_; | ||
1519 | 105 | unsigned int spacing_; | ||
1520 | 106 | unsigned int left_padding_; | ||
1521 | 107 | unsigned int right_padding_; | ||
1522 | 76 | 108 | ||
1523 | 77 | private: | 109 | private: |
1525 | 78 | unity::indicator::Entry::Ptr proxy_; | 110 | void OnMouseDown(int x, int y, long button_flags, long key_flags); |
1526 | 111 | void OnMouseUp(int x, int y, long button_flags, long key_flags); | ||
1527 | 112 | void OnMouseWheel(int x, int y, int delta, unsigned long mouse_state, unsigned long key_state); | ||
1528 | 113 | void OnActiveChanged(bool is_active); | ||
1529 | 114 | |||
1530 | 115 | glib::Object<GdkPixbuf> MakePixbuf(); | ||
1531 | 116 | |||
1532 | 79 | IndicatorEntryType type_; | 117 | IndicatorEntryType type_; |
1536 | 80 | nux::CairoGraphics util_cg_; | 118 | nux::BaseTexture* entry_texture_; |
1537 | 81 | nux::TextureLayer* texture_layer_; | 119 | nux::Geometry cached_geo_; |
1535 | 82 | int padding_; | ||
1538 | 83 | double opacity_; | 120 | double opacity_; |
1539 | 84 | bool draw_active_; | 121 | bool draw_active_; |
1541 | 85 | bool dash_showing_; | 122 | bool overlay_showing_; |
1542 | 86 | bool disabled_; | 123 | bool disabled_; |
1557 | 87 | gulong on_font_changed_connection_; | 124 | bool focused_; |
1544 | 88 | |||
1545 | 89 | static void OnFontChanged(GObject* gobject, GParamSpec* pspec, gpointer data); | ||
1546 | 90 | void OnMouseDown(int x, int y, long button_flags, long key_flags); | ||
1547 | 91 | void OnMouseUp(int x, int y, long button_flags, long key_flags); | ||
1548 | 92 | void OnMouseWheel(int x, int y, int delta, unsigned long mouse_state, unsigned long key_state); | ||
1549 | 93 | void OnActiveChanged(bool is_active); | ||
1550 | 94 | |||
1551 | 95 | void SetActiveState(bool active, int button); | ||
1552 | 96 | void ShowMenu(int button); | ||
1553 | 97 | |||
1554 | 98 | sigc::connection on_indicator_activate_changed_connection_; | ||
1555 | 99 | sigc::connection on_indicator_updated_connection_; | ||
1556 | 100 | sigc::connection on_panelstyle_changed_connection_; | ||
1558 | 101 | }; | 125 | }; |
1559 | 102 | 126 | ||
1560 | 103 | } | 127 | } |
1561 | 104 | 128 | ||
1562 | === modified file 'plugins/unityshell/src/PanelIndicatorsView.cpp' | |||
1563 | --- plugins/unityshell/src/PanelIndicatorsView.cpp 2012-03-21 12:31:11 +0000 | |||
1564 | +++ plugins/unityshell/src/PanelIndicatorsView.cpp 2012-04-05 23:42:20 +0000 | |||
1565 | @@ -1,6 +1,6 @@ | |||
1566 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1567 | 2 | /* | 2 | /* |
1569 | 3 | * Copyright (C) 2011 Canonical Ltd | 3 | * Copyright (C) 2011-2012 Canonical Ltd |
1570 | 4 | * | 4 | * |
1571 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
1572 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
1573 | @@ -14,7 +14,7 @@ | |||
1574 | 14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License |
1575 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1576 | 16 | * | 16 | * |
1578 | 17 | * Authored by: Marco Trevisan (Treviño) <mail@3v1n0.net> | 17 | * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com> |
1579 | 18 | * Neil Jagdish Patel <neil.patel@canonical.com> | 18 | * Neil Jagdish Patel <neil.patel@canonical.com> |
1580 | 19 | */ | 19 | */ |
1581 | 20 | 20 | ||
1582 | @@ -36,6 +36,8 @@ | |||
1583 | 36 | 36 | ||
1584 | 37 | namespace unity | 37 | namespace unity |
1585 | 38 | { | 38 | { |
1586 | 39 | using namespace indicator; | ||
1587 | 40 | |||
1588 | 39 | NUX_IMPLEMENT_OBJECT_TYPE(PanelIndicatorsView); | 41 | NUX_IMPLEMENT_OBJECT_TYPE(PanelIndicatorsView); |
1589 | 40 | 42 | ||
1590 | 41 | PanelIndicatorsView::PanelIndicatorsView() | 43 | PanelIndicatorsView::PanelIndicatorsView() |
1591 | @@ -45,8 +47,9 @@ | |||
1592 | 45 | { | 47 | { |
1593 | 46 | LOG_DEBUG(logger) << "Indicators View Added: "; | 48 | LOG_DEBUG(logger) << "Indicators View Added: "; |
1594 | 47 | layout_ = new nux::HLayout("", NUX_TRACKER_LOCATION); | 49 | layout_ = new nux::HLayout("", NUX_TRACKER_LOCATION); |
1595 | 50 | layout_->SetContentDistribution(nux::eStackRight); | ||
1596 | 48 | 51 | ||
1598 | 49 | SetCompositionLayout(layout_); | 52 | SetLayout(layout_); |
1599 | 50 | } | 53 | } |
1600 | 51 | 54 | ||
1601 | 52 | PanelIndicatorsView::~PanelIndicatorsView() | 55 | PanelIndicatorsView::~PanelIndicatorsView() |
1602 | @@ -59,7 +62,7 @@ | |||
1603 | 59 | } | 62 | } |
1604 | 60 | 63 | ||
1605 | 61 | void | 64 | void |
1607 | 62 | PanelIndicatorsView::AddIndicator(indicator::Indicator::Ptr const& indicator) | 65 | PanelIndicatorsView::AddIndicator(Indicator::Ptr const& indicator) |
1608 | 63 | { | 66 | { |
1609 | 64 | LOG_DEBUG(logger) << "IndicatorAdded: " << indicator->name(); | 67 | LOG_DEBUG(logger) << "IndicatorAdded: " << indicator->name(); |
1610 | 65 | indicators_.push_back(indicator); | 68 | indicators_.push_back(indicator); |
1611 | @@ -76,7 +79,7 @@ | |||
1612 | 76 | } | 79 | } |
1613 | 77 | 80 | ||
1614 | 78 | void | 81 | void |
1616 | 79 | PanelIndicatorsView::RemoveIndicator(indicator::Indicator::Ptr const& indicator) | 82 | PanelIndicatorsView::RemoveIndicator(Indicator::Ptr const& indicator) |
1617 | 80 | { | 83 | { |
1618 | 81 | auto connections = indicators_connections_.find(indicator); | 84 | auto connections = indicators_connections_.find(indicator); |
1619 | 82 | 85 | ||
1620 | @@ -88,7 +91,7 @@ | |||
1621 | 88 | } | 91 | } |
1622 | 89 | 92 | ||
1623 | 90 | for (auto entry : indicator->GetEntries()) | 93 | for (auto entry : indicator->GetEntries()) |
1625 | 91 | OnEntryRemoved (entry->id()); | 94 | OnEntryRemoved(entry->id()); |
1626 | 92 | 95 | ||
1627 | 93 | for (auto i = indicators_.begin(); i != indicators_.end(); i++) | 96 | for (auto i = indicators_.begin(); i != indicators_.end(); i++) |
1628 | 94 | { | 97 | { |
1629 | @@ -102,6 +105,12 @@ | |||
1630 | 102 | LOG_DEBUG(logger) << "IndicatorRemoved: " << indicator->name(); | 105 | LOG_DEBUG(logger) << "IndicatorRemoved: " << indicator->name(); |
1631 | 103 | } | 106 | } |
1632 | 104 | 107 | ||
1633 | 108 | PanelIndicatorsView::Indicators | ||
1634 | 109 | PanelIndicatorsView::GetIndicators() | ||
1635 | 110 | { | ||
1636 | 111 | return indicators_; | ||
1637 | 112 | } | ||
1638 | 113 | |||
1639 | 105 | void | 114 | void |
1640 | 106 | PanelIndicatorsView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | 115 | PanelIndicatorsView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) |
1641 | 107 | { | 116 | { |
1642 | @@ -121,16 +130,45 @@ | |||
1643 | 121 | entry.second->QueueDraw(); | 130 | entry.second->QueueDraw(); |
1644 | 122 | } | 131 | } |
1645 | 123 | 132 | ||
1646 | 133 | void | ||
1647 | 134 | PanelIndicatorsView::SetMaximumEntriesWidth(int max_width) | ||
1648 | 135 | { | ||
1649 | 136 | unsigned int n_entries = 0; | ||
1650 | 137 | |||
1651 | 138 | for (auto entry : entries_) | ||
1652 | 139 | if (entry.second->IsVisible()) | ||
1653 | 140 | n_entries++; | ||
1654 | 141 | |||
1655 | 142 | if (n_entries > 0) | ||
1656 | 143 | { | ||
1657 | 144 | for (auto entry : entries_) | ||
1658 | 145 | { | ||
1659 | 146 | if (entry.second->IsVisible() && n_entries > 0) | ||
1660 | 147 | { | ||
1661 | 148 | int max_entry_width = max_width / n_entries; | ||
1662 | 149 | |||
1663 | 150 | if (entry.second->GetBaseWidth() > max_entry_width) | ||
1664 | 151 | entry.second->SetMaximumWidth(max_entry_width); | ||
1665 | 152 | |||
1666 | 153 | max_width -= entry.second->GetBaseWidth(); | ||
1667 | 154 | --n_entries; | ||
1668 | 155 | } | ||
1669 | 156 | } | ||
1670 | 157 | } | ||
1671 | 158 | } | ||
1672 | 159 | |||
1673 | 124 | PanelIndicatorEntryView* | 160 | PanelIndicatorEntryView* |
1675 | 125 | PanelIndicatorsView::ActivateEntry(std::string const& entry_id) | 161 | PanelIndicatorsView::ActivateEntry(std::string const& entry_id, int button) |
1676 | 126 | { | 162 | { |
1677 | 127 | auto entry = entries_.find(entry_id); | 163 | auto entry = entries_.find(entry_id); |
1678 | 128 | 164 | ||
1680 | 129 | if (entry != entries_.end() && entry->second->IsEntryValid()) | 165 | if (entry != entries_.end()) |
1681 | 130 | { | 166 | { |
1682 | 131 | PanelIndicatorEntryView* view = entry->second; | 167 | PanelIndicatorEntryView* view = entry->second; |
1685 | 132 | LOG_DEBUG(logger) << "Activating: " << entry_id; | 168 | |
1686 | 133 | view->Activate(); | 169 | if (view->IsSensitive() && view->IsVisible()) |
1687 | 170 | view->Activate(button); | ||
1688 | 171 | |||
1689 | 134 | return view; | 172 | return view; |
1690 | 135 | } | 173 | } |
1691 | 136 | 174 | ||
1692 | @@ -148,24 +186,27 @@ | |||
1693 | 148 | for (auto entry : sorted_entries) | 186 | for (auto entry : sorted_entries) |
1694 | 149 | { | 187 | { |
1695 | 150 | PanelIndicatorEntryView* view = entry.second; | 188 | PanelIndicatorEntryView* view = entry.second; |
1697 | 151 | if (view->IsSensitive()) | 189 | |
1698 | 190 | if (view->IsSensitive() && view->IsVisible() && view->IsFocused()) | ||
1699 | 152 | { | 191 | { |
1701 | 153 | view->Activate(); | 192 | /* Use the 0 button, it means it's a keyboard activation */ |
1702 | 193 | view->Activate(0); | ||
1703 | 154 | return true; | 194 | return true; |
1704 | 155 | } | 195 | } |
1705 | 156 | } | 196 | } |
1706 | 197 | |||
1707 | 157 | return false; | 198 | return false; |
1708 | 158 | } | 199 | } |
1709 | 159 | 200 | ||
1710 | 160 | void | 201 | void |
1712 | 161 | PanelIndicatorsView::GetGeometryForSync(indicator::EntryLocationMap& locations) | 202 | PanelIndicatorsView::GetGeometryForSync(EntryLocationMap& locations) |
1713 | 162 | { | 203 | { |
1714 | 163 | for (auto entry : entries_) | 204 | for (auto entry : entries_) |
1715 | 164 | entry.second->GetGeometryForSync(locations); | 205 | entry.second->GetGeometryForSync(locations); |
1716 | 165 | } | 206 | } |
1717 | 166 | 207 | ||
1718 | 167 | PanelIndicatorEntryView* | 208 | PanelIndicatorEntryView* |
1720 | 168 | PanelIndicatorsView::ActivateEntryAt(int x, int y) | 209 | PanelIndicatorsView::ActivateEntryAt(int x, int y, int button) |
1721 | 169 | { | 210 | { |
1722 | 170 | PanelIndicatorEntryView* target = nullptr; | 211 | PanelIndicatorEntryView* target = nullptr; |
1723 | 171 | bool found_old_active = false; | 212 | bool found_old_active = false; |
1724 | @@ -180,9 +221,10 @@ | |||
1725 | 180 | { | 221 | { |
1726 | 181 | PanelIndicatorEntryView* view = entry.second; | 222 | PanelIndicatorEntryView* view = entry.second; |
1727 | 182 | 223 | ||
1729 | 183 | if (!target && view->IsVisible() && view->GetAbsoluteGeometry().IsPointInside(x, y)) | 224 | if (!target && view->IsVisible() && view->IsFocused() && |
1730 | 225 | view->GetAbsoluteGeometry().IsPointInside(x, y)) | ||
1731 | 184 | { | 226 | { |
1733 | 185 | view->Activate(0); | 227 | view->Activate(button); |
1734 | 186 | target = view; | 228 | target = view; |
1735 | 187 | break; | 229 | break; |
1736 | 188 | } | 230 | } |
1737 | @@ -219,11 +261,13 @@ | |||
1738 | 219 | GfxContext.PopClippingRectangle(); | 261 | GfxContext.PopClippingRectangle(); |
1739 | 220 | } | 262 | } |
1740 | 221 | 263 | ||
1744 | 222 | PanelIndicatorEntryView * | 264 | void |
1745 | 223 | PanelIndicatorsView::AddEntry(indicator::Entry::Ptr const& entry, int padding, | 265 | PanelIndicatorsView::AddEntryView(PanelIndicatorEntryView* view, |
1746 | 224 | IndicatorEntryPosition pos, IndicatorEntryType type) | 266 | IndicatorEntryPosition pos) |
1747 | 225 | { | 267 | { |
1749 | 226 | auto view = new PanelIndicatorEntryView(entry, padding, type); | 268 | if (!view) |
1750 | 269 | return; | ||
1751 | 270 | |||
1752 | 227 | int entry_pos = pos; | 271 | int entry_pos = pos; |
1753 | 228 | 272 | ||
1754 | 229 | view->SetOpacity(opacity_); | 273 | view->SetOpacity(opacity_); |
1755 | @@ -233,7 +277,7 @@ | |||
1756 | 233 | { | 277 | { |
1757 | 234 | entry_pos = nux::NUX_LAYOUT_BEGIN; | 278 | entry_pos = nux::NUX_LAYOUT_BEGIN; |
1758 | 235 | 279 | ||
1760 | 236 | if (entry->priority() > -1) | 280 | if (view->GetEntryPriority() > -1) |
1761 | 237 | { | 281 | { |
1762 | 238 | for (auto area : layout_->GetChildren()) | 282 | for (auto area : layout_->GetChildren()) |
1763 | 239 | { | 283 | { |
1764 | @@ -241,7 +285,7 @@ | |||
1765 | 241 | 285 | ||
1766 | 242 | if (en) | 286 | if (en) |
1767 | 243 | { | 287 | { |
1769 | 244 | if (en && entry->priority() <= en->GetEntryPriority()) | 288 | if (en && view->GetEntryPriority() <= en->GetEntryPriority()) |
1770 | 245 | break; | 289 | break; |
1771 | 246 | 290 | ||
1772 | 247 | entry_pos++; | 291 | entry_pos++; |
1773 | @@ -251,20 +295,28 @@ | |||
1774 | 251 | } | 295 | } |
1775 | 252 | 296 | ||
1776 | 253 | layout_->AddView(view, 0, nux::eCenter, nux::eFull, 1.0, (nux::LayoutPosition) entry_pos); | 297 | layout_->AddView(view, 0, nux::eCenter, nux::eFull, 1.0, (nux::LayoutPosition) entry_pos); |
1779 | 254 | layout_->SetContentDistribution(nux::eStackRight); | 298 | |
1780 | 255 | entries_[entry->id()] = view; | 299 | entries_[view->GetEntryID()] = view; |
1781 | 256 | 300 | ||
1782 | 257 | AddChild(view); | 301 | AddChild(view); |
1783 | 258 | QueueRelayout(); | 302 | QueueRelayout(); |
1784 | 259 | QueueDraw(); | 303 | QueueDraw(); |
1785 | 260 | 304 | ||
1786 | 261 | on_indicator_updated.emit(view); | 305 | on_indicator_updated.emit(view); |
1787 | 306 | } | ||
1788 | 307 | |||
1789 | 308 | PanelIndicatorEntryView * | ||
1790 | 309 | PanelIndicatorsView::AddEntry(Entry::Ptr const& entry, int padding, | ||
1791 | 310 | IndicatorEntryPosition pos, IndicatorEntryType type) | ||
1792 | 311 | { | ||
1793 | 312 | auto view = new PanelIndicatorEntryView(entry, padding, type); | ||
1794 | 313 | AddEntryView(view, pos); | ||
1795 | 262 | 314 | ||
1796 | 263 | return view; | 315 | return view; |
1797 | 264 | } | 316 | } |
1798 | 265 | 317 | ||
1799 | 266 | void | 318 | void |
1801 | 267 | PanelIndicatorsView::OnEntryAdded(indicator::Entry::Ptr const& entry) | 319 | PanelIndicatorsView::OnEntryAdded(Entry::Ptr const& entry) |
1802 | 268 | { | 320 | { |
1803 | 269 | AddEntry(entry); | 321 | AddEntry(entry); |
1804 | 270 | } | 322 | } |
1805 | @@ -279,19 +331,25 @@ | |||
1806 | 279 | } | 331 | } |
1807 | 280 | 332 | ||
1808 | 281 | void | 333 | void |
1809 | 334 | PanelIndicatorsView::RemoveEntryView(PanelIndicatorEntryView* view) | ||
1810 | 335 | { | ||
1811 | 336 | if (!view) | ||
1812 | 337 | return; | ||
1813 | 338 | |||
1814 | 339 | std::string const& entry_id = view->GetEntryID(); | ||
1815 | 340 | RemoveChild(view); | ||
1816 | 341 | on_indicator_updated.emit(view); | ||
1817 | 342 | entries_.erase(entry_id); | ||
1818 | 343 | layout_->RemoveChildObject(view); | ||
1819 | 344 | |||
1820 | 345 | QueueRelayout(); | ||
1821 | 346 | QueueDraw(); | ||
1822 | 347 | } | ||
1823 | 348 | |||
1824 | 349 | void | ||
1825 | 282 | PanelIndicatorsView::RemoveEntry(std::string const& entry_id) | 350 | PanelIndicatorsView::RemoveEntry(std::string const& entry_id) |
1826 | 283 | { | 351 | { |
1838 | 284 | PanelIndicatorEntryView* view = entries_[entry_id]; | 352 | RemoveEntryView(entries_[entry_id]); |
1828 | 285 | |||
1829 | 286 | if (view) | ||
1830 | 287 | { | ||
1831 | 288 | layout_->RemoveChildObject(view); | ||
1832 | 289 | entries_.erase(entry_id); | ||
1833 | 290 | on_indicator_updated.emit(view); | ||
1834 | 291 | |||
1835 | 292 | QueueRelayout(); | ||
1836 | 293 | QueueDraw(); | ||
1837 | 294 | } | ||
1839 | 295 | } | 353 | } |
1840 | 296 | 354 | ||
1841 | 297 | void | 355 | void |
1842 | @@ -301,17 +359,17 @@ | |||
1843 | 301 | } | 359 | } |
1844 | 302 | 360 | ||
1845 | 303 | void | 361 | void |
1847 | 304 | PanelIndicatorsView::DashShown() | 362 | PanelIndicatorsView::OverlayShown() |
1848 | 305 | { | 363 | { |
1849 | 306 | for (auto entry: entries_) | 364 | for (auto entry: entries_) |
1851 | 307 | entry.second->DashShown(); | 365 | entry.second->OverlayShown(); |
1852 | 308 | } | 366 | } |
1853 | 309 | 367 | ||
1854 | 310 | void | 368 | void |
1856 | 311 | PanelIndicatorsView::DashHidden() | 369 | PanelIndicatorsView::OverlayHidden() |
1857 | 312 | { | 370 | { |
1858 | 313 | for (auto entry: entries_) | 371 | for (auto entry: entries_) |
1860 | 314 | entry.second->DashHidden(); | 372 | entry.second->OverlayHidden(); |
1861 | 315 | } | 373 | } |
1862 | 316 | 374 | ||
1863 | 317 | double | 375 | double |
1864 | @@ -337,13 +395,16 @@ | |||
1865 | 337 | 395 | ||
1866 | 338 | std::string PanelIndicatorsView::GetName() const | 396 | std::string PanelIndicatorsView::GetName() const |
1867 | 339 | { | 397 | { |
1869 | 340 | return "IndicatorsView"; | 398 | return "Indicators"; |
1870 | 341 | } | 399 | } |
1871 | 342 | 400 | ||
1872 | 343 | void | 401 | void |
1873 | 344 | PanelIndicatorsView::AddProperties(GVariantBuilder* builder) | 402 | PanelIndicatorsView::AddProperties(GVariantBuilder* builder) |
1874 | 345 | { | 403 | { |
1876 | 346 | variant::BuilderWrapper(builder).add(GetGeometry()); | 404 | variant::BuilderWrapper(builder) |
1877 | 405 | .add(GetGeometry()) | ||
1878 | 406 | .add("entries", entries_.size()) | ||
1879 | 407 | .add("opacity", opacity_); | ||
1880 | 347 | } | 408 | } |
1881 | 348 | 409 | ||
1882 | 349 | } // namespace unity | 410 | } // namespace unity |
1883 | 350 | 411 | ||
1884 | === modified file 'plugins/unityshell/src/PanelIndicatorsView.h' | |||
1885 | --- plugins/unityshell/src/PanelIndicatorsView.h 2012-03-21 12:31:11 +0000 | |||
1886 | +++ plugins/unityshell/src/PanelIndicatorsView.h 2012-04-05 23:42:20 +0000 | |||
1887 | @@ -42,11 +42,11 @@ | |||
1888 | 42 | void AddIndicator(indicator::Indicator::Ptr const& indicator); | 42 | void AddIndicator(indicator::Indicator::Ptr const& indicator); |
1889 | 43 | void RemoveIndicator(indicator::Indicator::Ptr const& indicator); | 43 | void RemoveIndicator(indicator::Indicator::Ptr const& indicator); |
1890 | 44 | 44 | ||
1892 | 45 | typedef enum { | 45 | enum IndicatorEntryPosition { |
1893 | 46 | AUTO = -1, | 46 | AUTO = -1, |
1894 | 47 | START = nux::NUX_LAYOUT_BEGIN, | 47 | START = nux::NUX_LAYOUT_BEGIN, |
1895 | 48 | END = nux::NUX_LAYOUT_END, | 48 | END = nux::NUX_LAYOUT_END, |
1897 | 49 | } IndicatorEntryPosition; | 49 | }; |
1898 | 50 | 50 | ||
1899 | 51 | typedef PanelIndicatorEntryView::IndicatorEntryType IndicatorEntryType; | 51 | typedef PanelIndicatorEntryView::IndicatorEntryType IndicatorEntryType; |
1900 | 52 | 52 | ||
1901 | @@ -56,37 +56,46 @@ | |||
1902 | 56 | IndicatorEntryType type = IndicatorEntryType::INDICATOR); | 56 | IndicatorEntryType type = IndicatorEntryType::INDICATOR); |
1903 | 57 | void RemoveEntry(std::string const& entry_id); | 57 | void RemoveEntry(std::string const& entry_id); |
1904 | 58 | 58 | ||
1907 | 59 | PanelIndicatorEntryView* ActivateEntryAt(int x, int y); | 59 | PanelIndicatorEntryView* ActivateEntryAt(int x, int y, int button = 1); |
1908 | 60 | PanelIndicatorEntryView* ActivateEntry(std::string const& entry_id); | 60 | PanelIndicatorEntryView* ActivateEntry(std::string const& entry_id, int button = 1); |
1909 | 61 | bool ActivateIfSensitive(); | 61 | bool ActivateIfSensitive(); |
1910 | 62 | |||
1911 | 63 | virtual void OverlayShown(); | ||
1912 | 64 | virtual void OverlayHidden(); | ||
1913 | 65 | |||
1914 | 66 | void SetOpacity(double opacity); | ||
1915 | 67 | double GetOpacity(); | ||
1916 | 68 | |||
1917 | 69 | void SetMaximumEntriesWidth(int max_width); | ||
1918 | 62 | void GetGeometryForSync(indicator::EntryLocationMap& locations); | 70 | void GetGeometryForSync(indicator::EntryLocationMap& locations); |
1919 | 63 | 71 | ||
1920 | 72 | virtual void QueueDraw(); | ||
1921 | 73 | |||
1922 | 74 | sigc::signal<void, PanelIndicatorEntryView*> on_indicator_updated; | ||
1923 | 75 | |||
1924 | 76 | protected: | ||
1925 | 77 | std::string GetName() const; | ||
1926 | 78 | void AddProperties(GVariantBuilder* builder); | ||
1927 | 79 | |||
1928 | 80 | typedef std::vector<indicator::Indicator::Ptr> Indicators; | ||
1929 | 81 | Indicators GetIndicators(); | ||
1930 | 82 | |||
1931 | 64 | virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); | 83 | virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); |
1932 | 65 | virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); | 84 | virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); |
1933 | 66 | virtual void QueueDraw(); | ||
1934 | 67 | 85 | ||
1935 | 68 | virtual void OnEntryAdded(indicator::Entry::Ptr const& entry); | 86 | virtual void OnEntryAdded(indicator::Entry::Ptr const& entry); |
1936 | 69 | virtual void OnEntryRefreshed(PanelIndicatorEntryView* view); | 87 | virtual void OnEntryRefreshed(PanelIndicatorEntryView* view); |
1937 | 70 | virtual void OnEntryRemoved(std::string const& entry_id); | 88 | virtual void OnEntryRemoved(std::string const& entry_id); |
1938 | 71 | 89 | ||
1948 | 72 | void DashShown(); | 90 | virtual void AddEntryView(PanelIndicatorEntryView* view, |
1949 | 73 | void DashHidden(); | 91 | IndicatorEntryPosition pos = AUTO); |
1950 | 74 | 92 | virtual void RemoveEntryView(PanelIndicatorEntryView* view); | |
1951 | 75 | void SetOpacity(double opacity); | 93 | |
1943 | 76 | double GetOpacity(); | ||
1944 | 77 | |||
1945 | 78 | sigc::signal<void, PanelIndicatorEntryView*> on_indicator_updated; | ||
1946 | 79 | |||
1947 | 80 | protected: | ||
1952 | 81 | nux::HLayout* layout_; | 94 | nux::HLayout* layout_; |
1953 | 82 | typedef std::map<std::string, PanelIndicatorEntryView*> Entries; | 95 | typedef std::map<std::string, PanelIndicatorEntryView*> Entries; |
1954 | 83 | Entries entries_; | 96 | Entries entries_; |
1955 | 84 | 97 | ||
1956 | 85 | std::string GetName() const; | ||
1957 | 86 | void AddProperties(GVariantBuilder* builder); | ||
1958 | 87 | |||
1959 | 88 | private: | 98 | private: |
1960 | 89 | typedef std::vector<indicator::Indicator::Ptr> Indicators; | ||
1961 | 90 | Indicators indicators_; | 99 | Indicators indicators_; |
1962 | 91 | double opacity_; | 100 | double opacity_; |
1963 | 92 | 101 | ||
1964 | 93 | 102 | ||
1965 | === modified file 'plugins/unityshell/src/PanelMenuView.cpp' | |||
1966 | --- plugins/unityshell/src/PanelMenuView.cpp 2012-04-03 03:36:34 +0000 | |||
1967 | +++ plugins/unityshell/src/PanelMenuView.cpp 2012-04-05 23:42:20 +0000 | |||
1968 | @@ -1,6 +1,6 @@ | |||
1969 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1970 | 2 | /* | 2 | /* |
1972 | 3 | * Copyright (C) 2010 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
1973 | 4 | * | 4 | * |
1974 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
1975 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
1976 | @@ -15,61 +15,52 @@ | |||
1977 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1978 | 16 | * | 16 | * |
1979 | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
1981 | 18 | * Marco Trevisan <mail@3v1n0.net> | 18 | * Marco Trevisan <3v1n0@ubuntu.com> |
1982 | 19 | */ | 19 | */ |
1983 | 20 | #include <glib.h> | ||
1984 | 21 | #include <pango/pangocairo.h> | ||
1985 | 22 | #include <gtk/gtk.h> | ||
1986 | 23 | 20 | ||
1987 | 24 | #include <Nux/Nux.h> | 21 | #include <Nux/Nux.h> |
1995 | 25 | #include <Nux/HLayout.h> | 22 | #include <NuxCore/Logger.h> |
1989 | 26 | #include <Nux/VLayout.h> | ||
1990 | 27 | #include <Nux/TextureArea.h> | ||
1991 | 28 | |||
1992 | 29 | #include <NuxGraphics/GLThread.h> | ||
1993 | 30 | #include <NuxGraphics/XInputWindow.h> | ||
1994 | 31 | #include <Nux/BaseWindow.h> | ||
1996 | 32 | 23 | ||
1997 | 33 | #include "CairoTexture.h" | 24 | #include "CairoTexture.h" |
1998 | 34 | #include "PanelMenuView.h" | 25 | #include "PanelMenuView.h" |
1999 | 35 | #include "PanelStyle.h" | 26 | #include "PanelStyle.h" |
2000 | 36 | #include <UnityCore/Variant.h> | ||
2001 | 37 | |||
2002 | 38 | #include <gio/gdesktopappinfo.h> | ||
2003 | 39 | #include <gconf/gconf-client.h> | ||
2004 | 40 | |||
2005 | 41 | #include <glib.h> | ||
2006 | 42 | #include <glib/gi18n-lib.h> | ||
2007 | 43 | |||
2008 | 44 | #include "DashSettings.h" | 27 | #include "DashSettings.h" |
2009 | 45 | #include "ubus-server.h" | ||
2010 | 46 | #include "UBusMessages.h" | 28 | #include "UBusMessages.h" |
2011 | 47 | |||
2012 | 48 | #include "UScreen.h" | 29 | #include "UScreen.h" |
2013 | 49 | 30 | ||
2014 | 31 | #include <UnityCore/Variant.h> | ||
2015 | 32 | |||
2016 | 33 | #include <glib/gi18n-lib.h> | ||
2017 | 34 | |||
2018 | 50 | namespace unity | 35 | namespace unity |
2019 | 51 | { | 36 | { |
2020 | 52 | 37 | ||
2021 | 53 | namespace | 38 | namespace |
2022 | 54 | { | 39 | { |
2024 | 55 | const std::string WINDOW_TITLE_FONT_KEY = "/apps/metacity/general/titlebar_font"; | 40 | nux::logging::Logger logger("unity.panel.menu"); |
2025 | 41 | const int MAIN_LEFT_PADDING = 4; | ||
2026 | 42 | const int TITLE_PADDING = 2; | ||
2027 | 43 | const int MENUBAR_PADDING = 4; | ||
2028 | 44 | const int MENU_ENTRIES_PADDING = 6; | ||
2029 | 45 | const int DEFAULT_MENUS_FADEIN = 100; | ||
2030 | 46 | const int DEFAULT_MENUS_FADEOUT = 120; | ||
2031 | 47 | const int DEFAULT_MENUS_DISCOVERY = 2; | ||
2032 | 48 | const int DEFAULT_DISCOVERY_FADEIN = 200; | ||
2033 | 49 | const int DEFAULT_DISCOVERY_FADEOUT = 300; | ||
2034 | 50 | |||
2035 | 51 | const std::string DESKTOP_NAME(_("Ubuntu Desktop")); | ||
2036 | 56 | } | 52 | } |
2037 | 57 | 53 | ||
2039 | 58 | PanelMenuView::PanelMenuView(int padding) | 54 | PanelMenuView::PanelMenuView() |
2040 | 59 | : _matcher(bamf_matcher_get_default()), | 55 | : _matcher(bamf_matcher_get_default()), |
2041 | 60 | _title_layer(nullptr), | ||
2042 | 61 | _util_cg(CAIRO_FORMAT_ARGB32, 1, 1), | ||
2043 | 62 | _gradient_texture(nullptr), | ||
2044 | 63 | _is_inside(false), | 56 | _is_inside(false), |
2045 | 64 | _is_grabbed(false), | 57 | _is_grabbed(false), |
2046 | 65 | _is_maximized(false), | 58 | _is_maximized(false), |
2047 | 66 | _is_own_window(false), | ||
2048 | 67 | _last_active_view(nullptr), | 59 | _last_active_view(nullptr), |
2049 | 68 | _new_application(nullptr), | 60 | _new_application(nullptr), |
2053 | 69 | _last_width(0), | 61 | _overlay_showing(false), |
2051 | 70 | _last_height(0), | ||
2052 | 71 | _places_showing(false), | ||
2054 | 72 | _switcher_showing(false), | 62 | _switcher_showing(false), |
2055 | 63 | _launcher_keynav(false), | ||
2056 | 73 | _show_now_activated(false), | 64 | _show_now_activated(false), |
2057 | 74 | _we_control_active(false), | 65 | _we_control_active(false), |
2058 | 75 | _new_app_menu_shown(false), | 66 | _new_app_menu_shown(false), |
2059 | @@ -79,26 +70,19 @@ | |||
2060 | 79 | _update_show_now_id(0), | 70 | _update_show_now_id(0), |
2061 | 80 | _new_app_show_id(0), | 71 | _new_app_show_id(0), |
2062 | 81 | _new_app_hide_id(0), | 72 | _new_app_hide_id(0), |
2071 | 82 | _menus_fadein(100), | 73 | _menus_fadein(DEFAULT_MENUS_FADEIN), |
2072 | 83 | _menus_fadeout(120), | 74 | _menus_fadeout(DEFAULT_MENUS_FADEOUT), |
2073 | 84 | _menus_discovery(2), | 75 | _menus_discovery(DEFAULT_MENUS_DISCOVERY), |
2074 | 85 | _menus_discovery_fadein(200), | 76 | _menus_discovery_fadein(DEFAULT_DISCOVERY_FADEIN), |
2075 | 86 | _menus_discovery_fadeout(300), | 77 | _menus_discovery_fadeout(DEFAULT_DISCOVERY_FADEOUT), |
2076 | 87 | _panel_title(nullptr), | 78 | _fade_in_animator(_menus_fadein), |
2077 | 88 | _fade_in_animator(nullptr), | 79 | _fade_out_animator(_menus_fadeout) |
2070 | 89 | _fade_out_animator(nullptr) | ||
2078 | 90 | { | 80 | { |
2090 | 91 | WindowManager* win_manager; | 81 | layout_->SetContentDistribution(nux::eStackLeft); |
2091 | 92 | 82 | ||
2092 | 93 | // TODO: kill _menu_layout - should just use the _layout defined | 83 | BamfWindow* active_win = bamf_matcher_get_active_window(_matcher); |
2093 | 94 | // in the base class. | 84 | if (BAMF_IS_WINDOW(active_win)) |
2094 | 95 | _menu_layout = new nux::HLayout("", NUX_TRACKER_LOCATION); | 85 | _active_xid = bamf_window_get_xid(active_win); |
2084 | 96 | _menu_layout->SetParentObject(this); | ||
2085 | 97 | |||
2086 | 98 | /* This is for our parent and for PanelView to read indicator entries, we | ||
2087 | 99 | * shouldn't touch this again | ||
2088 | 100 | */ | ||
2089 | 101 | layout_ = _menu_layout; | ||
2095 | 102 | 86 | ||
2096 | 103 | _view_opened_signal.Connect(_matcher, "view-opened", | 87 | _view_opened_signal.Connect(_matcher, "view-opened", |
2097 | 104 | sigc::mem_fun(this, &PanelMenuView::OnViewOpened)); | 88 | sigc::mem_fun(this, &PanelMenuView::OnViewOpened)); |
2098 | @@ -109,35 +93,35 @@ | |||
2099 | 109 | _active_app_changed_signal.Connect(_matcher, "active-application-changed", | 93 | _active_app_changed_signal.Connect(_matcher, "active-application-changed", |
2100 | 110 | sigc::mem_fun(this, &PanelMenuView::OnActiveAppChanged)); | 94 | sigc::mem_fun(this, &PanelMenuView::OnActiveAppChanged)); |
2101 | 111 | 95 | ||
2102 | 112 | _padding = padding; | ||
2103 | 113 | |||
2104 | 114 | _window_buttons = new WindowButtons(); | 96 | _window_buttons = new WindowButtons(); |
2105 | 97 | _window_buttons->SetMonitor(_monitor); | ||
2106 | 98 | _window_buttons->SetControlledWindow(_active_xid); | ||
2107 | 115 | _window_buttons->SetParentObject(this); | 99 | _window_buttons->SetParentObject(this); |
2109 | 116 | _window_buttons->NeedRedraw(); | 100 | _window_buttons->SetLeftAndRightPadding(MAIN_LEFT_PADDING, MENUBAR_PADDING); |
2110 | 101 | _window_buttons->SetMaximumHeight(panel::Style::Instance().panel_height); | ||
2111 | 102 | _window_buttons->ComputeContentSize(); | ||
2112 | 117 | 103 | ||
2113 | 118 | _window_buttons->close_clicked.connect(sigc::mem_fun(this, &PanelMenuView::OnCloseClicked)); | ||
2114 | 119 | _window_buttons->minimize_clicked.connect(sigc::mem_fun(this, &PanelMenuView::OnMinimizeClicked)); | ||
2115 | 120 | _window_buttons->restore_clicked.connect(sigc::mem_fun(this, &PanelMenuView::OnRestoreClicked)); | ||
2116 | 121 | _window_buttons->mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); | 104 | _window_buttons->mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); |
2117 | 122 | _window_buttons->mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); | 105 | _window_buttons->mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); |
2118 | 123 | //_window_buttons->mouse_move.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseMove)); | 106 | //_window_buttons->mouse_move.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseMove)); |
2131 | 124 | 107 | AddChild(_window_buttons); | |
2132 | 125 | _panel_titlebar_grab_area = new PanelTitlebarGrabArea(); | 108 | |
2133 | 126 | _panel_titlebar_grab_area->SetParentObject(this); | 109 | layout_->SetLeftAndRightPadding(_window_buttons->GetContentWidth(), 0); |
2134 | 127 | _panel_titlebar_grab_area->mouse_down.connect(sigc::mem_fun(this, &PanelMenuView::OnMouseClicked)); | 110 | layout_->SetBaseHeight(panel::Style::Instance().panel_height); |
2135 | 128 | _panel_titlebar_grab_area->mouse_down.connect(sigc::mem_fun(this, &PanelMenuView::OnMouseMiddleClicked)); | 111 | |
2136 | 129 | _panel_titlebar_grab_area->mouse_down.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedGrabStart)); | 112 | _titlebar_grab_area = new PanelTitlebarGrabArea(); |
2137 | 130 | _panel_titlebar_grab_area->mouse_drag.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedGrabMove)); | 113 | _titlebar_grab_area->SetParentObject(this); |
2138 | 131 | _panel_titlebar_grab_area->mouse_up.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedGrabEnd)); | 114 | _titlebar_grab_area->activate_request.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedActivate)); |
2139 | 132 | _panel_titlebar_grab_area->mouse_double_click.connect(sigc::mem_fun(this, &PanelMenuView::OnMouseDoubleClicked)); | 115 | _titlebar_grab_area->restore_request.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedRestore)); |
2140 | 133 | 116 | _titlebar_grab_area->lower_request.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedLower)); | |
2141 | 134 | win_manager = WindowManager::Default(); | 117 | _titlebar_grab_area->grab_started.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedGrabStart)); |
2142 | 135 | 118 | _titlebar_grab_area->grab_move.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedGrabMove)); | |
2143 | 119 | _titlebar_grab_area->grab_end.connect(sigc::mem_fun(this, &PanelMenuView::OnMaximizedGrabEnd)); | ||
2144 | 120 | AddChild(_titlebar_grab_area); | ||
2145 | 121 | |||
2146 | 122 | WindowManager* win_manager = WindowManager::Default(); | ||
2147 | 136 | win_manager->window_minimized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMinimized)); | 123 | win_manager->window_minimized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMinimized)); |
2148 | 137 | win_manager->window_unminimized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowUnminimized)); | 124 | win_manager->window_unminimized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowUnminimized)); |
2149 | 138 | //win_manager->initiate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadInitiate)); | ||
2150 | 139 | //win_manager->terminate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadTerminate)); | ||
2151 | 140 | |||
2152 | 141 | win_manager->window_maximized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMaximized)); | 125 | win_manager->window_maximized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMaximized)); |
2153 | 142 | win_manager->window_restored.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowRestored)); | 126 | win_manager->window_restored.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowRestored)); |
2154 | 143 | win_manager->window_unmapped.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowUnmapped)); | 127 | win_manager->window_unmapped.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowUnmapped)); |
2155 | @@ -146,39 +130,40 @@ | |||
2156 | 146 | win_manager->window_resized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMoved)); | 130 | win_manager->window_resized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMoved)); |
2157 | 147 | win_manager->window_decorated.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowDecorated)); | 131 | win_manager->window_decorated.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowDecorated)); |
2158 | 148 | win_manager->window_undecorated.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowUndecorated)); | 132 | win_manager->window_undecorated.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowUndecorated)); |
2161 | 149 | 133 | win_manager->initiate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadInitiate)); | |
2162 | 150 | panel::Style::Instance().changed.connect(sigc::mem_fun(this, &PanelMenuView::Refresh)); | 134 | win_manager->terminate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadTerminate)); |
2163 | 135 | win_manager->initiate_expo.connect(sigc::mem_fun(this, &PanelMenuView::OnExpoInitiate)); | ||
2164 | 136 | win_manager->terminate_expo.connect(sigc::mem_fun(this, &PanelMenuView::OnExpoTerminate)); | ||
2165 | 137 | win_manager->compiz_screen_viewport_switch_ended.connect(sigc::mem_fun(this, &PanelMenuView::OnExpoTerminate)); | ||
2166 | 138 | |||
2167 | 139 | _style_changed_connection = panel::Style::Instance().changed.connect([&] { | ||
2168 | 140 | _window_buttons->ComputeContentSize(); | ||
2169 | 141 | layout_->SetLeftAndRightPadding(_window_buttons->GetContentWidth(), 0); | ||
2170 | 142 | |||
2171 | 143 | Refresh(true); | ||
2172 | 144 | FullRedraw(); | ||
2173 | 145 | }); | ||
2174 | 151 | 146 | ||
2175 | 152 | mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); | 147 | mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); |
2176 | 153 | mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); | 148 | mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); |
2177 | 154 | //mouse_move.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseMove)); | 149 | //mouse_move.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseMove)); |
2178 | 155 | 150 | ||
2205 | 156 | _panel_titlebar_grab_area->mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); | 151 | _titlebar_grab_area->mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); |
2206 | 157 | _panel_titlebar_grab_area->mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); | 152 | _titlebar_grab_area->mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); |
2207 | 158 | 153 | ||
2208 | 159 | // Register for all the interesting events | 154 | _ubus_manager.RegisterInterest(UBUS_SWITCHER_SHOWN, sigc::mem_fun(this, &PanelMenuView::OnSwitcherShown)); |
2209 | 160 | UBusServer* ubus = ubus_server_get_default(); | 155 | _ubus_manager.RegisterInterest(UBUS_SWITCHER_SELECTION_CHANGED, sigc::mem_fun(this, &PanelMenuView::OnSwitcherSelectionChanged)); |
2210 | 161 | _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_OVERLAY_SHOWN, | 156 | |
2211 | 162 | (UBusCallback)PanelMenuView::OnPlaceViewShown, | 157 | _ubus_manager.RegisterInterest(UBUS_LAUNCHER_START_KEY_NAV, sigc::mem_fun(this, &PanelMenuView::OnLauncherKeyNavStarted)); |
2212 | 163 | this)); | 158 | _ubus_manager.RegisterInterest(UBUS_LAUNCHER_END_KEY_NAV, sigc::mem_fun(this, &PanelMenuView::OnLauncherKeyNavEnded)); |
2213 | 164 | _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_OVERLAY_HIDDEN, | 159 | _ubus_manager.RegisterInterest(UBUS_LAUNCHER_START_KEY_SWTICHER, sigc::mem_fun(this, &PanelMenuView::OnLauncherKeyNavStarted)); |
2214 | 165 | (UBusCallback)PanelMenuView::OnPlaceViewHidden, | 160 | _ubus_manager.RegisterInterest(UBUS_LAUNCHER_END_KEY_SWTICHER, sigc::mem_fun(this, &PanelMenuView::OnLauncherKeyNavEnded)); |
2215 | 166 | this)); | 161 | _ubus_manager.RegisterInterest(UBUS_LAUNCHER_SELECTION_CHANGED, sigc::mem_fun(this, &PanelMenuView::OnLauncherSelectionChanged)); |
2216 | 167 | 162 | ||
2217 | 168 | _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_SWITCHER_SHOWN, | 163 | _fade_in_animator.animation_updated.connect(sigc::mem_fun(this, &PanelMenuView::OnFadeInChanged)); |
2218 | 169 | (UBusCallback)PanelMenuView::OnSwitcherShown, | 164 | _fade_in_animator.animation_ended.connect(sigc::mem_fun(this, &PanelMenuView::FullRedraw)); |
2219 | 170 | this)); | 165 | _fade_out_animator.animation_updated.connect(sigc::mem_fun(this, &PanelMenuView::OnFadeOutChanged)); |
2220 | 171 | _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_SWITCHER_SELECTION_CHANGED, | 166 | _fade_out_animator.animation_ended.connect(sigc::mem_fun(this, &PanelMenuView::FullRedraw)); |
2195 | 172 | (UBusCallback)PanelMenuView::OnSwitcherSelectionChanged, | ||
2196 | 173 | this)); | ||
2197 | 174 | |||
2198 | 175 | _fade_in_animator = new Animator(_menus_fadein); | ||
2199 | 176 | _fade_out_animator = new Animator(_menus_fadeout); | ||
2200 | 177 | |||
2201 | 178 | _fade_in_animator->animation_updated.connect(sigc::mem_fun(this, &PanelMenuView::OnFadeInChanged)); | ||
2202 | 179 | _fade_in_animator->animation_ended.connect(sigc::mem_fun(this, &PanelMenuView::FullRedraw)); | ||
2203 | 180 | _fade_out_animator->animation_updated.connect(sigc::mem_fun(this, &PanelMenuView::OnFadeOutChanged)); | ||
2204 | 181 | _fade_out_animator->animation_ended.connect(sigc::mem_fun(this, &PanelMenuView::FullRedraw)); | ||
2221 | 182 | 167 | ||
2222 | 183 | SetOpacity(0.0f); | 168 | SetOpacity(0.0f); |
2223 | 184 | _window_buttons->SetOpacity(0.0f); | 169 | _window_buttons->SetOpacity(0.0f); |
2224 | @@ -198,41 +183,48 @@ | |||
2225 | 198 | if (_new_app_hide_id) | 183 | if (_new_app_hide_id) |
2226 | 199 | g_source_remove(_new_app_hide_id); | 184 | g_source_remove(_new_app_hide_id); |
2227 | 200 | 185 | ||
2228 | 201 | if (_title_layer) | ||
2229 | 202 | delete _title_layer; | ||
2230 | 203 | |||
2231 | 204 | if (_fade_in_animator) | ||
2232 | 205 | delete _fade_in_animator; | ||
2233 | 206 | |||
2234 | 207 | if (_fade_out_animator) | ||
2235 | 208 | delete _fade_out_animator; | ||
2236 | 209 | |||
2237 | 210 | _menu_layout->UnReference(); | ||
2238 | 211 | _window_buttons->UnReference(); | 186 | _window_buttons->UnReference(); |
2243 | 212 | _panel_titlebar_grab_area->UnReference(); | 187 | _titlebar_grab_area->UnReference(); |
2244 | 213 | 188 | ||
2245 | 214 | UBusServer* ubus = ubus_server_get_default(); | 189 | _style_changed_connection.disconnect(); |
2246 | 215 | for (auto interest : _ubus_interests) | 190 | } |
2247 | 191 | |||
2248 | 192 | void PanelMenuView::OverlayShown() | ||
2249 | 193 | { | ||
2250 | 194 | _overlay_showing = true; | ||
2251 | 195 | QueueDraw(); | ||
2252 | 196 | } | ||
2253 | 197 | |||
2254 | 198 | void PanelMenuView::OverlayHidden() | ||
2255 | 199 | { | ||
2256 | 200 | _overlay_showing = false; | ||
2257 | 201 | QueueDraw(); | ||
2258 | 202 | } | ||
2259 | 203 | |||
2260 | 204 | void PanelMenuView::AddIndicator(indicator::Indicator::Ptr const& indicator) | ||
2261 | 205 | { | ||
2262 | 206 | if (!GetIndicators().empty()) | ||
2263 | 216 | { | 207 | { |
2266 | 217 | if (interest != 0) | 208 | LOG_ERROR(logger) << "PanelMenuView has already an indicator!"; |
2267 | 218 | ubus_server_unregister_interest(ubus, interest); | 209 | return; |
2268 | 219 | } | 210 | } |
2269 | 211 | |||
2270 | 212 | PanelIndicatorsView::AddIndicator(indicator); | ||
2271 | 220 | } | 213 | } |
2272 | 221 | 214 | ||
2276 | 222 | void | 215 | void PanelMenuView::SetMenuShowTimings(int fadein, int fadeout, int discovery, |
2277 | 223 | PanelMenuView::SetMenuShowTimings(int fadein, int fadeout, int discovery, | 216 | int discovery_fadein, int discovery_fadeout) |
2275 | 224 | int discovery_fadein, int discovery_fadeout) | ||
2278 | 225 | { | 217 | { |
2279 | 226 | if (fadein > -1) | 218 | if (fadein > -1) |
2280 | 227 | { | 219 | { |
2281 | 228 | _menus_fadein = fadein; | 220 | _menus_fadein = fadein; |
2283 | 229 | _fade_in_animator->SetDuration(_menus_fadein); | 221 | _fade_in_animator.SetDuration(_menus_fadein); |
2284 | 230 | } | 222 | } |
2285 | 231 | 223 | ||
2286 | 232 | if (fadeout > -1) | 224 | if (fadeout > -1) |
2287 | 233 | { | 225 | { |
2288 | 234 | _menus_fadeout = fadeout; | 226 | _menus_fadeout = fadeout; |
2290 | 235 | _fade_out_animator->SetDuration(_menus_fadeout); | 227 | _fade_out_animator.SetDuration(_menus_fadeout); |
2291 | 236 | } | 228 | } |
2292 | 237 | 229 | ||
2293 | 238 | if (discovery > -1) | 230 | if (discovery > -1) |
2294 | @@ -245,16 +237,13 @@ | |||
2295 | 245 | _menus_discovery_fadeout = discovery_fadeout; | 237 | _menus_discovery_fadeout = discovery_fadeout; |
2296 | 246 | } | 238 | } |
2297 | 247 | 239 | ||
2300 | 248 | void | 240 | void PanelMenuView::FullRedraw() |
2299 | 249 | PanelMenuView::FullRedraw() | ||
2301 | 250 | { | 241 | { |
2305 | 251 | _menu_layout->NeedRedraw(); | 242 | QueueDraw(); |
2306 | 252 | _window_buttons->NeedRedraw(); | 243 | _window_buttons->QueueDraw(); |
2304 | 253 | NeedRedraw(); | ||
2307 | 254 | } | 244 | } |
2308 | 255 | 245 | ||
2311 | 256 | nux::Area* | 246 | nux::Area* PanelMenuView::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) |
2310 | 257 | PanelMenuView::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) | ||
2312 | 258 | { | 247 | { |
2313 | 259 | bool mouse_inside = TestMousePointerInclusionFilterMouseWheel(mouse_position, event_type); | 248 | bool mouse_inside = TestMousePointerInclusionFilterMouseWheel(mouse_position, event_type); |
2314 | 260 | 249 | ||
2315 | @@ -262,80 +251,59 @@ | |||
2316 | 262 | return nullptr; | 251 | return nullptr; |
2317 | 263 | 252 | ||
2318 | 264 | Area* found_area = nullptr; | 253 | Area* found_area = nullptr; |
2319 | 254 | |||
2320 | 255 | if (_overlay_showing) | ||
2321 | 256 | { | ||
2322 | 257 | if (_window_buttons) | ||
2323 | 258 | return _window_buttons->FindAreaUnderMouse(mouse_position, event_type); | ||
2324 | 259 | } | ||
2325 | 260 | |||
2326 | 265 | if (!_we_control_active) | 261 | if (!_we_control_active) |
2327 | 266 | { | 262 | { |
2330 | 267 | found_area = _panel_titlebar_grab_area->FindAreaUnderMouse(mouse_position, event_type); | 263 | /* When the current panel is not active, it all behaves like a grab-area */ |
2331 | 268 | NUX_RETURN_VALUE_IF_NOTNULL(found_area, found_area); | 264 | if (GetAbsoluteGeometry().IsInside(mouse_position)) |
2332 | 265 | return _titlebar_grab_area; | ||
2333 | 269 | } | 266 | } |
2334 | 270 | 267 | ||
2336 | 271 | if (_is_maximized || _places_showing) | 268 | if (_is_maximized) |
2337 | 272 | { | 269 | { |
2338 | 273 | if (_window_buttons) | 270 | if (_window_buttons) |
2339 | 274 | { | 271 | { |
2340 | 275 | found_area = _window_buttons->FindAreaUnderMouse(mouse_position, event_type); | 272 | found_area = _window_buttons->FindAreaUnderMouse(mouse_position, event_type); |
2341 | 276 | NUX_RETURN_VALUE_IF_NOTNULL(found_area, found_area); | 273 | NUX_RETURN_VALUE_IF_NOTNULL(found_area, found_area); |
2342 | 277 | } | 274 | } |
2364 | 278 | 275 | } | |
2365 | 279 | if (_panel_titlebar_grab_area) | 276 | |
2366 | 280 | { | 277 | if (_titlebar_grab_area && !_overlay_showing) |
2367 | 281 | found_area = _panel_titlebar_grab_area->FindAreaUnderMouse(mouse_position, event_type); | 278 | { |
2368 | 282 | NUX_RETURN_VALUE_IF_NOTNULL(found_area, found_area); | 279 | found_area = _titlebar_grab_area->FindAreaUnderMouse(mouse_position, event_type); |
2369 | 283 | } | 280 | NUX_RETURN_VALUE_IF_NOTNULL(found_area, found_area); |
2370 | 284 | } | 281 | } |
2371 | 285 | 282 | ||
2372 | 286 | if (_panel_titlebar_grab_area) | 283 | return PanelIndicatorsView::FindAreaUnderMouse(mouse_position, event_type); |
2352 | 287 | { | ||
2353 | 288 | found_area = _panel_titlebar_grab_area->FindAreaUnderMouse(mouse_position, event_type); | ||
2354 | 289 | NUX_RETURN_VALUE_IF_NOTNULL(found_area, found_area); | ||
2355 | 290 | } | ||
2356 | 291 | |||
2357 | 292 | if (!_is_own_window) | ||
2358 | 293 | { | ||
2359 | 294 | found_area = _menu_layout->FindAreaUnderMouse(mouse_position, event_type); | ||
2360 | 295 | NUX_RETURN_VALUE_IF_NOTNULL(found_area, found_area); | ||
2361 | 296 | } | ||
2362 | 297 | |||
2363 | 298 | return View::FindAreaUnderMouse(mouse_position, event_type); | ||
2373 | 299 | } | 284 | } |
2374 | 300 | 285 | ||
2376 | 301 | long PanelMenuView::PostLayoutManagement(long LayoutResult) | 286 | void PanelMenuView::PreLayoutManagement() |
2377 | 302 | { | 287 | { |
2389 | 303 | long res = View::PostLayoutManagement(LayoutResult); | 288 | PanelIndicatorsView::PreLayoutManagement(); |
2390 | 304 | int old_window_buttons_w, new_window_buttons_w; | 289 | nux::Geometry const& geo = GetGeometry(); |
2391 | 305 | int old_menu_area_w, new_menu_area_w; | 290 | |
2381 | 306 | |||
2382 | 307 | nux::Geometry geo = GetGeometry(); | ||
2383 | 308 | |||
2384 | 309 | int h_padding = _padding - 2; | ||
2385 | 310 | int v_padding = 1; | ||
2386 | 311 | |||
2387 | 312 | old_window_buttons_w = _window_buttons->GetContentWidth(); | ||
2388 | 313 | _window_buttons->SetGeometry(geo.x + h_padding, geo.y + v_padding, old_window_buttons_w, geo.height); | ||
2392 | 314 | _window_buttons->ComputeContentSize(); | 291 | _window_buttons->ComputeContentSize(); |
2413 | 315 | new_window_buttons_w = _window_buttons->GetContentWidth(); | 292 | int buttons_diff = geo.height - _window_buttons->GetContentHeight(); |
2414 | 316 | 293 | _window_buttons->SetBaseY(buttons_diff > 0 ? std::ceil(buttons_diff/2.0f) : 0); | |
2415 | 317 | /* Explicitly set the size and position of the widgets */ | 294 | |
2416 | 318 | geo.x += h_padding + new_window_buttons_w + h_padding; | 295 | layout_->ComputeContentSize(); |
2417 | 319 | geo.width -= h_padding + new_window_buttons_w + h_padding; | 296 | int layout_width = layout_->GetContentWidth(); |
2418 | 320 | 297 | ||
2419 | 321 | old_menu_area_w = _menu_layout->GetContentWidth(); | 298 | _titlebar_grab_area->SetBaseX(layout_width); |
2420 | 322 | _menu_layout->SetGeometry(geo.x, geo.y, old_menu_area_w, geo.height); | 299 | _titlebar_grab_area->SetBaseHeight(geo.height); |
2421 | 323 | _menu_layout->ComputeContentSize(); | 300 | _titlebar_grab_area->SetMinimumWidth(geo.width - layout_width); |
2422 | 324 | new_menu_area_w = _menu_layout->GetContentWidth(); | 301 | _titlebar_grab_area->SetMaximumWidth(geo.width - layout_width); |
2423 | 325 | 302 | ||
2424 | 326 | geo.x += new_menu_area_w; | 303 | SetMaximumEntriesWidth(geo.width - _window_buttons->GetContentWidth()); |
2405 | 327 | geo.width -= new_menu_area_w; | ||
2406 | 328 | |||
2407 | 329 | _panel_titlebar_grab_area->SetGeometry(geo.x, geo.y, geo.width, geo.height); | ||
2408 | 330 | |||
2409 | 331 | if (_is_inside) | ||
2410 | 332 | NeedRedraw(); | ||
2411 | 333 | |||
2412 | 334 | return res; | ||
2425 | 335 | } | 304 | } |
2426 | 336 | 305 | ||
2429 | 337 | void | 306 | void PanelMenuView::OnFadeInChanged(double opacity) |
2428 | 338 | PanelMenuView::OnFadeInChanged(double opacity) | ||
2430 | 339 | { | 307 | { |
2431 | 340 | if (DrawMenus() && GetOpacity() != 1.0f) | 308 | if (DrawMenus() && GetOpacity() != 1.0f) |
2432 | 341 | SetOpacity(opacity); | 309 | SetOpacity(opacity); |
2433 | @@ -343,11 +311,10 @@ | |||
2434 | 343 | if (DrawWindowButtons() && _window_buttons->GetOpacity() != 1.0f) | 311 | if (DrawWindowButtons() && _window_buttons->GetOpacity() != 1.0f) |
2435 | 344 | _window_buttons->SetOpacity(opacity); | 312 | _window_buttons->SetOpacity(opacity); |
2436 | 345 | 313 | ||
2438 | 346 | NeedRedraw(); | 314 | QueueDraw(); |
2439 | 347 | } | 315 | } |
2440 | 348 | 316 | ||
2443 | 349 | void | 317 | void PanelMenuView::OnFadeOutChanged(double progress) |
2442 | 350 | PanelMenuView::OnFadeOutChanged(double progress) | ||
2444 | 351 | { | 318 | { |
2445 | 352 | double opacity = CLAMP(1.0f - progress, 0.0f, 1.0f); | 319 | double opacity = CLAMP(1.0f - progress, 0.0f, 1.0f); |
2446 | 353 | 320 | ||
2447 | @@ -357,13 +324,16 @@ | |||
2448 | 357 | if (!DrawWindowButtons() && _window_buttons->GetOpacity() != 0.0f) | 324 | if (!DrawWindowButtons() && _window_buttons->GetOpacity() != 0.0f) |
2449 | 358 | _window_buttons->SetOpacity(opacity); | 325 | _window_buttons->SetOpacity(opacity); |
2450 | 359 | 326 | ||
2452 | 360 | NeedRedraw(); | 327 | QueueDraw(); |
2453 | 361 | } | 328 | } |
2454 | 362 | 329 | ||
2457 | 363 | bool | 330 | bool PanelMenuView::DrawMenus() const |
2456 | 364 | PanelMenuView::DrawMenus() | ||
2458 | 365 | { | 331 | { |
2460 | 366 | if (!_is_own_window && !_places_showing && _we_control_active && !_switcher_showing) | 332 | auto wm = WindowManager::Default(); |
2461 | 333 | bool screen_grabbed = (wm->IsExpoActive() || wm->IsScaleActive()); | ||
2462 | 334 | |||
2463 | 335 | if (_we_control_active && !_overlay_showing && !screen_grabbed && | ||
2464 | 336 | !_switcher_showing && !_launcher_keynav) | ||
2465 | 367 | { | 337 | { |
2466 | 368 | if (_is_inside || _last_active_view || _show_now_activated || _new_application) | 338 | if (_is_inside || _last_active_view || _show_now_activated || _new_application) |
2467 | 369 | { | 339 | { |
2468 | @@ -374,13 +344,16 @@ | |||
2469 | 374 | return false; | 344 | return false; |
2470 | 375 | } | 345 | } |
2471 | 376 | 346 | ||
2474 | 377 | bool | 347 | bool PanelMenuView::DrawWindowButtons() const |
2473 | 378 | PanelMenuView::DrawWindowButtons() | ||
2475 | 379 | { | 348 | { |
2477 | 380 | if (_places_showing) | 349 | auto wm = WindowManager::Default(); |
2478 | 350 | bool screen_grabbed = (wm->IsExpoActive() || wm->IsScaleActive()); | ||
2479 | 351 | |||
2480 | 352 | if (_overlay_showing) | ||
2481 | 381 | return true; | 353 | return true; |
2482 | 382 | 354 | ||
2484 | 383 | if (!_is_own_window && _we_control_active && _is_maximized && !_switcher_showing) | 355 | if (_we_control_active && _is_maximized && !screen_grabbed && |
2485 | 356 | !_launcher_keynav && !_switcher_showing) | ||
2486 | 384 | { | 357 | { |
2487 | 385 | if (_is_inside || _show_now_activated || _new_application) | 358 | if (_is_inside || _show_now_activated || _new_application) |
2488 | 386 | { | 359 | { |
2489 | @@ -391,19 +364,18 @@ | |||
2490 | 391 | return false; | 364 | return false; |
2491 | 392 | } | 365 | } |
2492 | 393 | 366 | ||
2495 | 394 | void | 367 | void PanelMenuView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) |
2494 | 395 | PanelMenuView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
2496 | 396 | { | 368 | { |
2500 | 397 | nux::Geometry geo = GetGeometry(); | 369 | nux::Geometry const& geo = GetGeometry(); |
2501 | 398 | int button_width = _padding + _window_buttons->GetContentWidth() + _padding; | 370 | int button_width = _window_buttons->GetContentWidth(); |
2502 | 399 | float factor = 4; | 371 | const float factor = 4; |
2503 | 400 | button_width /= factor; | 372 | button_width /= factor; |
2504 | 401 | 373 | ||
2506 | 402 | if (geo.width != _last_width || geo.height != _last_height) | 374 | if (geo != _last_geo) |
2507 | 403 | { | 375 | { |
2511 | 404 | _last_width = geo.width; | 376 | _last_geo = geo; |
2512 | 405 | _last_height = geo.height; | 377 | QueueRelayout(); |
2513 | 406 | Refresh(); | 378 | Refresh(true); |
2514 | 407 | } | 379 | } |
2515 | 408 | 380 | ||
2516 | 409 | GfxContext.PushClippingRectangle(geo); | 381 | GfxContext.PushClippingRectangle(geo); |
2517 | @@ -417,7 +389,7 @@ | |||
2518 | 417 | nux::ColorLayer layer(nux::Color(0x00000000), true, rop); | 389 | nux::ColorLayer layer(nux::Color(0x00000000), true, rop); |
2519 | 418 | nux::GetPainter().PushDrawLayer(GfxContext, GetGeometry(), &layer); | 390 | nux::GetPainter().PushDrawLayer(GfxContext, GetGeometry(), &layer); |
2520 | 419 | 391 | ||
2522 | 420 | if (_title_layer && !_is_own_window) | 392 | if (_title_texture) |
2523 | 421 | { | 393 | { |
2524 | 422 | guint blend_alpha = 0, blend_src = 0, blend_dest = 0; | 394 | guint blend_alpha = 0, blend_src = 0, blend_dest = 0; |
2525 | 423 | bool draw_menus = DrawMenus(); | 395 | bool draw_menus = DrawMenus(); |
2526 | @@ -429,7 +401,7 @@ | |||
2527 | 429 | 401 | ||
2528 | 430 | for (auto entry : entries_) | 402 | for (auto entry : entries_) |
2529 | 431 | { | 403 | { |
2531 | 432 | if (entry.second->IsEntryValid()) | 404 | if (entry.second->IsVisible()) |
2532 | 433 | { | 405 | { |
2533 | 434 | has_menu = true; | 406 | has_menu = true; |
2534 | 435 | break; | 407 | break; |
2535 | @@ -542,20 +514,22 @@ | |||
2536 | 542 | geo.width, geo.height, | 514 | geo.width, geo.height, |
2537 | 543 | _gradient_texture, texxform0, | 515 | _gradient_texture, texxform0, |
2538 | 544 | nux::color::White, | 516 | nux::color::White, |
2540 | 545 | _title_layer->GetDeviceTexture(), | 517 | _title_texture->GetDeviceTexture(), |
2541 | 546 | texxform1, | 518 | texxform1, |
2542 | 547 | nux::color::White); | 519 | nux::color::White); |
2543 | 548 | } | 520 | } |
2545 | 549 | else if (!_places_showing) | 521 | else if (!_overlay_showing) |
2546 | 550 | { | 522 | { |
2547 | 523 | double title_opacity = 0.0f; | ||
2548 | 524 | |||
2549 | 551 | if (_we_control_active && _window_buttons->GetOpacity() == 0.0 && | 525 | if (_we_control_active && _window_buttons->GetOpacity() == 0.0 && |
2550 | 552 | (!has_menu || (has_menu && GetOpacity() == 0.0))) | 526 | (!has_menu || (has_menu && GetOpacity() == 0.0))) |
2551 | 553 | { | 527 | { |
2553 | 554 | nux::GetPainter().PushDrawLayer(GfxContext, geo, _title_layer); | 528 | title_opacity = 1.0f; |
2554 | 555 | } | 529 | } |
2555 | 556 | else | 530 | else |
2556 | 557 | { | 531 | { |
2558 | 558 | double title_opacity = 1.0f; | 532 | title_opacity = 1.0f; |
2559 | 559 | 533 | ||
2560 | 560 | if (has_menu) | 534 | if (has_menu) |
2561 | 561 | title_opacity -= MAX(GetOpacity(), _window_buttons->GetOpacity()); | 535 | title_opacity -= MAX(GetOpacity(), _window_buttons->GetOpacity()); |
2562 | @@ -572,10 +546,13 @@ | |||
2563 | 572 | // If we're fading-in the buttons/menus, let's fade-out quickly the title | 546 | // If we're fading-in the buttons/menus, let's fade-out quickly the title |
2564 | 573 | title_opacity = CLAMP(title_opacity - 0.2f, 0.0f, 1.0f); | 547 | title_opacity = CLAMP(title_opacity - 0.2f, 0.0f, 1.0f); |
2565 | 574 | } | 548 | } |
2566 | 549 | } | ||
2567 | 575 | 550 | ||
2568 | 551 | if (title_opacity > 0.0f) | ||
2569 | 552 | { | ||
2570 | 576 | nux::TexCoordXForm texxform; | 553 | nux::TexCoordXForm texxform; |
2571 | 577 | GfxContext.QRP_1Tex(geo.x, geo.y, geo.width, geo.height, | 554 | GfxContext.QRP_1Tex(geo.x, geo.y, geo.width, geo.height, |
2573 | 578 | _title_layer->GetDeviceTexture(), texxform, | 555 | _title_texture->GetDeviceTexture(), texxform, |
2574 | 579 | nux::color::White * title_opacity); | 556 | nux::color::White * title_opacity); |
2575 | 580 | } | 557 | } |
2576 | 581 | } | 558 | } |
2577 | @@ -588,10 +565,9 @@ | |||
2578 | 588 | GfxContext.PopClippingRectangle(); | 565 | GfxContext.PopClippingRectangle(); |
2579 | 589 | } | 566 | } |
2580 | 590 | 567 | ||
2583 | 591 | void | 568 | void PanelMenuView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) |
2582 | 592 | PanelMenuView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
2584 | 593 | { | 569 | { |
2586 | 594 | nux::Geometry geo = GetGeometry(); | 570 | nux::Geometry const& geo = GetGeometry(); |
2587 | 595 | bool draw_menus = DrawMenus(); | 571 | bool draw_menus = DrawMenus(); |
2588 | 596 | bool draw_buttons = DrawWindowButtons(); | 572 | bool draw_buttons = DrawWindowButtons(); |
2589 | 597 | 573 | ||
2590 | @@ -602,17 +578,17 @@ | |||
2591 | 602 | for (auto entry : entries_) | 578 | for (auto entry : entries_) |
2592 | 603 | entry.second->SetDisabled(false); | 579 | entry.second->SetDisabled(false); |
2593 | 604 | 580 | ||
2595 | 605 | _menu_layout->ProcessDraw(GfxContext, true); | 581 | layout_->ProcessDraw(GfxContext, true); |
2596 | 606 | 582 | ||
2598 | 607 | _fade_out_animator->Stop(); | 583 | _fade_out_animator.Stop(); |
2599 | 608 | 584 | ||
2600 | 609 | if (_new_application && !_is_inside) | 585 | if (_new_application && !_is_inside) |
2601 | 610 | { | 586 | { |
2603 | 611 | _fade_in_animator->Start(_menus_discovery_fadein, GetOpacity()); | 587 | _fade_in_animator.Start(_menus_discovery_fadein, GetOpacity()); |
2604 | 612 | } | 588 | } |
2605 | 613 | else | 589 | else |
2606 | 614 | { | 590 | { |
2608 | 615 | _fade_in_animator->Start(GetOpacity()); | 591 | _fade_in_animator.Start(GetOpacity()); |
2609 | 616 | _new_app_menu_shown = false; | 592 | _new_app_menu_shown = false; |
2610 | 617 | } | 593 | } |
2611 | 618 | } | 594 | } |
2612 | @@ -622,19 +598,19 @@ | |||
2613 | 622 | entry.second->SetDisabled(true); | 598 | entry.second->SetDisabled(true); |
2614 | 623 | } | 599 | } |
2615 | 624 | 600 | ||
2617 | 625 | if (GetOpacity() != 0.0f && !draw_menus) | 601 | if (GetOpacity() != 0.0f && !draw_menus && !_overlay_showing) |
2618 | 626 | { | 602 | { |
2620 | 627 | _menu_layout->ProcessDraw(GfxContext, true); | 603 | layout_->ProcessDraw(GfxContext, true); |
2621 | 628 | 604 | ||
2623 | 629 | _fade_in_animator->Stop(); | 605 | _fade_in_animator.Stop(); |
2624 | 630 | 606 | ||
2625 | 631 | if (!_new_app_menu_shown) | 607 | if (!_new_app_menu_shown) |
2626 | 632 | { | 608 | { |
2628 | 633 | _fade_out_animator->Start(1.0f - GetOpacity()); | 609 | _fade_out_animator.Start(1.0f - GetOpacity()); |
2629 | 634 | } | 610 | } |
2630 | 635 | else | 611 | else |
2631 | 636 | { | 612 | { |
2633 | 637 | _fade_out_animator->Start(_menus_discovery_fadeout, 1.0f - GetOpacity()); | 613 | _fade_out_animator.Start(_menus_discovery_fadeout, 1.0f - GetOpacity()); |
2634 | 638 | } | 614 | } |
2635 | 639 | } | 615 | } |
2636 | 640 | 616 | ||
2637 | @@ -642,299 +618,260 @@ | |||
2638 | 642 | { | 618 | { |
2639 | 643 | _window_buttons->ProcessDraw(GfxContext, true); | 619 | _window_buttons->ProcessDraw(GfxContext, true); |
2640 | 644 | 620 | ||
2643 | 645 | _fade_out_animator->Stop(); | 621 | if (_window_buttons->GetOpacity() != 1.0f) |
2644 | 646 | _fade_in_animator->Start(_window_buttons->GetOpacity()); | 622 | { |
2645 | 623 | _fade_out_animator.Stop(); | ||
2646 | 624 | _fade_in_animator.Start(_window_buttons->GetOpacity()); | ||
2647 | 625 | } | ||
2648 | 647 | } | 626 | } |
2649 | 648 | 627 | ||
2650 | 649 | if (_window_buttons->GetOpacity() != 0.0f && !draw_buttons) | 628 | if (_window_buttons->GetOpacity() != 0.0f && !draw_buttons) |
2651 | 650 | { | 629 | { |
2652 | 651 | _window_buttons->ProcessDraw(GfxContext, true); | 630 | _window_buttons->ProcessDraw(GfxContext, true); |
2654 | 652 | _fade_in_animator->Stop(); | 631 | _fade_in_animator.Stop(); |
2655 | 653 | 632 | ||
2656 | 654 | /* If we try to hide only the buttons, then use a faster fadeout */ | 633 | /* If we try to hide only the buttons, then use a faster fadeout */ |
2658 | 655 | if (!_fade_out_animator->IsRunning()) | 634 | if (!_fade_out_animator.IsRunning()) |
2659 | 656 | { | 635 | { |
2661 | 657 | _fade_out_animator->Start(_menus_fadeout/3, 1.0f - _window_buttons->GetOpacity()); | 636 | _fade_out_animator.Start(_menus_fadeout/3, 1.0f - _window_buttons->GetOpacity()); |
2662 | 658 | } | 637 | } |
2663 | 659 | } | 638 | } |
2664 | 660 | 639 | ||
2665 | 661 | GfxContext.PopClippingRectangle(); | 640 | GfxContext.PopClippingRectangle(); |
2666 | 662 | } | 641 | } |
2667 | 663 | 642 | ||
2670 | 664 | gchar* | 643 | std::string PanelMenuView::GetActiveViewName(bool use_appname) const |
2669 | 665 | PanelMenuView::GetActiveViewName() | ||
2671 | 666 | { | 644 | { |
2676 | 667 | gchar* label = nullptr; | 645 | std::string label; |
2677 | 668 | BamfWindow* window; | 646 | BamfWindow* window; |
2674 | 669 | |||
2675 | 670 | _is_own_window = false; | ||
2678 | 671 | 647 | ||
2679 | 672 | window = bamf_matcher_get_active_window(_matcher); | 648 | window = bamf_matcher_get_active_window(_matcher); |
2680 | 649 | |||
2681 | 673 | if (BAMF_IS_WINDOW(window)) | 650 | if (BAMF_IS_WINDOW(window)) |
2682 | 674 | { | 651 | { |
2683 | 652 | BamfView *view = reinterpret_cast<BamfView*>(window); | ||
2684 | 675 | std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList(); | 653 | std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList(); |
2686 | 676 | guint32 window_xid = bamf_window_get_xid(BAMF_WINDOW(window)); | 654 | Window window_xid = bamf_window_get_xid(window); |
2687 | 677 | 655 | ||
2688 | 678 | if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end()) | 656 | if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end()) |
2689 | 679 | { | 657 | { |
2757 | 680 | _is_own_window = true; | 658 | /* If the active window is an unity window, we need to fallback to the |
2758 | 681 | return g_strdup(""); | 659 | * top one, anyway we should always avoid to focus unity internal windows */ |
2759 | 682 | } | 660 | BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow()); |
2760 | 683 | 661 | ||
2761 | 684 | if (BAMF_IS_WINDOW(window) && | 662 | if (top_win && top_win != window) |
2762 | 685 | bamf_window_get_window_type(window) == BAMF_WINDOW_DESKTOP) | 663 | { |
2763 | 686 | { | 664 | window = top_win; |
2764 | 687 | label = g_strdup(_("Ubuntu Desktop")); | 665 | } |
2765 | 688 | } | 666 | else |
2766 | 689 | else if (!WindowManager::Default()->IsWindowOnCurrentDesktop(window_xid) || | 667 | { |
2767 | 690 | WindowManager::Default()->IsWindowObscured(window_xid)) | 668 | return ""; |
2768 | 691 | { | 669 | } |
2769 | 692 | return g_strdup(""); | 670 | } |
2770 | 693 | } | 671 | |
2771 | 694 | 672 | if (bamf_window_get_window_type(window) == BAMF_WINDOW_DESKTOP) | |
2772 | 695 | if (_is_maximized) | 673 | { |
2773 | 696 | label = bamf_view_get_name(BAMF_VIEW(window)); | 674 | label = DESKTOP_NAME; |
2774 | 697 | } | 675 | } |
2775 | 698 | 676 | else if (!IsValidWindow(window_xid)) | |
2776 | 699 | if (!label) | 677 | { |
2777 | 700 | { | 678 | return ""; |
2778 | 701 | BamfApplication* app = bamf_matcher_get_active_application(_matcher); | 679 | } |
2779 | 702 | if (BAMF_IS_APPLICATION(app)) | 680 | |
2780 | 703 | { | 681 | if (WindowManager::Default()->IsWindowMaximized(window_xid) && !use_appname) |
2781 | 704 | const gchar* filename; | 682 | { |
2782 | 705 | 683 | label = glib::String(bamf_view_get_name(view)).Str(); | |
2783 | 706 | filename = bamf_application_get_desktop_file(app); | 684 | } |
2784 | 707 | 685 | ||
2785 | 708 | if (filename && g_strcmp0(filename, "") != 0) | 686 | if (label.empty()) |
2786 | 709 | { | 687 | { |
2787 | 710 | GDesktopAppInfo* info; | 688 | BamfApplication* app; |
2788 | 711 | 689 | app = bamf_matcher_get_application_for_window(_matcher, window); | |
2789 | 712 | info = g_desktop_app_info_new_from_filename(bamf_application_get_desktop_file(app)); | 690 | |
2790 | 713 | 691 | if (BAMF_IS_APPLICATION(app)) | |
2791 | 714 | if (info) | 692 | { |
2792 | 715 | { | 693 | view = reinterpret_cast<BamfView*>(app); |
2793 | 716 | label = g_strdup(g_app_info_get_display_name(G_APP_INFO(info))); | 694 | label = glib::String(bamf_view_get_name(view)).Str(); |
2794 | 717 | g_object_unref(info); | 695 | } |
2795 | 718 | } | 696 | } |
2796 | 719 | else | 697 | |
2797 | 720 | { | 698 | if (label.empty()) |
2798 | 721 | g_warning("Unable to get GDesktopAppInfo for %s", | 699 | { |
2799 | 722 | bamf_application_get_desktop_file(app)); | 700 | view = reinterpret_cast<BamfView*>(window); |
2800 | 723 | } | 701 | label = glib::String(bamf_view_get_name(view)).Str(); |
2801 | 724 | } | 702 | } |
2802 | 725 | 703 | } | |
2736 | 726 | if (label == nullptr) | ||
2737 | 727 | { | ||
2738 | 728 | BamfView* active_view; | ||
2739 | 729 | |||
2740 | 730 | active_view = (BamfView*)bamf_matcher_get_active_window(_matcher); | ||
2741 | 731 | if (BAMF_IS_VIEW(active_view)) | ||
2742 | 732 | label = bamf_view_get_name(active_view); | ||
2743 | 733 | else | ||
2744 | 734 | label = g_strdup(""); | ||
2745 | 735 | } | ||
2746 | 736 | } | ||
2747 | 737 | else | ||
2748 | 738 | { | ||
2749 | 739 | label = g_strdup(" "); | ||
2750 | 740 | } | ||
2751 | 741 | } | ||
2752 | 742 | |||
2753 | 743 | char *escaped = g_markup_escape_text(label, -1); | ||
2754 | 744 | g_free(label); | ||
2755 | 745 | label = g_strdup_printf("<b>%s</b>", escaped); | ||
2756 | 746 | g_free(escaped); | ||
2803 | 747 | 704 | ||
2804 | 748 | return label; | 705 | return label; |
2805 | 749 | } | 706 | } |
2806 | 750 | 707 | ||
2813 | 751 | void PanelMenuView::DrawText(cairo_t *cr_real, | 708 | void PanelMenuView::DrawTitle(cairo_t *cr_real, nux::Geometry const& geo, std::string const& label) const |
2808 | 752 | int &x, int y, int width, int height, | ||
2809 | 753 | const char* font_desc, | ||
2810 | 754 | const char* label, | ||
2811 | 755 | int increase_size | ||
2812 | 756 | ) | ||
2814 | 757 | { | 709 | { |
2926 | 758 | PangoLayout* layout = nullptr; | 710 | using namespace panel; |
2927 | 759 | PangoFontDescription* desc = nullptr; | 711 | cairo_t* cr; |
2928 | 760 | GtkSettings* settings = gtk_settings_get_default(); | 712 | cairo_pattern_t* linpat; |
2929 | 761 | cairo_t* cr; | 713 | const int fading_pixels = 35; |
2930 | 762 | cairo_pattern_t* linpat; | 714 | int x = MAIN_LEFT_PADDING + TITLE_PADDING + geo.x; |
2931 | 763 | GdkScreen* screen = gdk_screen_get_default(); | 715 | int y = geo.y; |
2932 | 764 | int dpi = 0; | 716 | |
2933 | 765 | const int fading_pixels = 35; | 717 | int text_width = 0; |
2934 | 766 | char *font_description = g_strdup(font_desc); | 718 | int text_height = 0; |
2935 | 767 | 719 | int text_space = 0; | |
2936 | 768 | int text_width = 0; | 720 | |
2937 | 769 | int text_height = 0; | 721 | // Find out dimensions first |
2938 | 770 | int text_space = 0; | 722 | GdkScreen* screen = gdk_screen_get_default(); |
2939 | 771 | 723 | PangoContext* cxt; | |
2940 | 772 | { // Find out dimensions first | 724 | PangoRectangle log_rect; |
2941 | 773 | GConfClient* client = gconf_client_get_default(); | 725 | PangoFontDescription* desc; |
2942 | 774 | PangoContext* cxt; | 726 | |
2943 | 775 | PangoRectangle log_rect; | 727 | nux::CairoGraphics util_cg(CAIRO_FORMAT_ARGB32, 1, 1); |
2944 | 776 | 728 | cr = util_cg.GetContext(); | |
2945 | 777 | cr = _util_cg.GetContext(); | 729 | |
2946 | 778 | 730 | int dpi = Style::Instance().GetTextDPI(); | |
2947 | 779 | g_object_get(settings, "gtk-xft-dpi", &dpi, nullptr); | 731 | |
2948 | 780 | 732 | std::string font_description(Style::Instance().GetFontDescription(PanelItem::TITLE)); | |
2949 | 781 | font_description = gconf_client_get_string(client, WINDOW_TITLE_FONT_KEY.c_str(), nullptr); | 733 | desc = pango_font_description_from_string(font_description.c_str()); |
2950 | 782 | desc = pango_font_description_from_string(font_description); | 734 | |
2951 | 783 | 735 | glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr)); | |
2952 | 784 | if (font_desc) | 736 | pango_layout_set_font_description(layout, desc); |
2953 | 785 | { | 737 | pango_layout_set_markup(layout, label.c_str(), -1); |
2954 | 786 | int size = pango_font_description_get_size(desc); | 738 | |
2955 | 787 | size /= pango_font_description_get_size_is_absolute(desc) ? 1 : PANGO_SCALE; | 739 | cxt = pango_layout_get_context(layout); |
2956 | 788 | 740 | pango_cairo_context_set_font_options(cxt, gdk_screen_get_font_options(screen)); | |
2957 | 789 | // Adjust y depending on size of the font | 741 | pango_cairo_context_set_resolution(cxt, dpi / static_cast<float>(PANGO_SCALE)); |
2958 | 790 | y -= ((unsigned int)(size - 9)) / 2; | 742 | pango_layout_context_changed(layout); |
2959 | 791 | 743 | ||
2960 | 792 | size += increase_size; | 744 | pango_layout_get_extents(layout, nullptr, &log_rect); |
2961 | 793 | 745 | text_width = log_rect.width / PANGO_SCALE; | |
2962 | 794 | char* description = g_strdup_printf("%s %d", font_desc, size); | 746 | text_height = log_rect.height / PANGO_SCALE; |
2963 | 795 | pango_font_description_free(desc); | 747 | |
2964 | 796 | desc = pango_font_description_from_string(description); | 748 | pango_font_description_free(desc); |
2965 | 797 | g_free(description); | 749 | cairo_destroy(cr); |
2966 | 798 | } | 750 | |
2967 | 799 | 751 | // Draw the text | |
2968 | 800 | layout = pango_cairo_create_layout(cr); | 752 | GtkStyleContext* style_context = Style::Instance().GetStyleContext(); |
2969 | 801 | pango_layout_set_font_description(layout, desc); | 753 | text_space = geo.width - x; |
2970 | 802 | pango_layout_set_markup(layout, label, -1); | 754 | cr = cr_real; |
2971 | 803 | 755 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | |
2972 | 804 | cxt = pango_layout_get_context(layout); | 756 | |
2973 | 805 | pango_cairo_context_set_font_options(cxt, gdk_screen_get_font_options(screen)); | 757 | gtk_style_context_save(style_context); |
2974 | 806 | pango_cairo_context_set_resolution(cxt, (float)dpi / (float)PANGO_SCALE); | 758 | |
2975 | 807 | pango_layout_context_changed(layout); | 759 | GtkWidgetPath* widget_path = gtk_widget_path_new(); |
2976 | 808 | 760 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | |
2977 | 809 | pango_layout_get_extents(layout, nullptr, &log_rect); | 761 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); |
2978 | 810 | text_width = log_rect.width / PANGO_SCALE; | 762 | gtk_widget_path_iter_set_name(widget_path, -1 , "UnityPanelWidget"); |
2979 | 811 | text_height = log_rect.height / PANGO_SCALE; | 763 | |
2980 | 812 | 764 | gtk_style_context_set_path(style_context, widget_path); | |
2981 | 813 | pango_font_description_free(desc); | 765 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); |
2982 | 814 | g_free(font_description); | 766 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); |
2983 | 815 | cairo_destroy(cr); | 767 | |
2984 | 816 | g_object_unref(client); | 768 | y += (geo.height - text_height) / 2; |
2985 | 817 | } | 769 | |
2986 | 818 | 770 | pango_cairo_update_layout(cr, layout); | |
2987 | 819 | { // Draw the text | 771 | |
2988 | 820 | GtkStyleContext* style_context = panel::Style::Instance().GetStyleContext(); | 772 | if (text_width > text_space) |
2989 | 821 | text_space = width - x; | 773 | { |
2990 | 822 | cr = cr_real; | 774 | int out_pixels = text_width - text_space; |
2991 | 823 | 775 | int fading_width = out_pixels < fading_pixels ? out_pixels : fading_pixels; | |
2992 | 824 | gtk_style_context_save(style_context); | 776 | |
2993 | 825 | 777 | cairo_push_group(cr); | |
2994 | 826 | GtkWidgetPath* widget_path = gtk_widget_path_new(); | 778 | gtk_render_layout(style_context, cr, x, y, layout); |
2995 | 827 | gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW); | 779 | cairo_pop_group_to_source(cr); |
2996 | 828 | gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); | 780 | |
2997 | 829 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_BAR); | 781 | linpat = cairo_pattern_create_linear(geo.width - fading_width, y, geo.width, y); |
2998 | 830 | gtk_widget_path_append_type(widget_path, GTK_TYPE_MENU_ITEM); | 782 | cairo_pattern_add_color_stop_rgba(linpat, 0, 0, 0, 0, 1); |
2999 | 831 | 783 | cairo_pattern_add_color_stop_rgba(linpat, 1, 0, 0, 0, 0); | |
3000 | 832 | gtk_style_context_set_path(style_context, widget_path); | 784 | cairo_mask(cr, linpat); |
3001 | 833 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR); | 785 | |
3002 | 834 | gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM); | 786 | cairo_pattern_destroy(linpat); |
3003 | 835 | 787 | } | |
3004 | 836 | y += (height - text_height) / 2; | 788 | else |
3005 | 837 | 789 | { | |
3006 | 838 | pango_cairo_update_layout(cr, layout); | 790 | gtk_render_layout(style_context, cr, x, y, layout); |
3007 | 839 | 791 | } | |
3008 | 840 | if (text_width > text_space) | 792 | |
3009 | 841 | { | 793 | x += text_width; |
3010 | 842 | int out_pixels = text_width - text_space; | 794 | |
3011 | 843 | int fading_width = out_pixels < fading_pixels ? out_pixels : fading_pixels; | 795 | gtk_widget_path_free(widget_path); |
3012 | 844 | 796 | gtk_style_context_restore(style_context); | |
2902 | 845 | cairo_push_group(cr); | ||
2903 | 846 | gtk_render_layout(style_context, cr, x, y, layout); | ||
2904 | 847 | cairo_pop_group_to_source(cr); | ||
2905 | 848 | |||
2906 | 849 | linpat = cairo_pattern_create_linear(width - fading_width, y, width, y); | ||
2907 | 850 | cairo_pattern_add_color_stop_rgba(linpat, 0, 0, 0, 0, 1); | ||
2908 | 851 | cairo_pattern_add_color_stop_rgba(linpat, 1, 0, 0, 0, 0); | ||
2909 | 852 | cairo_mask(cr, linpat); | ||
2910 | 853 | |||
2911 | 854 | cairo_pattern_destroy(linpat); | ||
2912 | 855 | } | ||
2913 | 856 | else | ||
2914 | 857 | { | ||
2915 | 858 | gtk_render_layout(style_context, cr, x, y, layout); | ||
2916 | 859 | } | ||
2917 | 860 | |||
2918 | 861 | x += text_width; | ||
2919 | 862 | |||
2920 | 863 | gtk_widget_path_free(widget_path); | ||
2921 | 864 | gtk_style_context_restore(style_context); | ||
2922 | 865 | } | ||
2923 | 866 | |||
2924 | 867 | if (layout) | ||
2925 | 868 | g_object_unref(layout); | ||
3013 | 869 | } | 797 | } |
3014 | 870 | 798 | ||
3017 | 871 | void | 799 | void PanelMenuView::Refresh(bool force) |
3016 | 872 | PanelMenuView::Refresh() | ||
3018 | 873 | { | 800 | { |
3020 | 874 | nux::Geometry geo = GetGeometry(); | 801 | nux::Geometry const& geo = GetGeometry(); |
3021 | 875 | 802 | ||
3022 | 876 | // We can get into a race that causes the geometry to be wrong as there hasn't been a | 803 | // We can get into a race that causes the geometry to be wrong as there hasn't been a |
3023 | 877 | // layout cycle before the first callback. This is to protect from that. | 804 | // layout cycle before the first callback. This is to protect from that. |
3024 | 878 | if (geo.width > _monitor_geo.width) | 805 | if (geo.width > _monitor_geo.width) |
3025 | 879 | return; | 806 | return; |
3026 | 880 | 807 | ||
3033 | 881 | int x = 0; | 808 | auto win_manager = WindowManager::Default(); |
3034 | 882 | int y = 0; | 809 | std::string new_title; |
3035 | 883 | int width = geo.width; | 810 | |
3036 | 884 | int height = geo.height; | 811 | if (win_manager->IsScaleActive()) |
3037 | 885 | 812 | { | |
3038 | 886 | nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, width, height); | 813 | if (win_manager->IsScaleActiveForGroup()) |
3039 | 814 | new_title = GetActiveViewName(true); | ||
3040 | 815 | else if (_we_control_active) | ||
3041 | 816 | new_title = DESKTOP_NAME; | ||
3042 | 817 | } | ||
3043 | 818 | else if (win_manager->IsExpoActive()) | ||
3044 | 819 | { | ||
3045 | 820 | new_title = DESKTOP_NAME; | ||
3046 | 821 | } | ||
3047 | 822 | else if (!_we_control_active) | ||
3048 | 823 | { | ||
3049 | 824 | new_title = ""; | ||
3050 | 825 | } | ||
3051 | 826 | else if (!_switcher_showing && !_launcher_keynav) | ||
3052 | 827 | { | ||
3053 | 828 | new_title = GetActiveViewName(); | ||
3054 | 829 | _window_buttons->SetControlledWindow(_active_xid); | ||
3055 | 830 | } | ||
3056 | 831 | |||
3057 | 832 | if (!_switcher_showing && !_launcher_keynav) | ||
3058 | 833 | { | ||
3059 | 834 | if (_panel_title != new_title) | ||
3060 | 835 | { | ||
3061 | 836 | _panel_title = new_title; | ||
3062 | 837 | } | ||
3063 | 838 | else if (!force && _last_geo == geo && _title_texture) | ||
3064 | 839 | { | ||
3065 | 840 | // No need to redraw the title, let's save some CPU time! | ||
3066 | 841 | return; | ||
3067 | 842 | } | ||
3068 | 843 | } | ||
3069 | 844 | |||
3070 | 845 | if (_panel_title.empty()) | ||
3071 | 846 | { | ||
3072 | 847 | _title_texture = nullptr; | ||
3073 | 848 | return; | ||
3074 | 849 | } | ||
3075 | 850 | |||
3076 | 851 | nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, geo.width, geo.height); | ||
3077 | 887 | cairo_t* cr = cairo_graphics.GetContext(); | 852 | cairo_t* cr = cairo_graphics.GetContext(); |
3078 | 888 | cairo_set_line_width(cr, 1); | ||
3079 | 889 | 853 | ||
3080 | 890 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); | 854 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
3081 | 891 | cairo_paint(cr); | 855 | cairo_paint(cr); |
3082 | 892 | 856 | ||
3098 | 893 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); | 857 | glib::String escaped(g_markup_escape_text(_panel_title.c_str(), -1)); |
3099 | 894 | 858 | ||
3100 | 895 | x = _padding; | 859 | std::ostringstream bold_label; |
3101 | 896 | y = 0; | 860 | bold_label << "<b>" << escaped.Str() << "</b>"; |
3102 | 897 | 861 | ||
3103 | 898 | if (_panel_title) | 862 | DrawTitle(cr, geo, bold_label.str()); |
3089 | 899 | { | ||
3090 | 900 | DrawText(cr, x, y, width, height, nullptr, _panel_title); | ||
3091 | 901 | } | ||
3092 | 902 | else | ||
3093 | 903 | { | ||
3094 | 904 | char* title = GetActiveViewName(); | ||
3095 | 905 | DrawText(cr, x, y, width, height, nullptr, title); | ||
3096 | 906 | g_free(title); | ||
3097 | 907 | } | ||
3104 | 908 | 863 | ||
3105 | 909 | cairo_destroy(cr); | 864 | cairo_destroy(cr); |
3106 | 910 | 865 | ||
3126 | 911 | nux::BaseTexture* texture2D = texture_from_cairo_graphics(cairo_graphics); | 866 | _title_texture = texture_ptr_from_cairo_graphics(cairo_graphics); |
3108 | 912 | |||
3109 | 913 | if (_title_layer) | ||
3110 | 914 | delete _title_layer; | ||
3111 | 915 | |||
3112 | 916 | nux::TexCoordXForm texxform; | ||
3113 | 917 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); | ||
3114 | 918 | texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); | ||
3115 | 919 | |||
3116 | 920 | nux::ROPConfig rop; | ||
3117 | 921 | rop.Blend = true; | ||
3118 | 922 | rop.SrcBlend = GL_ONE; | ||
3119 | 923 | rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; | ||
3120 | 924 | _title_layer = new nux::TextureLayer(texture2D->GetDeviceTexture(), | ||
3121 | 925 | texxform, | ||
3122 | 926 | nux::color::White, | ||
3123 | 927 | true, | ||
3124 | 928 | rop); | ||
3125 | 929 | texture2D->UnReference(); | ||
3127 | 930 | } | 867 | } |
3128 | 931 | 868 | ||
3132 | 932 | void | 869 | void PanelMenuView::OnActiveChanged(PanelIndicatorEntryView* view, bool is_active) |
3130 | 933 | PanelMenuView::OnActiveChanged(PanelIndicatorEntryView* view, | ||
3131 | 934 | bool is_active) | ||
3133 | 935 | { | 870 | { |
3134 | 936 | if (is_active) | 871 | if (is_active) |
3135 | 872 | { | ||
3136 | 937 | _last_active_view = view; | 873 | _last_active_view = view; |
3137 | 874 | } | ||
3138 | 938 | else | 875 | else |
3139 | 939 | { | 876 | { |
3140 | 940 | if (_last_active_view == view) | 877 | if (_last_active_view == view) |
3141 | @@ -947,37 +884,36 @@ | |||
3142 | 947 | FullRedraw(); | 884 | FullRedraw(); |
3143 | 948 | } | 885 | } |
3144 | 949 | 886 | ||
3147 | 950 | void | 887 | void PanelMenuView::OnEntryAdded(indicator::Entry::Ptr const& entry) |
3146 | 951 | PanelMenuView::OnEntryAdded(unity::indicator::Entry::Ptr const& entry) | ||
3148 | 952 | { | 888 | { |
3150 | 953 | auto view = AddEntry(entry, 6, IndicatorEntryPosition::END, IndicatorEntryType::MENU); | 889 | PanelIndicatorEntryView* view; |
3151 | 890 | |||
3152 | 891 | view = new PanelIndicatorEntryView(entry, MENU_ENTRIES_PADDING, IndicatorEntryType::MENU); | ||
3153 | 892 | view->mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); | ||
3154 | 893 | view->mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); | ||
3155 | 954 | 894 | ||
3156 | 955 | entry->show_now_changed.connect(sigc::mem_fun(this, &PanelMenuView::UpdateShowNow)); | 895 | entry->show_now_changed.connect(sigc::mem_fun(this, &PanelMenuView::UpdateShowNow)); |
3157 | 956 | |||
3158 | 957 | view->active_changed.connect(sigc::mem_fun(this, &PanelMenuView::OnActiveChanged)); | 896 | view->active_changed.connect(sigc::mem_fun(this, &PanelMenuView::OnActiveChanged)); |
3161 | 958 | view->mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter)); | 897 | |
3162 | 959 | view->mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave)); | 898 | AddEntryView(view, IndicatorEntryPosition::END); |
3163 | 960 | } | 899 | } |
3164 | 961 | 900 | ||
3167 | 962 | void | 901 | void PanelMenuView::NotifyAllMenusClosed() |
3166 | 963 | PanelMenuView::AllMenusClosed() | ||
3168 | 964 | { | 902 | { |
3169 | 965 | auto mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); | ||
3170 | 966 | _is_inside = GetAbsoluteGeometry().IsPointInside(mouse.x, mouse.y); | ||
3171 | 967 | _last_active_view = nullptr; | 903 | _last_active_view = nullptr; |
3172 | 968 | 904 | ||
3173 | 905 | auto mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); | ||
3174 | 906 | _is_inside = GetAbsoluteGeometry().IsInside(mouse); | ||
3175 | 969 | FullRedraw(); | 907 | FullRedraw(); |
3176 | 970 | } | 908 | } |
3177 | 971 | 909 | ||
3180 | 972 | void | 910 | void PanelMenuView::OnNameChanged(BamfView* bamf_view, gchar* new_name, gchar* old_name) |
3179 | 973 | PanelMenuView::OnNameChanged(BamfView* bamf_view, gchar* new_name, gchar* old_name) | ||
3181 | 974 | { | 911 | { |
3182 | 975 | Refresh(); | 912 | Refresh(); |
3183 | 976 | FullRedraw(); | 913 | FullRedraw(); |
3184 | 977 | } | 914 | } |
3185 | 978 | 915 | ||
3188 | 979 | gboolean | 916 | gboolean PanelMenuView::OnNewAppShow(PanelMenuView* self) |
3187 | 980 | PanelMenuView::OnNewAppShow(PanelMenuView* self) | ||
3189 | 981 | { | 917 | { |
3190 | 982 | BamfApplication* active_app = bamf_matcher_get_active_application(self->_matcher); | 918 | BamfApplication* active_app = bamf_matcher_get_active_application(self->_matcher); |
3191 | 983 | self->_new_application = glib::Object<BamfApplication>(active_app, glib::AddRef()); | 919 | self->_new_application = glib::Object<BamfApplication>(active_app, glib::AddRef()); |
3192 | @@ -998,10 +934,9 @@ | |||
3193 | 998 | return FALSE; | 934 | return FALSE; |
3194 | 999 | } | 935 | } |
3195 | 1000 | 936 | ||
3198 | 1001 | gboolean | 937 | gboolean PanelMenuView::OnNewAppHide(PanelMenuView* self) |
3197 | 1002 | PanelMenuView::OnNewAppHide(PanelMenuView* self) | ||
3199 | 1003 | { | 938 | { |
3201 | 1004 | self->OnViewClosed(self->_matcher, BAMF_VIEW(self->_new_application.RawPtr())); | 939 | self->OnApplicationClosed(self->_new_application); |
3202 | 1005 | self->_new_app_hide_id = 0; | 940 | self->_new_app_hide_id = 0; |
3203 | 1006 | self->_new_app_menu_shown = true; | 941 | self->_new_app_menu_shown = true; |
3204 | 1007 | self->QueueDraw(); | 942 | self->QueueDraw(); |
3205 | @@ -1009,8 +944,7 @@ | |||
3206 | 1009 | return FALSE; | 944 | return FALSE; |
3207 | 1010 | } | 945 | } |
3208 | 1011 | 946 | ||
3211 | 1012 | void | 947 | void PanelMenuView::OnViewOpened(BamfMatcher *matcher, BamfView *view) |
3210 | 1013 | PanelMenuView::OnViewOpened(BamfMatcher *matcher, BamfView *view) | ||
3212 | 1014 | { | 948 | { |
3213 | 1015 | /* FIXME: here we should also check for if the view is also user_visible | 949 | /* FIXME: here we should also check for if the view is also user_visible |
3214 | 1016 | * but it seems that BAMF doesn't handle this correctly after some | 950 | * but it seems that BAMF doesn't handle this correctly after some |
3215 | @@ -1021,27 +955,48 @@ | |||
3216 | 1021 | _new_apps.push_front(glib::Object<BamfApplication>(BAMF_APPLICATION(view), glib::AddRef())); | 955 | _new_apps.push_front(glib::Object<BamfApplication>(BAMF_APPLICATION(view), glib::AddRef())); |
3217 | 1022 | } | 956 | } |
3218 | 1023 | 957 | ||
3221 | 1024 | void | 958 | void PanelMenuView::OnApplicationClosed(BamfApplication* app) |
3220 | 1025 | PanelMenuView::OnViewClosed(BamfMatcher *matcher, BamfView *view) | ||
3222 | 1026 | { | 959 | { |
3229 | 1027 | if (!BAMF_IS_APPLICATION(view)) | 960 | if (BAMF_IS_APPLICATION(app)) |
3224 | 1028 | return; | ||
3225 | 1029 | |||
3226 | 1030 | BamfApplication* app = BAMF_APPLICATION(view); | ||
3227 | 1031 | |||
3228 | 1032 | if (std::find(_new_apps.begin(), _new_apps.end(), app) != _new_apps.end()) | ||
3230 | 1033 | { | 961 | { |
3234 | 1034 | _new_apps.remove(glib::Object<BamfApplication>(app, glib::AddRef())); | 962 | if (std::find(_new_apps.begin(), _new_apps.end(), app) != _new_apps.end()) |
3235 | 1035 | 963 | { | |
3236 | 1036 | if (_new_application == app || _new_apps.empty()) | 964 | _new_apps.remove(glib::Object<BamfApplication>(app, glib::AddRef())); |
3237 | 965 | } | ||
3238 | 966 | else if (_new_apps.empty()) | ||
3239 | 967 | { | ||
3240 | 1037 | _new_application = nullptr; | 968 | _new_application = nullptr; |
3248 | 1038 | } | 969 | } |
3249 | 1039 | } | 970 | } |
3250 | 1040 | 971 | ||
3251 | 1041 | void | 972 | if (app == _new_application) |
3252 | 1042 | PanelMenuView::OnActiveAppChanged(BamfMatcher *matcher, | 973 | { |
3253 | 1043 | BamfApplication* old_app, | 974 | _new_application = nullptr; |
3254 | 1044 | BamfApplication* new_app) | 975 | } |
3255 | 976 | } | ||
3256 | 977 | |||
3257 | 978 | void PanelMenuView::OnViewClosed(BamfMatcher *matcher, BamfView *view) | ||
3258 | 979 | { | ||
3259 | 980 | if (BAMF_IS_APPLICATION(view)) | ||
3260 | 981 | { | ||
3261 | 982 | OnApplicationClosed(reinterpret_cast<BamfApplication*>(view)); | ||
3262 | 983 | } | ||
3263 | 984 | else if (reinterpret_cast<BamfApplication*>(view) == _new_application) | ||
3264 | 985 | { | ||
3265 | 986 | _new_application = nullptr; | ||
3266 | 987 | } | ||
3267 | 988 | else if (BAMF_IS_WINDOW(view)) | ||
3268 | 989 | { | ||
3269 | 990 | /* FIXME, this can be removed when window_unmapped WindowManager signal | ||
3270 | 991 | * will emit the proper xid */ | ||
3271 | 992 | Window xid = bamf_window_get_xid(reinterpret_cast<BamfWindow*>(view)); | ||
3272 | 993 | OnWindowUnmapped(xid); | ||
3273 | 994 | } | ||
3274 | 995 | } | ||
3275 | 996 | |||
3276 | 997 | void PanelMenuView::OnActiveAppChanged(BamfMatcher *matcher, | ||
3277 | 998 | BamfApplication* old_app, | ||
3278 | 999 | BamfApplication* new_app) | ||
3279 | 1045 | { | 1000 | { |
3280 | 1046 | if (BAMF_IS_APPLICATION(new_app)) | 1001 | if (BAMF_IS_APPLICATION(new_app)) |
3281 | 1047 | { | 1002 | { |
3282 | @@ -1078,15 +1033,14 @@ | |||
3283 | 1078 | } | 1033 | } |
3284 | 1079 | 1034 | ||
3285 | 1080 | if (_new_application) | 1035 | if (_new_application) |
3287 | 1081 | OnViewClosed(matcher, BAMF_VIEW(_new_application.RawPtr())); | 1036 | OnApplicationClosed(_new_application); |
3288 | 1082 | } | 1037 | } |
3289 | 1083 | } | 1038 | } |
3290 | 1084 | } | 1039 | } |
3291 | 1085 | 1040 | ||
3296 | 1086 | void | 1041 | void PanelMenuView::OnActiveWindowChanged(BamfMatcher *matcher, |
3297 | 1087 | PanelMenuView::OnActiveWindowChanged(BamfMatcher *matcher, | 1042 | BamfView* old_view, |
3298 | 1088 | BamfView* old_view, | 1043 | BamfView* new_view) |
3295 | 1089 | BamfView* new_view) | ||
3299 | 1090 | { | 1044 | { |
3300 | 1091 | _show_now_activated = false; | 1045 | _show_now_activated = false; |
3301 | 1092 | _is_maximized = false; | 1046 | _is_maximized = false; |
3302 | @@ -1100,15 +1054,16 @@ | |||
3303 | 1100 | 1054 | ||
3304 | 1101 | if (BAMF_IS_WINDOW(new_view)) | 1055 | if (BAMF_IS_WINDOW(new_view)) |
3305 | 1102 | { | 1056 | { |
3310 | 1103 | BamfWindow* window = BAMF_WINDOW(new_view); | 1057 | WindowManager *wm = WindowManager::Default(); |
3311 | 1104 | guint32 xid = _active_xid = bamf_window_get_xid(window); | 1058 | BamfWindow* window = reinterpret_cast<BamfWindow*>(new_view); |
3312 | 1105 | _is_maximized = WindowManager::Default()->IsWindowMaximized(xid); | 1059 | guint32 xid = bamf_window_get_xid(window); |
3313 | 1106 | nux::Geometry geo = WindowManager::Default()->GetWindowGeometry(xid); | 1060 | _active_xid = xid; |
3314 | 1061 | _is_maximized = wm->IsWindowMaximized(xid); | ||
3315 | 1107 | 1062 | ||
3316 | 1108 | if (bamf_window_get_window_type(window) == BAMF_WINDOW_DESKTOP) | 1063 | if (bamf_window_get_window_type(window) == BAMF_WINDOW_DESKTOP) |
3317 | 1109 | _we_control_active = true; | 1064 | _we_control_active = true; |
3318 | 1110 | else | 1065 | else |
3320 | 1111 | _we_control_active = UScreen::GetDefault()->GetMonitorGeometry(_monitor).IsPointInside(geo.x + (geo.width / 2), geo.y); | 1066 | _we_control_active = IsWindowUnderOurControl(xid); |
3321 | 1112 | 1067 | ||
3322 | 1113 | if (_decor_map.find(xid) == _decor_map.end()) | 1068 | if (_decor_map.find(xid) == _decor_map.end()) |
3323 | 1114 | { | 1069 | { |
3324 | @@ -1117,9 +1072,9 @@ | |||
3325 | 1117 | // if we've just started tracking this window and it is maximized, let's | 1072 | // if we've just started tracking this window and it is maximized, let's |
3326 | 1118 | // make sure it's undecorated just in case it slipped by us earlier | 1073 | // make sure it's undecorated just in case it slipped by us earlier |
3327 | 1119 | // (I'm looking at you, Chromium!) | 1074 | // (I'm looking at you, Chromium!) |
3329 | 1120 | if (_is_maximized && WindowManager::Default ()->IsWindowDecorated(xid)) | 1075 | if (_is_maximized && wm->IsWindowDecorated(xid)) |
3330 | 1121 | { | 1076 | { |
3332 | 1122 | WindowManager::Default()->Undecorate(xid); | 1077 | wm->Undecorate(xid); |
3333 | 1123 | _maximized_set.insert(xid); | 1078 | _maximized_set.insert(xid); |
3334 | 1124 | } | 1079 | } |
3335 | 1125 | } | 1080 | } |
3336 | @@ -1130,103 +1085,128 @@ | |||
3337 | 1130 | // register callback for new view | 1085 | // register callback for new view |
3338 | 1131 | _view_name_changed_signal.Connect(new_view, "name-changed", | 1086 | _view_name_changed_signal.Connect(new_view, "name-changed", |
3339 | 1132 | sigc::mem_fun(this, &PanelMenuView::OnNameChanged)); | 1087 | sigc::mem_fun(this, &PanelMenuView::OnNameChanged)); |
3340 | 1088 | |||
3341 | 1089 | _window_buttons->SetControlledWindow(_is_maximized ? _active_xid : 0); | ||
3342 | 1133 | } | 1090 | } |
3343 | 1134 | 1091 | ||
3344 | 1135 | Refresh(); | 1092 | Refresh(); |
3345 | 1136 | FullRedraw(); | 1093 | FullRedraw(); |
3346 | 1137 | } | 1094 | } |
3347 | 1138 | 1095 | ||
3410 | 1139 | void | 1096 | void PanelMenuView::OnSpreadInitiate() |
3411 | 1140 | PanelMenuView::OnSpreadInitiate() | 1097 | { |
3412 | 1141 | { | 1098 | /*foreach (guint32 &xid, windows) |
3413 | 1142 | /*foreach (guint32 &xid, windows) | 1099 | { |
3414 | 1143 | { | 1100 | if (WindowManager::Default()->IsWindowMaximized(xid)) |
3415 | 1144 | if (WindowManager::Default ()->IsWindowMaximized (xid)) | 1101 | WindowManager::Default()->Decorate(xid); |
3416 | 1145 | WindowManager::Default ()->Decorate (xid); | 1102 | }*/ |
3417 | 1146 | }*/ | 1103 | |
3418 | 1147 | } | 1104 | Refresh(); |
3419 | 1148 | 1105 | QueueDraw(); | |
3420 | 1149 | void | 1106 | } |
3421 | 1150 | PanelMenuView::OnSpreadTerminate() | 1107 | |
3422 | 1151 | { | 1108 | void PanelMenuView::OnSpreadTerminate() |
3423 | 1152 | /*foreach (guint32 &xid, windows) | 1109 | { |
3424 | 1153 | { | 1110 | /*foreach (guint32 &xid, windows) |
3425 | 1154 | if (WindowManager::Default ()->IsWindowMaximized (xid)) | 1111 | { |
3426 | 1155 | WindowManager::Default ()->Undecorate (xid); | 1112 | if (WindowManager::Default()->IsWindowMaximized(xid)) |
3427 | 1156 | }*/ | 1113 | WindowManager::Default()->Undecorate(xid); |
3428 | 1157 | } | 1114 | }*/ |
3429 | 1158 | 1115 | ||
3430 | 1159 | void | 1116 | Refresh(); |
3431 | 1160 | PanelMenuView::OnWindowMinimized(guint32 xid) | 1117 | QueueDraw(); |
3432 | 1161 | { | 1118 | } |
3433 | 1162 | if (WindowManager::Default()->IsWindowMaximized(xid)) | 1119 | |
3434 | 1163 | { | 1120 | void PanelMenuView::OnExpoInitiate() |
3435 | 1164 | WindowManager::Default()->Decorate(xid); | 1121 | { |
3436 | 1165 | _maximized_set.erase(xid); | 1122 | Refresh(); |
3437 | 1166 | } | 1123 | QueueDraw(); |
3438 | 1167 | } | 1124 | } |
3439 | 1168 | 1125 | ||
3440 | 1169 | void | 1126 | void PanelMenuView::OnExpoTerminate() |
3441 | 1170 | PanelMenuView::OnWindowUnminimized(guint32 xid) | 1127 | { |
3442 | 1171 | { | 1128 | Refresh(); |
3443 | 1172 | if (WindowManager::Default()->IsWindowMaximized(xid)) | 1129 | QueueDraw(); |
3444 | 1173 | { | 1130 | } |
3445 | 1174 | WindowManager::Default()->Undecorate(xid); | 1131 | |
3446 | 1175 | _maximized_set.insert(xid); | 1132 | void PanelMenuView::OnWindowMinimized(guint32 xid) |
3447 | 1176 | } | 1133 | { |
3448 | 1177 | } | 1134 | if (WindowManager::Default()->IsWindowMaximized(xid)) |
3449 | 1178 | 1135 | { | |
3450 | 1179 | void | 1136 | WindowManager::Default()->Decorate(xid); |
3451 | 1180 | PanelMenuView::OnWindowUnmapped(guint32 xid) | 1137 | _maximized_set.erase(xid); |
3452 | 1181 | { | 1138 | |
3453 | 1182 | if (WindowManager::Default()->IsWindowMaximized(xid)) | 1139 | Refresh(); |
3454 | 1183 | { | 1140 | QueueDraw(); |
3455 | 1184 | WindowManager::Default()->Decorate(xid); | 1141 | } |
3456 | 1185 | _maximized_set.erase(xid); | 1142 | } |
3457 | 1186 | } | 1143 | |
3458 | 1187 | } | 1144 | void PanelMenuView::OnWindowUnminimized(guint32 xid) |
3459 | 1188 | 1145 | { | |
3460 | 1189 | void | 1146 | if (WindowManager::Default()->IsWindowMaximized(xid)) |
3461 | 1190 | PanelMenuView::OnWindowMapped(guint32 xid) | 1147 | { |
3462 | 1191 | { | 1148 | WindowManager::Default()->Undecorate(xid); |
3463 | 1192 | if (WindowManager::Default()->IsWindowMaximized(xid)) | 1149 | _maximized_set.insert(xid); |
3464 | 1193 | { | 1150 | |
3465 | 1194 | WindowManager::Default()->Undecorate(xid); | 1151 | Refresh(); |
3466 | 1195 | _maximized_set.insert(xid); | 1152 | QueueDraw(); |
3467 | 1196 | } | 1153 | } |
3468 | 1197 | } | 1154 | } |
3469 | 1198 | 1155 | ||
3470 | 1199 | void | 1156 | void PanelMenuView::OnWindowUnmapped(guint32 xid) |
3471 | 1200 | PanelMenuView::OnWindowDecorated(guint32 xid) | 1157 | { |
3472 | 1158 | // FIXME: compiz doesn't give us a valid xid (is always 0 on unmap) | ||
3473 | 1159 | // we need to do this again on BamfView closed signal. | ||
3474 | 1160 | if (_maximized_set.find(xid) != _maximized_set.end()) | ||
3475 | 1161 | { | ||
3476 | 1162 | WindowManager::Default()->Decorate(xid); | ||
3477 | 1163 | _maximized_set.erase(xid); | ||
3478 | 1164 | _decor_map.erase(xid); | ||
3479 | 1165 | |||
3480 | 1166 | Refresh(); | ||
3481 | 1167 | QueueDraw(); | ||
3482 | 1168 | } | ||
3483 | 1169 | } | ||
3484 | 1170 | |||
3485 | 1171 | void PanelMenuView::OnWindowMapped(guint32 xid) | ||
3486 | 1172 | { | ||
3487 | 1173 | if (WindowManager::Default()->IsWindowMaximized(xid)) | ||
3488 | 1174 | { | ||
3489 | 1175 | WindowManager::Default()->Undecorate(xid); | ||
3490 | 1176 | _maximized_set.insert(xid); | ||
3491 | 1177 | |||
3492 | 1178 | Refresh(); | ||
3493 | 1179 | QueueDraw(); | ||
3494 | 1180 | } | ||
3495 | 1181 | } | ||
3496 | 1182 | |||
3497 | 1183 | void PanelMenuView::OnWindowDecorated(guint32 xid) | ||
3498 | 1201 | { | 1184 | { |
3499 | 1202 | _decor_map[xid] = true; | 1185 | _decor_map[xid] = true; |
3500 | 1203 | 1186 | ||
3501 | 1204 | if (_maximized_set.find(xid) != _maximized_set.end ()) | 1187 | if (_maximized_set.find(xid) != _maximized_set.end ()) |
3502 | 1205 | { | 1188 | { |
3504 | 1206 | WindowManager::Default ()->Undecorate(xid); | 1189 | WindowManager::Default()->Undecorate(xid); |
3505 | 1207 | } | 1190 | } |
3506 | 1208 | } | 1191 | } |
3507 | 1209 | 1192 | ||
3510 | 1210 | void | 1193 | void PanelMenuView::OnWindowUndecorated(guint32 xid) |
3509 | 1211 | PanelMenuView::OnWindowUndecorated(guint32 xid) | ||
3511 | 1212 | { | 1194 | { |
3512 | 1213 | _decor_map[xid] = false; | 1195 | _decor_map[xid] = false; |
3513 | 1214 | } | 1196 | } |
3514 | 1215 | 1197 | ||
3517 | 1216 | void | 1198 | void PanelMenuView::OnWindowMaximized(guint xid) |
3516 | 1217 | PanelMenuView::OnWindowMaximized(guint xid) | ||
3518 | 1218 | { | 1199 | { |
3519 | 1219 | BamfWindow* window; | ||
3520 | 1220 | bool updated = false; | 1200 | bool updated = false; |
3521 | 1201 | bool is_active = (_active_xid == xid); | ||
3522 | 1221 | 1202 | ||
3525 | 1222 | window = bamf_matcher_get_active_window(_matcher); | 1203 | if (is_active) |
3524 | 1223 | if (BAMF_IS_WINDOW(window) && bamf_window_get_xid(window) == xid) | ||
3526 | 1224 | { | 1204 | { |
3527 | 1205 | // We need to update the _is_inside state in the case of maximization by grab | ||
3528 | 1206 | auto mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); | ||
3529 | 1207 | _is_inside = GetAbsoluteGeometry().IsInside(mouse); | ||
3530 | 1208 | |||
3531 | 1225 | _is_maximized = true; | 1209 | _is_maximized = true; |
3532 | 1226 | |||
3533 | 1227 | // We need to update the _is_inside state in the case of maximization by grab | ||
3534 | 1228 | auto mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); | ||
3535 | 1229 | _is_inside = GetAbsoluteGeometry().IsPointInside(mouse.x, mouse.y); | ||
3536 | 1230 | updated = true; | 1210 | updated = true; |
3537 | 1231 | } | 1211 | } |
3538 | 1232 | 1212 | ||
3539 | @@ -1245,16 +1225,12 @@ | |||
3540 | 1245 | } | 1225 | } |
3541 | 1246 | } | 1226 | } |
3542 | 1247 | 1227 | ||
3545 | 1248 | void | 1228 | void PanelMenuView::OnWindowRestored(guint xid) |
3544 | 1249 | PanelMenuView::OnWindowRestored(guint xid) | ||
3546 | 1250 | { | 1229 | { |
3547 | 1251 | BamfWindow* window; | ||
3548 | 1252 | |||
3549 | 1253 | if (_maximized_set.find(xid) == _maximized_set.end()) | 1230 | if (_maximized_set.find(xid) == _maximized_set.end()) |
3550 | 1254 | return; | 1231 | return; |
3551 | 1255 | 1232 | ||
3554 | 1256 | window = bamf_matcher_get_active_window(_matcher); | 1233 | if (_active_xid == xid) |
3553 | 1257 | if (BAMF_IS_WINDOW(window) && bamf_window_get_xid(window) == xid) | ||
3555 | 1258 | { | 1234 | { |
3556 | 1259 | _is_maximized = false; | 1235 | _is_maximized = false; |
3557 | 1260 | _is_grabbed = false; | 1236 | _is_grabbed = false; |
3558 | @@ -1269,193 +1245,272 @@ | |||
3559 | 1269 | FullRedraw(); | 1245 | FullRedraw(); |
3560 | 1270 | } | 1246 | } |
3561 | 1271 | 1247 | ||
3564 | 1272 | gboolean | 1248 | gboolean PanelMenuView::UpdateActiveWindowPosition(PanelMenuView* self) |
3563 | 1273 | PanelMenuView::UpdateActiveWindowPosition(PanelMenuView* self) | ||
3565 | 1274 | { | 1249 | { |
3572 | 1275 | auto window_geo = WindowManager::Default()->GetWindowGeometry(self->_active_xid); | 1250 | bool we_control_window = self->IsWindowUnderOurControl(self->_active_xid); |
3573 | 1276 | auto monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(self->_monitor); | 1251 | |
3574 | 1277 | auto intersect = monitor_geo.Intersect(window_geo); | 1252 | if (we_control_window != self->_we_control_active) |
3575 | 1278 | 1253 | { | |
3576 | 1279 | self->_we_control_active = (intersect.width > window_geo.width/4 && | 1254 | self->_we_control_active = we_control_window; |
3577 | 1280 | intersect.height > window_geo.height/4); | 1255 | |
3578 | 1256 | self->Refresh(); | ||
3579 | 1257 | self->QueueDraw(); | ||
3580 | 1258 | } | ||
3581 | 1281 | 1259 | ||
3582 | 1282 | self->_active_moved_id = 0; | 1260 | self->_active_moved_id = 0; |
3583 | 1283 | self->QueueDraw(); | ||
3584 | 1284 | 1261 | ||
3585 | 1285 | return FALSE; | 1262 | return FALSE; |
3586 | 1286 | } | 1263 | } |
3587 | 1287 | 1264 | ||
3590 | 1288 | void | 1265 | void PanelMenuView::OnWindowMoved(guint xid) |
3589 | 1289 | PanelMenuView::OnWindowMoved(guint xid) | ||
3591 | 1290 | { | 1266 | { |
3592 | 1291 | if (_active_xid == xid) | 1267 | if (_active_xid == xid) |
3593 | 1292 | { | 1268 | { |
3673 | 1293 | if (_active_moved_id) | 1269 | /* When moving the active window, if the current panel is controlling |
3674 | 1294 | g_source_remove(_active_moved_id); | 1270 | * the active window, then we postpone the timeout function every movement |
3675 | 1295 | 1271 | * that we have, setting a longer timeout. | |
3676 | 1296 | if (!_we_control_active) | 1272 | * Otherwise, if the moved window is not controlled by the current panel |
3677 | 1297 | UpdateActiveWindowPosition(this); | 1273 | * every few millisecond we check the new window position */ |
3678 | 1298 | else | 1274 | |
3679 | 1299 | _active_moved_id = g_timeout_add(250, (GSourceFunc)PanelMenuView::UpdateActiveWindowPosition, this); | 1275 | unsigned int timeout = 250; |
3680 | 1300 | } | 1276 | |
3681 | 1301 | } | 1277 | if (_we_control_active) |
3682 | 1302 | 1278 | { | |
3683 | 1303 | void | 1279 | if (_active_moved_id) |
3684 | 1304 | PanelMenuView::OnCloseClicked() | 1280 | g_source_remove(_active_moved_id); |
3685 | 1305 | { | 1281 | } |
3686 | 1306 | if (_places_showing) | 1282 | else |
3687 | 1307 | { | 1283 | { |
3688 | 1308 | ubus_server_send_message(ubus_server_get_default(), UBUS_PLACE_VIEW_CLOSE_REQUEST, nullptr); | 1284 | timeout = 60; |
3689 | 1309 | } | 1285 | |
3690 | 1310 | else | 1286 | if (_active_moved_id) |
3691 | 1311 | { | 1287 | return; |
3692 | 1312 | BamfWindow* window; | 1288 | } |
3693 | 1313 | 1289 | ||
3694 | 1314 | window = bamf_matcher_get_active_window(_matcher); | 1290 | _active_moved_id = g_timeout_add(timeout, (GSourceFunc)UpdateActiveWindowPosition, this); |
3695 | 1315 | if (BAMF_IS_WINDOW(window)) | 1291 | } |
3696 | 1316 | { | 1292 | } |
3697 | 1317 | WindowManager::Default()->Close(bamf_window_get_xid(window)); | 1293 | |
3698 | 1318 | NeedRedraw(); | 1294 | bool PanelMenuView::IsWindowUnderOurControl(Window xid) const |
3699 | 1319 | } | 1295 | { |
3700 | 1320 | } | 1296 | if (UScreen::GetDefault()->GetMonitors().size() > 1) |
3701 | 1321 | } | 1297 | { |
3702 | 1322 | 1298 | auto wm = WindowManager::Default(); | |
3703 | 1323 | void | 1299 | nux::Geometry const& window_geo = wm->GetWindowGeometry(xid); |
3704 | 1324 | PanelMenuView::OnMinimizeClicked() | 1300 | nux::Geometry const& intersect = _monitor_geo.Intersect(window_geo); |
3705 | 1325 | { | 1301 | |
3706 | 1326 | if (_places_showing) | 1302 | /* We only care of the horizontal window portion */ |
3707 | 1327 | { | 1303 | return (intersect.width > window_geo.width/2 && intersect.height > 0); |
3708 | 1328 | // no action when dash is opened, LP bug #838875 | 1304 | } |
3709 | 1329 | return; | 1305 | |
3710 | 1330 | } | 1306 | return true; |
3711 | 1331 | else | 1307 | } |
3712 | 1332 | { | 1308 | |
3713 | 1333 | BamfWindow* window; | 1309 | bool PanelMenuView::IsValidWindow(Window xid) const |
3714 | 1334 | 1310 | { | |
3715 | 1335 | window = bamf_matcher_get_active_window(_matcher); | 1311 | auto wm = WindowManager::Default(); |
3716 | 1336 | if (BAMF_IS_WINDOW(window)) | 1312 | std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList(); |
3717 | 1337 | { | 1313 | |
3718 | 1338 | WindowManager::Default()->Minimize(bamf_window_get_xid(window)); | 1314 | if (wm->IsWindowOnCurrentDesktop(xid) && !wm->IsWindowObscured(xid) && |
3719 | 1339 | NeedRedraw(); | 1315 | wm->IsWindowVisible(xid) && IsWindowUnderOurControl(xid) && |
3720 | 1340 | } | 1316 | std::find(our_xids.begin(), our_xids.end(), xid) == our_xids.end()) |
3721 | 1341 | } | 1317 | { |
3722 | 1342 | } | 1318 | return true; |
3723 | 1343 | 1319 | } | |
3724 | 1344 | void | 1320 | |
3725 | 1345 | PanelMenuView::OnRestoreClicked() | 1321 | return false; |
3726 | 1346 | { | 1322 | } |
3727 | 1347 | if (_places_showing) | 1323 | |
3728 | 1348 | { | 1324 | Window PanelMenuView::GetMaximizedWindow() const |
3729 | 1349 | if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP) | 1325 | { |
3730 | 1350 | dash::Settings::Instance().SetFormFactor(dash::FormFactor::NETBOOK); | 1326 | Window window_xid = 0; |
3652 | 1351 | else | ||
3653 | 1352 | dash::Settings::Instance().SetFormFactor(dash::FormFactor::DESKTOP); | ||
3654 | 1353 | } | ||
3655 | 1354 | else | ||
3656 | 1355 | { | ||
3657 | 1356 | BamfWindow* window; | ||
3658 | 1357 | |||
3659 | 1358 | window = bamf_matcher_get_active_window(_matcher); | ||
3660 | 1359 | if (BAMF_IS_WINDOW(window)) | ||
3661 | 1360 | { | ||
3662 | 1361 | WindowManager::Default()->Restore(bamf_window_get_xid(window)); | ||
3663 | 1362 | NeedRedraw(); | ||
3664 | 1363 | } | ||
3665 | 1364 | } | ||
3666 | 1365 | } | ||
3667 | 1366 | |||
3668 | 1367 | guint32 | ||
3669 | 1368 | PanelMenuView::GetMaximizedWindow() | ||
3670 | 1369 | { | ||
3671 | 1370 | guint32 window_xid = 0; | ||
3672 | 1371 | nux::Geometry monitor = UScreen::GetDefault()->GetMonitorGeometry(_monitor); | ||
3731 | 1372 | 1327 | ||
3732 | 1373 | // Find the front-most of the maximized windows we are controlling | 1328 | // Find the front-most of the maximized windows we are controlling |
3733 | 1374 | for (auto xid : _maximized_set) | 1329 | for (auto xid : _maximized_set) |
3734 | 1375 | { | 1330 | { |
3735 | 1376 | // We can safely assume only the front-most is visible | 1331 | // We can safely assume only the front-most is visible |
3741 | 1377 | if (WindowManager::Default()->IsWindowOnCurrentDesktop(xid) | 1332 | if (IsValidWindow(xid)) |
3742 | 1378 | && !WindowManager::Default()->IsWindowObscured(xid)) | 1333 | { |
3743 | 1379 | { | 1334 | window_xid = xid; |
3744 | 1380 | nux::Geometry geo = WindowManager::Default()->GetWindowGeometry(xid); | 1335 | break; |
3745 | 1381 | if (monitor.IsPointInside(geo.x + (geo.width / 2), geo.y)) | 1336 | } |
3746 | 1337 | } | ||
3747 | 1338 | |||
3748 | 1339 | return window_xid; | ||
3749 | 1340 | } | ||
3750 | 1341 | |||
3751 | 1342 | Window PanelMenuView::GetTopWindow() const | ||
3752 | 1343 | { | ||
3753 | 1344 | Window window_xid = 0; | ||
3754 | 1345 | GList* windows = bamf_matcher_get_window_stack_for_monitor(_matcher, _monitor); | ||
3755 | 1346 | |||
3756 | 1347 | for (GList* l = windows; l; l = l->next) | ||
3757 | 1348 | { | ||
3758 | 1349 | if (!BAMF_IS_WINDOW(l->data)) | ||
3759 | 1350 | continue; | ||
3760 | 1351 | |||
3761 | 1352 | Window xid = bamf_window_get_xid(static_cast<BamfWindow*>(l->data)); | ||
3762 | 1353 | bool visible = bamf_view_user_visible(static_cast<BamfView*>(l->data)); | ||
3763 | 1354 | |||
3764 | 1355 | if (visible && IsValidWindow(xid)) | ||
3765 | 1356 | { | ||
3766 | 1357 | window_xid = xid; | ||
3767 | 1358 | } | ||
3768 | 1359 | } | ||
3769 | 1360 | |||
3770 | 1361 | g_list_free(windows); | ||
3771 | 1362 | |||
3772 | 1363 | return window_xid; | ||
3773 | 1364 | } | ||
3774 | 1365 | |||
3775 | 1366 | BamfWindow* PanelMenuView::GetBamfWindowForXid(Window xid) const | ||
3776 | 1367 | { | ||
3777 | 1368 | BamfWindow* window = nullptr; | ||
3778 | 1369 | |||
3779 | 1370 | if (xid != 0) | ||
3780 | 1371 | { | ||
3781 | 1372 | GList* windows = bamf_matcher_get_windows(_matcher); | ||
3782 | 1373 | |||
3783 | 1374 | for (GList* l = windows; l; l = l->next) | ||
3784 | 1375 | { | ||
3785 | 1376 | if (!BAMF_IS_WINDOW(l->data)) | ||
3786 | 1377 | continue; | ||
3787 | 1378 | |||
3788 | 1379 | auto win = static_cast<BamfWindow*>(l->data); | ||
3789 | 1380 | |||
3790 | 1381 | if (bamf_window_get_xid(win) == xid) | ||
3791 | 1382 | { | 1382 | { |
3793 | 1383 | window_xid = xid; | 1383 | window = win; |
3794 | 1384 | break; | 1384 | break; |
3795 | 1385 | } | 1385 | } |
3796 | 1386 | } | 1386 | } |
3817 | 1387 | } | 1387 | |
3818 | 1388 | return window_xid; | 1388 | g_list_free(windows); |
3819 | 1389 | } | 1389 | } |
3820 | 1390 | 1390 | ||
3821 | 1391 | void | 1391 | return window; |
3822 | 1392 | PanelMenuView::OnMaximizedGrabStart(int x, int y, unsigned long button_flags, unsigned long) | 1392 | } |
3823 | 1393 | { | 1393 | |
3824 | 1394 | Window maximized_win; | 1394 | void PanelMenuView::OnMaximizedActivate(int x, int y) |
3825 | 1395 | if (nux::GetEventButton(button_flags) != 1 || _places_showing) | 1395 | { |
3826 | 1396 | return; | 1396 | Window maximized = GetMaximizedWindow(); |
3827 | 1397 | 1397 | ||
3828 | 1398 | // When Start dragging the panelmenu of a maximized window, change cursor | 1398 | if (maximized != 0) |
3829 | 1399 | // to simulate the dragging, waiting to go out of the panel area. | 1399 | { |
3830 | 1400 | // | 1400 | WindowManager::Default()->Activate(maximized); |
3831 | 1401 | // This is a workaround to avoid that the grid plugin would be fired | 1401 | } |
3832 | 1402 | // showing the window shape preview effect. See bug #838923 | 1402 | } |
3833 | 1403 | 1403 | ||
3834 | 1404 | maximized_win = GetMaximizedWindow (); | 1404 | void PanelMenuView::OnMaximizedRestore(int x, int y) |
3835 | 1405 | 1405 | { | |
3836 | 1406 | if (maximized_win != 0) | 1406 | if (_overlay_showing) |
3837 | 1407 | return; | ||
3838 | 1408 | |||
3839 | 1409 | Window maximized = GetMaximizedWindow(); | ||
3840 | 1410 | |||
3841 | 1411 | if (maximized != 0) | ||
3842 | 1412 | { | ||
3843 | 1413 | WindowManager::Default()->Restore(maximized); | ||
3844 | 1414 | _is_inside = true; | ||
3845 | 1415 | } | ||
3846 | 1416 | } | ||
3847 | 1417 | |||
3848 | 1418 | void PanelMenuView::OnMaximizedLower(int x, int y) | ||
3849 | 1419 | { | ||
3850 | 1420 | if (_overlay_showing) | ||
3851 | 1421 | return; | ||
3852 | 1422 | |||
3853 | 1423 | Window maximized = GetMaximizedWindow(); | ||
3854 | 1424 | |||
3855 | 1425 | if (maximized != 0) | ||
3856 | 1426 | { | ||
3857 | 1427 | WindowManager::Default()->Lower(maximized); | ||
3858 | 1428 | } | ||
3859 | 1429 | } | ||
3860 | 1430 | |||
3861 | 1431 | void PanelMenuView::OnMaximizedGrabStart(int x, int y) | ||
3862 | 1432 | { | ||
3863 | 1433 | /* When Start dragging the panelmenu of a maximized window, change cursor | ||
3864 | 1434 | * to simulate the dragging, waiting to go out of the panel area. | ||
3865 | 1435 | * | ||
3866 | 1436 | * This is a workaround to avoid that the grid plugin would be fired | ||
3867 | 1437 | * showing the window shape preview effect. See bug #838923 */ | ||
3868 | 1438 | |||
3869 | 1439 | Window maximized = GetMaximizedWindow(); | ||
3870 | 1440 | |||
3871 | 1441 | if (maximized != 0) | ||
3872 | 1407 | { | 1442 | { |
3873 | 1408 | /* Always activate the window in case it is on another monitor */ | 1443 | /* Always activate the window in case it is on another monitor */ |
3876 | 1409 | WindowManager::Default ()->Activate (maximized_win); | 1444 | WindowManager::Default()->Activate(maximized); |
3877 | 1410 | _panel_titlebar_grab_area->SetGrabbed(true); | 1445 | _titlebar_grab_area->SetGrabbed(true); |
3878 | 1411 | } | 1446 | } |
3879 | 1412 | } | 1447 | } |
3880 | 1413 | 1448 | ||
3883 | 1414 | void | 1449 | void PanelMenuView::OnMaximizedGrabMove(int x, int y) |
3882 | 1415 | PanelMenuView::OnMaximizedGrabMove(int x, int y, int, int, unsigned long button_flags, unsigned long) | ||
3884 | 1416 | { | 1450 | { |
3885 | 1417 | // FIXME nux doesn't export it with drag event. | ||
3886 | 1418 | // if (nux::GetEventButton(button_flags) != 1) | ||
3887 | 1419 | // return; | ||
3888 | 1420 | |||
3889 | 1421 | // We use this, due to the problem above | ||
3890 | 1422 | if (!_panel_titlebar_grab_area->IsGrabbed()) | ||
3891 | 1423 | return; | ||
3892 | 1424 | |||
3893 | 1425 | auto panel = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow()); | 1451 | auto panel = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow()); |
3894 | 1426 | 1452 | ||
3895 | 1427 | if (!panel) | 1453 | if (!panel) |
3896 | 1428 | return; | 1454 | return; |
3897 | 1429 | 1455 | ||
3908 | 1430 | x += _panel_titlebar_grab_area->GetAbsoluteX(); | 1456 | /* Adjusting the x, y coordinates to get the absolute values */ |
3909 | 1431 | y += _panel_titlebar_grab_area->GetAbsoluteY(); | 1457 | x += _titlebar_grab_area->GetAbsoluteX(); |
3910 | 1432 | 1458 | y += _titlebar_grab_area->GetAbsoluteY(); | |
3911 | 1433 | guint32 window_xid = GetMaximizedWindow(); | 1459 | |
3912 | 1434 | 1460 | Window maximized = GetMaximizedWindow(); | |
3913 | 1435 | // When the drag goes out from the Panel, start the real movement. | 1461 | |
3914 | 1436 | // | 1462 | /* When the drag goes out from the Panel, start the real movement. |
3915 | 1437 | // This is a workaround to avoid that the grid plugin would be fired | 1463 | * |
3916 | 1438 | // showing the window shape preview effect. See bug #838923 | 1464 | * This is a workaround to avoid that the grid plugin would be fired |
3917 | 1439 | if (window_xid != 0 && panel && !panel->GetAbsoluteGeometry().IsPointInside(x, y)) | 1465 | * showing the window shape preview effect. See bug #838923 */ |
3918 | 1466 | if (maximized != 0 && panel) | ||
3919 | 1440 | { | 1467 | { |
3928 | 1441 | _panel_titlebar_grab_area->SetGrabbed(false); | 1468 | nux::Geometry const& panel_geo = panel->GetAbsoluteGeometry(); |
3929 | 1442 | 1469 | ||
3930 | 1443 | WindowManager::Default()->Activate(window_xid); | 1470 | if (!panel_geo.IsPointInside(x, y)) |
3931 | 1444 | _is_inside = true; | 1471 | { |
3932 | 1445 | _is_grabbed = true; | 1472 | auto wm = WindowManager::Default(); |
3933 | 1446 | Refresh(); | 1473 | nux::Geometry const& restored_geo = wm->GetWindowSavedGeometry(maximized); |
3934 | 1447 | FullRedraw(); | 1474 | nux::Geometry const& workarea_geo = wm->GetWorkAreaGeometry(maximized); |
3935 | 1448 | WindowManager::Default()->StartMove(window_xid, x, y); | 1475 | |
3936 | 1476 | /* By default try to restore the window horizontally-centered respect to the | ||
3937 | 1477 | * pointer position, if it doesn't fit on that area try to keep it into the | ||
3938 | 1478 | * current workarea as much as possible, but giving priority to the left border | ||
3939 | 1479 | * that shouldn't be never put out of the workarea */ | ||
3940 | 1480 | int restore_x = x - (restored_geo.width * x / panel_geo.width); | ||
3941 | 1481 | int restore_y = y; | ||
3942 | 1482 | |||
3943 | 1483 | if (restore_x + restored_geo.width > workarea_geo.x + workarea_geo.width) | ||
3944 | 1484 | { | ||
3945 | 1485 | restore_x = workarea_geo.x + workarea_geo.width - restored_geo.width; | ||
3946 | 1486 | } | ||
3947 | 1487 | |||
3948 | 1488 | if (restore_x < workarea_geo.x) | ||
3949 | 1489 | { | ||
3950 | 1490 | restore_x = workarea_geo.x; | ||
3951 | 1491 | } | ||
3952 | 1492 | |||
3953 | 1493 | wm->Activate(maximized); | ||
3954 | 1494 | wm->RestoreAt(maximized, restore_x, restore_y); | ||
3955 | 1495 | |||
3956 | 1496 | _is_inside = true; | ||
3957 | 1497 | _is_grabbed = true; | ||
3958 | 1498 | Refresh(); | ||
3959 | 1499 | FullRedraw(); | ||
3960 | 1500 | |||
3961 | 1501 | /* Ungrab the pointer and start the X move, to make the decorator handle it */ | ||
3962 | 1502 | _titlebar_grab_area->SetGrabbed(false); | ||
3963 | 1503 | wm->StartMove(maximized, x, y); | ||
3964 | 1504 | } | ||
3965 | 1449 | } | 1505 | } |
3966 | 1450 | } | 1506 | } |
3967 | 1451 | 1507 | ||
3970 | 1452 | void | 1508 | void PanelMenuView::OnMaximizedGrabEnd(int x, int y) |
3969 | 1453 | PanelMenuView::OnMaximizedGrabEnd(int x, int y, unsigned long, unsigned long) | ||
3971 | 1454 | { | 1509 | { |
3973 | 1455 | _panel_titlebar_grab_area->SetGrabbed(false); | 1510 | _titlebar_grab_area->SetGrabbed(false); |
3974 | 1456 | 1511 | ||
3977 | 1457 | x += _panel_titlebar_grab_area->GetAbsoluteX(); | 1512 | x += _titlebar_grab_area->GetAbsoluteX(); |
3978 | 1458 | y += _panel_titlebar_grab_area->GetAbsoluteY(); | 1513 | y += _titlebar_grab_area->GetAbsoluteY(); |
3979 | 1459 | _is_inside = GetAbsoluteGeometry().IsPointInside(x, y); | 1514 | _is_inside = GetAbsoluteGeometry().IsPointInside(x, y); |
3980 | 1460 | 1515 | ||
3981 | 1461 | if (!_is_inside) | 1516 | if (!_is_inside) |
3982 | @@ -1465,115 +1520,108 @@ | |||
3983 | 1465 | FullRedraw(); | 1520 | FullRedraw(); |
3984 | 1466 | } | 1521 | } |
3985 | 1467 | 1522 | ||
3986 | 1468 | void | ||
3987 | 1469 | PanelMenuView::OnMouseDoubleClicked(int x, int y, unsigned long button_flags, unsigned long) | ||
3988 | 1470 | { | ||
3989 | 1471 | if (nux::GetEventButton(button_flags) != 1 || _places_showing) | ||
3990 | 1472 | return; | ||
3991 | 1473 | |||
3992 | 1474 | guint32 window_xid = GetMaximizedWindow(); | ||
3993 | 1475 | |||
3994 | 1476 | if (window_xid != 0) | ||
3995 | 1477 | { | ||
3996 | 1478 | WindowManager::Default()->Restore(window_xid); | ||
3997 | 1479 | _is_inside = true; | ||
3998 | 1480 | } | ||
3999 | 1481 | } | ||
4000 | 1482 | |||
4001 | 1483 | void | ||
4002 | 1484 | PanelMenuView::OnMouseClicked(int x, int y, unsigned long button_flags, unsigned long) | ||
4003 | 1485 | { | ||
4004 | 1486 | if (nux::GetEventButton(button_flags) != 1 || _places_showing) | ||
4005 | 1487 | return; | ||
4006 | 1488 | |||
4007 | 1489 | guint32 window_xid = GetMaximizedWindow(); | ||
4008 | 1490 | |||
4009 | 1491 | if (window_xid != 0) | ||
4010 | 1492 | { | ||
4011 | 1493 | WindowManager::Default()->Raise(window_xid); | ||
4012 | 1494 | } | ||
4013 | 1495 | } | ||
4014 | 1496 | |||
4015 | 1497 | void | ||
4016 | 1498 | PanelMenuView::OnMouseMiddleClicked(int x, int y, unsigned long button_flags, unsigned long) | ||
4017 | 1499 | { | ||
4018 | 1500 | if (nux::GetEventButton(button_flags) != 2 || _places_showing) | ||
4019 | 1501 | return; | ||
4020 | 1502 | |||
4021 | 1503 | guint32 window_xid = GetMaximizedWindow(); | ||
4022 | 1504 | |||
4023 | 1505 | if (window_xid != 0) | ||
4024 | 1506 | { | ||
4025 | 1507 | WindowManager::Default()->Lower(window_xid); | ||
4026 | 1508 | } | ||
4027 | 1509 | } | ||
4028 | 1510 | |||
4029 | 1511 | // Introspectable | 1523 | // Introspectable |
4030 | 1512 | std::string | 1524 | std::string |
4031 | 1513 | PanelMenuView::GetName() const | 1525 | PanelMenuView::GetName() const |
4032 | 1514 | { | 1526 | { |
4034 | 1515 | return ""; | 1527 | return "MenuView"; |
4035 | 1516 | } | 1528 | } |
4036 | 1517 | 1529 | ||
4037 | 1518 | void PanelMenuView::AddProperties(GVariantBuilder* builder) | 1530 | void PanelMenuView::AddProperties(GVariantBuilder* builder) |
4038 | 1519 | { | 1531 | { |
4061 | 1520 | } | 1532 | PanelIndicatorsView::AddProperties(builder); |
4062 | 1521 | 1533 | ||
4063 | 1522 | void PanelMenuView::OnPlaceViewShown(GVariant* data, PanelMenuView* self) | 1534 | variant::BuilderWrapper(builder) |
4064 | 1523 | { | 1535 | .add("mouse_inside", _is_inside) |
4065 | 1524 | self->_places_showing = true; | 1536 | .add("grabbed", _is_grabbed) |
4066 | 1525 | self->QueueDraw(); | 1537 | .add("active_win_maximized", _is_maximized) |
4067 | 1526 | } | 1538 | .add("panel_title", _panel_title) |
4068 | 1527 | 1539 | .add("monitor", _monitor) | |
4069 | 1528 | void PanelMenuView::OnPlaceViewHidden(GVariant* data, PanelMenuView* self) | 1540 | .add("active_window", _active_xid) |
4070 | 1529 | { | 1541 | .add("draw_menus", DrawMenus()) |
4071 | 1530 | self->_places_showing = false; | 1542 | .add("draw_window_buttons", DrawWindowButtons()) |
4072 | 1531 | self->QueueDraw(); | 1543 | .add("controls_active_window", _we_control_active); |
4073 | 1532 | } | 1544 | } |
4074 | 1533 | 1545 | ||
4075 | 1534 | void PanelMenuView::OnSwitcherShown(GVariant* data, PanelMenuView* self) | 1546 | void PanelMenuView::OnSwitcherShown(GVariant* data) |
4076 | 1535 | { | 1547 | { |
4077 | 1536 | if (!self || !data) | 1548 | if (!data) |
4078 | 1537 | return; | 1549 | return; |
4079 | 1538 | 1550 | ||
4080 | 1539 | self->_switcher_showing = g_variant_get_boolean(data); | 1551 | bool switcher_shown; |
4081 | 1540 | 1552 | int monitor; | |
4082 | 1541 | if (!self->_switcher_showing) | 1553 | g_variant_get(data, "(bi)", &switcher_shown, &monitor); |
4083 | 1554 | |||
4084 | 1555 | if (switcher_shown == _switcher_showing || monitor != _monitor) | ||
4085 | 1556 | return; | ||
4086 | 1557 | |||
4087 | 1558 | _switcher_showing = switcher_shown; | ||
4088 | 1559 | |||
4089 | 1560 | if (!_switcher_showing) | ||
4090 | 1542 | { | 1561 | { |
4091 | 1543 | auto mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); | 1562 | auto mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); |
4099 | 1544 | self->_is_inside = self->GetAbsoluteGeometry().IsPointInside(mouse.x, mouse.y); | 1563 | _is_inside = GetAbsoluteGeometry().IsInside(mouse); |
4093 | 1545 | |||
4094 | 1546 | if (self->_panel_title) | ||
4095 | 1547 | { | ||
4096 | 1548 | g_free(self->_panel_title); | ||
4097 | 1549 | self->_panel_title = nullptr; | ||
4098 | 1550 | } | ||
4100 | 1551 | } | 1564 | } |
4101 | 1552 | else | 1565 | else |
4102 | 1553 | { | 1566 | { |
4126 | 1554 | self->_show_now_activated = false; | 1567 | _show_now_activated = false; |
4127 | 1555 | } | 1568 | } |
4128 | 1556 | 1569 | ||
4129 | 1557 | self->Refresh(); | 1570 | Refresh(); |
4130 | 1558 | self->QueueDraw(); | 1571 | QueueDraw(); |
4131 | 1559 | } | 1572 | } |
4132 | 1560 | 1573 | ||
4133 | 1561 | void PanelMenuView::OnSwitcherSelectionChanged(GVariant* data, PanelMenuView* self) | 1574 | void PanelMenuView::OnSwitcherSelectionChanged(GVariant* data) |
4134 | 1562 | { | 1575 | { |
4135 | 1563 | if (!self || !data) | 1576 | if (!data || !_switcher_showing) |
4136 | 1564 | return; | 1577 | return; |
4137 | 1565 | 1578 | ||
4138 | 1566 | if (self->_panel_title) | 1579 | const gchar *title = g_variant_get_string(data, 0); |
4139 | 1567 | g_free(self->_panel_title); | 1580 | _panel_title = (title ? title : ""); |
4140 | 1568 | 1581 | ||
4141 | 1569 | self->_panel_title = g_strdup(g_variant_get_string(data, 0)); | 1582 | Refresh(); |
4142 | 1570 | 1583 | QueueDraw(); | |
4143 | 1571 | self->Refresh(); | 1584 | } |
4144 | 1572 | self->QueueDraw(); | 1585 | |
4145 | 1573 | } | 1586 | void PanelMenuView::OnLauncherKeyNavStarted(GVariant* data) |
4146 | 1574 | 1587 | { | |
4147 | 1575 | gboolean | 1588 | if (_launcher_keynav) |
4148 | 1576 | PanelMenuView::UpdateShowNowWithDelay(PanelMenuView *self) | 1589 | return; |
4149 | 1590 | |||
4150 | 1591 | |||
4151 | 1592 | if (!data || (data && g_variant_get_int32(data) == _monitor)) | ||
4152 | 1593 | { | ||
4153 | 1594 | _launcher_keynav = true; | ||
4154 | 1595 | } | ||
4155 | 1596 | } | ||
4156 | 1597 | |||
4157 | 1598 | void PanelMenuView::OnLauncherKeyNavEnded(GVariant* data) | ||
4158 | 1599 | { | ||
4159 | 1600 | if (!_launcher_keynav) | ||
4160 | 1601 | return; | ||
4161 | 1602 | |||
4162 | 1603 | _launcher_keynav = false; | ||
4163 | 1604 | |||
4164 | 1605 | auto mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); | ||
4165 | 1606 | _is_inside = GetAbsoluteGeometry().IsInside(mouse); | ||
4166 | 1607 | |||
4167 | 1608 | Refresh(); | ||
4168 | 1609 | QueueDraw(); | ||
4169 | 1610 | } | ||
4170 | 1611 | |||
4171 | 1612 | void PanelMenuView::OnLauncherSelectionChanged(GVariant* data) | ||
4172 | 1613 | { | ||
4173 | 1614 | if (!data || !_launcher_keynav) | ||
4174 | 1615 | return; | ||
4175 | 1616 | |||
4176 | 1617 | const gchar *title = g_variant_get_string(data, 0); | ||
4177 | 1618 | _panel_title = (title ? title : ""); | ||
4178 | 1619 | |||
4179 | 1620 | Refresh(); | ||
4180 | 1621 | QueueDraw(); | ||
4181 | 1622 | } | ||
4182 | 1623 | |||
4183 | 1624 | gboolean PanelMenuView::UpdateShowNowWithDelay(PanelMenuView *self) | ||
4184 | 1577 | { | 1625 | { |
4185 | 1578 | bool active = false; | 1626 | bool active = false; |
4186 | 1579 | 1627 | ||
4187 | @@ -1597,8 +1645,7 @@ | |||
4188 | 1597 | return FALSE; | 1645 | return FALSE; |
4189 | 1598 | } | 1646 | } |
4190 | 1599 | 1647 | ||
4193 | 1600 | void | 1648 | void PanelMenuView::UpdateShowNow(bool status) |
4192 | 1601 | PanelMenuView::UpdateShowNow(bool status) | ||
4194 | 1602 | { | 1649 | { |
4195 | 1603 | /* When we get a show now event, if we are requested to show the menus, | 1650 | /* When we get a show now event, if we are requested to show the menus, |
4196 | 1604 | * we take the last incoming event and we wait for small delay (to avoid the | 1651 | * we take the last incoming event and we wait for small delay (to avoid the |
4197 | @@ -1610,6 +1657,7 @@ | |||
4198 | 1610 | { | 1657 | { |
4199 | 1611 | _show_now_activated = false; | 1658 | _show_now_activated = false; |
4200 | 1612 | QueueDraw(); | 1659 | QueueDraw(); |
4201 | 1660 | return; | ||
4202 | 1613 | } | 1661 | } |
4203 | 1614 | 1662 | ||
4204 | 1615 | if (_update_show_now_id != 0) | 1663 | if (_update_show_now_id != 0) |
4205 | @@ -1626,27 +1674,55 @@ | |||
4206 | 1626 | } | 1674 | } |
4207 | 1627 | } | 1675 | } |
4208 | 1628 | 1676 | ||
4211 | 1629 | void | 1677 | void PanelMenuView::SetMonitor(int monitor) |
4210 | 1630 | PanelMenuView::SetMonitor(int monitor) | ||
4212 | 1631 | { | 1678 | { |
4213 | 1632 | _monitor = monitor; | 1679 | _monitor = monitor; |
4214 | 1633 | _monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(_monitor); | 1680 | _monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(_monitor); |
4215 | 1681 | |||
4216 | 1682 | _maximized_set.clear(); | ||
4217 | 1683 | GList* windows = bamf_matcher_get_window_stack_for_monitor(_matcher, _monitor); | ||
4218 | 1684 | |||
4219 | 1685 | for (GList* l = windows; l; l = l->next) | ||
4220 | 1686 | { | ||
4221 | 1687 | if (!BAMF_IS_WINDOW(l->data)) | ||
4222 | 1688 | continue; | ||
4223 | 1689 | |||
4224 | 1690 | auto window = static_cast<BamfWindow*>(l->data); | ||
4225 | 1691 | auto view = static_cast<BamfView*>(l->data); | ||
4226 | 1692 | |||
4227 | 1693 | if (bamf_view_is_active(view)) | ||
4228 | 1694 | { | ||
4229 | 1695 | _active_xid = bamf_window_get_xid(window); | ||
4230 | 1696 | } | ||
4231 | 1697 | |||
4232 | 1698 | if (bamf_window_maximized(window) == BAMF_WINDOW_MAXIMIZED) | ||
4233 | 1699 | { | ||
4234 | 1700 | Window xid = bamf_window_get_xid(window); | ||
4235 | 1701 | |||
4236 | 1702 | _decor_map[xid] = WindowManager::Default()->IsWindowDecorated(xid); | ||
4237 | 1703 | |||
4238 | 1704 | if (_decor_map[xid]) | ||
4239 | 1705 | WindowManager::Default()->Undecorate(xid); | ||
4240 | 1706 | |||
4241 | 1707 | _maximized_set.insert(xid); | ||
4242 | 1708 | } | ||
4243 | 1709 | } | ||
4244 | 1710 | |||
4245 | 1711 | Window maximized = GetMaximizedWindow(); | ||
4246 | 1712 | Window buttons_win = (maximized == _active_xid) ? maximized : 0; | ||
4247 | 1713 | |||
4248 | 1714 | _window_buttons->SetMonitor(_monitor); | ||
4249 | 1715 | _window_buttons->SetControlledWindow(buttons_win); | ||
4250 | 1716 | |||
4251 | 1717 | g_list_free(windows); | ||
4252 | 1634 | } | 1718 | } |
4253 | 1635 | 1719 | ||
4256 | 1636 | bool | 1720 | bool PanelMenuView::GetControlsActive() const |
4255 | 1637 | PanelMenuView::GetControlsActive() | ||
4257 | 1638 | { | 1721 | { |
4258 | 1639 | return _we_control_active; | 1722 | return _we_control_active; |
4259 | 1640 | } | 1723 | } |
4260 | 1641 | 1724 | ||
4269 | 1642 | bool | 1725 | void PanelMenuView::OnPanelViewMouseEnter(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state) |
4262 | 1643 | PanelMenuView::HasOurWindowFocused() | ||
4263 | 1644 | { | ||
4264 | 1645 | return _is_own_window; | ||
4265 | 1646 | } | ||
4266 | 1647 | |||
4267 | 1648 | void | ||
4268 | 1649 | PanelMenuView::OnPanelViewMouseEnter(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state) | ||
4270 | 1650 | { | 1726 | { |
4271 | 1651 | if (!_is_inside) | 1727 | if (!_is_inside) |
4272 | 1652 | { | 1728 | { |
4273 | @@ -1659,8 +1735,7 @@ | |||
4274 | 1659 | } | 1735 | } |
4275 | 1660 | } | 1736 | } |
4276 | 1661 | 1737 | ||
4279 | 1662 | void | 1738 | void PanelMenuView::OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state) |
4278 | 1663 | PanelMenuView::OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state) | ||
4280 | 1664 | { | 1739 | { |
4281 | 1665 | if (_is_inside) | 1740 | if (_is_inside) |
4282 | 1666 | { | 1741 | { |
4283 | 1667 | 1742 | ||
4284 | === modified file 'plugins/unityshell/src/PanelMenuView.h' | |||
4285 | --- plugins/unityshell/src/PanelMenuView.h 2012-03-21 12:31:11 +0000 | |||
4286 | +++ plugins/unityshell/src/PanelMenuView.h 2012-04-05 23:42:20 +0000 | |||
4287 | @@ -1,6 +1,6 @@ | |||
4288 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
4289 | 2 | /* | 2 | /* |
4291 | 3 | * Copyright (C) 2010 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
4292 | 4 | * | 4 | * |
4293 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
4294 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
4295 | @@ -15,14 +15,15 @@ | |||
4296 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4297 | 16 | * | 16 | * |
4298 | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
4299 | 18 | * Marco Trevisan <3v1n0@ubuntu.com> | ||
4300 | 18 | */ | 19 | */ |
4301 | 19 | 20 | ||
4302 | 20 | #ifndef PANEL_MENU_VIEW_H | 21 | #ifndef PANEL_MENU_VIEW_H |
4303 | 21 | #define PANEL_MENU_VIEW_H | 22 | #define PANEL_MENU_VIEW_H |
4304 | 22 | 23 | ||
4308 | 23 | #include <Nux/View.h> | 24 | #include <UnityCore/GLibWrapper.h> |
4309 | 24 | #include <map> | 25 | #include <UnityCore/GLibSignal.h> |
4310 | 25 | #include <set> | 26 | #include <libbamf/libbamf.h> |
4311 | 26 | 27 | ||
4312 | 27 | #include "PanelIndicatorsView.h" | 28 | #include "PanelIndicatorsView.h" |
4313 | 28 | #include "StaticCairoText.h" | 29 | #include "StaticCairoText.h" |
4314 | @@ -30,10 +31,7 @@ | |||
4315 | 30 | #include "PanelTitlebarGrabAreaView.h" | 31 | #include "PanelTitlebarGrabAreaView.h" |
4316 | 31 | #include "PluginAdapter.h" | 32 | #include "PluginAdapter.h" |
4317 | 32 | #include "Animator.h" | 33 | #include "Animator.h" |
4322 | 33 | 34 | #include "UBusWrapper.h" | |
4319 | 34 | #include <UnityCore/GLibWrapper.h> | ||
4320 | 35 | #include <UnityCore/GLibSignal.h> | ||
4321 | 36 | #include <libbamf/libbamf.h> | ||
4323 | 37 | 35 | ||
4324 | 38 | namespace unity | 36 | namespace unity |
4325 | 39 | { | 37 | { |
4326 | @@ -41,41 +39,50 @@ | |||
4327 | 41 | class PanelMenuView : public PanelIndicatorsView | 39 | class PanelMenuView : public PanelIndicatorsView |
4328 | 42 | { | 40 | { |
4329 | 43 | public: | 41 | public: |
4343 | 44 | // This contains all the menubar logic for the Panel. Mainly it contains | 42 | PanelMenuView(); |
4331 | 45 | // the following states: | ||
4332 | 46 | // 1. Unmaximized window + no mouse hover | ||
4333 | 47 | // 2. Unmaximized window + mouse hover | ||
4334 | 48 | // 3. Unmaximized window + active menu (Alt+F/arrow key nav) | ||
4335 | 49 | // 4. Maximized window + no mouse hover | ||
4336 | 50 | // 5. Maximized window + mouse hover | ||
4337 | 51 | // 6. Maximized window + active menu | ||
4338 | 52 | // | ||
4339 | 53 | // It also deals with undecorating maximized windows (and redecorating them | ||
4340 | 54 | // on unmaximize) | ||
4341 | 55 | |||
4342 | 56 | PanelMenuView(int padding = 6); | ||
4344 | 57 | ~PanelMenuView(); | 43 | ~PanelMenuView(); |
4345 | 58 | 44 | ||
4346 | 59 | void SetMenuShowTimings(int fadein, int fadeout, int discovery, | 45 | void SetMenuShowTimings(int fadein, int fadeout, int discovery, |
4347 | 60 | int discovery_fadein, int discovery_fadeout); | 46 | int discovery_fadein, int discovery_fadeout); |
4348 | 61 | 47 | ||
4350 | 62 | void FullRedraw(); | 48 | void SetMousePosition(int x, int y); |
4351 | 49 | void SetMonitor(int monitor); | ||
4352 | 50 | |||
4353 | 51 | Window GetTopWindow() const; | ||
4354 | 52 | Window GetMaximizedWindow() const; | ||
4355 | 53 | bool GetControlsActive() const; | ||
4356 | 54 | |||
4357 | 55 | void NotifyAllMenusClosed(); | ||
4358 | 56 | |||
4359 | 57 | virtual void AddIndicator(indicator::Indicator::Ptr const& indicator); | ||
4360 | 58 | |||
4361 | 59 | virtual void OverlayShown(); | ||
4362 | 60 | virtual void OverlayHidden(); | ||
4363 | 61 | |||
4364 | 62 | protected: | ||
4365 | 63 | std::string GetName() const; | ||
4366 | 64 | void AddProperties(GVariantBuilder* builder); | ||
4367 | 63 | 65 | ||
4368 | 64 | virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); | 66 | virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); |
4369 | 65 | virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); | 67 | virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); |
4374 | 66 | virtual long PostLayoutManagement(long LayoutResult); | 68 | virtual void PreLayoutManagement(); |
4375 | 67 | 69 | virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, | |
4376 | 68 | void SetMousePosition(int x, int y); | 70 | nux::NuxEventType event_type); |
4377 | 69 | 71 | virtual void OnEntryAdded(indicator::Entry::Ptr const& entry); | |
4378 | 72 | |||
4379 | 73 | private: | ||
4380 | 70 | void OnActiveChanged(PanelIndicatorEntryView* view, bool is_active); | 74 | void OnActiveChanged(PanelIndicatorEntryView* view, bool is_active); |
4381 | 71 | void OnViewOpened(BamfMatcher* matcher, BamfView* view); | 75 | void OnViewOpened(BamfMatcher* matcher, BamfView* view); |
4382 | 72 | void OnViewClosed(BamfMatcher* matcher, BamfView* view); | 76 | void OnViewClosed(BamfMatcher* matcher, BamfView* view); |
4383 | 77 | void OnApplicationClosed(BamfApplication* app); | ||
4384 | 73 | void OnActiveWindowChanged(BamfMatcher* matcher, BamfView* old_view, BamfView* new_view); | 78 | void OnActiveWindowChanged(BamfMatcher* matcher, BamfView* old_view, BamfView* new_view); |
4385 | 74 | void OnActiveAppChanged(BamfMatcher* matcher, BamfApplication* old_app, BamfApplication* new_app); | 79 | void OnActiveAppChanged(BamfMatcher* matcher, BamfApplication* old_app, BamfApplication* new_app); |
4386 | 75 | void OnNameChanged(BamfView* bamf_view, gchar* new_name, gchar* old_name); | 80 | void OnNameChanged(BamfView* bamf_view, gchar* new_name, gchar* old_name); |
4387 | 76 | 81 | ||
4388 | 77 | void OnSpreadInitiate(); | 82 | void OnSpreadInitiate(); |
4389 | 78 | void OnSpreadTerminate(); | 83 | void OnSpreadTerminate(); |
4390 | 84 | void OnExpoInitiate(); | ||
4391 | 85 | void OnExpoTerminate(); | ||
4392 | 79 | void OnWindowMinimized(guint32 xid); | 86 | void OnWindowMinimized(guint32 xid); |
4393 | 80 | void OnWindowUnminimized(guint32 xid); | 87 | void OnWindowUnminimized(guint32 xid); |
4394 | 81 | void OnWindowUnmapped(guint32 xid); | 88 | void OnWindowUnmapped(guint32 xid); |
4395 | @@ -86,42 +93,30 @@ | |||
4396 | 86 | void OnWindowDecorated(guint32 xid); | 93 | void OnWindowDecorated(guint32 xid); |
4397 | 87 | void OnWindowUndecorated(guint32 xid); | 94 | void OnWindowUndecorated(guint32 xid); |
4398 | 88 | 95 | ||
4424 | 89 | guint32 GetMaximizedWindow(); | 96 | void OnMaximizedActivate(int x, int y); |
4425 | 90 | 97 | void OnMaximizedRestore(int x, int y); | |
4426 | 91 | void OnMaximizedGrabStart(int, int, unsigned long, unsigned long); | 98 | void OnMaximizedLower(int x, int y); |
4427 | 92 | void OnMaximizedGrabMove(int, int, int, int, unsigned long, unsigned long); | 99 | void OnMaximizedGrabStart(int x, int y); |
4428 | 93 | void OnMaximizedGrabEnd(int, int, unsigned long, unsigned long); | 100 | void OnMaximizedGrabMove(int x, int y); |
4429 | 94 | void OnMouseDoubleClicked(int, int, unsigned long, unsigned long); | 101 | void OnMaximizedGrabEnd(int x, int y); |
4430 | 95 | void OnMouseClicked(int, int, unsigned long, unsigned long); | 102 | |
4431 | 96 | void OnMouseMiddleClicked(int, int, unsigned long, unsigned long); | 103 | void FullRedraw(); |
4432 | 97 | 104 | void Refresh(bool force = false); | |
4433 | 98 | void Refresh(); | 105 | void DrawTitle(cairo_t *cr_real, nux::Geometry const& geo, std::string const& label) const; |
4434 | 99 | void AllMenusClosed(); | 106 | |
4410 | 100 | |||
4411 | 101 | void OnCloseClicked(); | ||
4412 | 102 | void OnMinimizeClicked(); | ||
4413 | 103 | void OnRestoreClicked(); | ||
4414 | 104 | void SetMonitor(int monitor); | ||
4415 | 105 | bool GetControlsActive(); | ||
4416 | 106 | |||
4417 | 107 | bool HasOurWindowFocused(); | ||
4418 | 108 | |||
4419 | 109 | protected: | ||
4420 | 110 | std::string GetName() const; | ||
4421 | 111 | void AddProperties(GVariantBuilder* builder); | ||
4422 | 112 | |||
4423 | 113 | virtual nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type); | ||
4435 | 114 | void OnPanelViewMouseEnter(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); | 107 | void OnPanelViewMouseEnter(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); |
4436 | 115 | void OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); | 108 | void OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state); |
4437 | 116 | void OnPanelViewMouseMove(int x, int y, int dx, int dy, unsigned long mouse_button_state, unsigned long special_keys_state); | 109 | void OnPanelViewMouseMove(int x, int y, int dx, int dy, unsigned long mouse_button_state, unsigned long special_keys_state); |
4446 | 117 | virtual void OnEntryAdded(unity::indicator::Entry::Ptr const& entry); | 110 | |
4447 | 118 | 111 | BamfWindow* GetBamfWindowForXid(Window xid) const; | |
4448 | 119 | private: | 112 | |
4449 | 120 | gchar* GetActiveViewName(); | 113 | std::string GetActiveViewName(bool use_appname = false) const; |
4450 | 121 | static void OnPlaceViewShown(GVariant* data, PanelMenuView* self); | 114 | |
4451 | 122 | static void OnPlaceViewHidden(GVariant* data, PanelMenuView* self); | 115 | void OnSwitcherShown(GVariant* data); |
4452 | 123 | static void OnSwitcherShown(GVariant* data, PanelMenuView* self); | 116 | void OnSwitcherSelectionChanged(GVariant* data); |
4453 | 124 | static void OnSwitcherSelectionChanged(GVariant* data, PanelMenuView* self); | 117 | void OnLauncherKeyNavStarted(GVariant* data); |
4454 | 118 | void OnLauncherKeyNavEnded(GVariant* data); | ||
4455 | 119 | void OnLauncherSelectionChanged(GVariant* data); | ||
4456 | 125 | 120 | ||
4457 | 126 | void UpdateShowNow(bool ignore); | 121 | void UpdateShowNow(bool ignore); |
4458 | 127 | 122 | ||
4459 | @@ -130,53 +125,47 @@ | |||
4460 | 130 | static gboolean OnNewAppShow(PanelMenuView* self); | 125 | static gboolean OnNewAppShow(PanelMenuView* self); |
4461 | 131 | static gboolean OnNewAppHide(PanelMenuView* self); | 126 | static gboolean OnNewAppHide(PanelMenuView* self); |
4462 | 132 | 127 | ||
4469 | 133 | void DrawText(cairo_t *cr_real, | 128 | bool IsValidWindow(Window xid) const; |
4470 | 134 | int &x, int y, int width, int height, | 129 | bool IsWindowUnderOurControl(Window xid) const; |
4465 | 135 | const char* font_desc, | ||
4466 | 136 | const char* label, | ||
4467 | 137 | int increase_size=0 | ||
4468 | 138 | ); | ||
4471 | 139 | 130 | ||
4474 | 140 | bool DrawMenus(); | 131 | bool DrawMenus() const; |
4475 | 141 | bool DrawWindowButtons(); | 132 | bool DrawWindowButtons() const; |
4476 | 142 | 133 | ||
4477 | 143 | void OnFadeInChanged(double); | 134 | void OnFadeInChanged(double); |
4478 | 144 | void OnFadeOutChanged(double); | 135 | void OnFadeOutChanged(double); |
4479 | 145 | 136 | ||
4480 | 146 | private: | ||
4481 | 147 | glib::Object<BamfMatcher> _matcher; | 137 | glib::Object<BamfMatcher> _matcher; |
4482 | 148 | 138 | ||
4486 | 149 | nux::TextureLayer* _title_layer; | 139 | nux::TextureLayer* _title_layer; |
4487 | 150 | nux::HLayout* _menu_layout; | 140 | nux::HLayout* _menu_layout; |
4488 | 151 | nux::CairoGraphics _util_cg; | 141 | nux::ObjectPtr<nux::BaseTexture> _title_texture; |
4489 | 152 | nux::ObjectPtr<nux::IOpenGLBaseTexture> _gradient_texture; | 142 | nux::ObjectPtr<nux::IOpenGLBaseTexture> _gradient_texture; |
4490 | 153 | 143 | ||
4491 | 154 | bool _is_inside; | 144 | bool _is_inside; |
4492 | 155 | bool _is_grabbed; | 145 | bool _is_grabbed; |
4493 | 156 | bool _is_maximized; | 146 | bool _is_maximized; |
4495 | 157 | bool _is_own_window; | 147 | |
4496 | 158 | PanelIndicatorEntryView* _last_active_view; | 148 | PanelIndicatorEntryView* _last_active_view; |
4497 | 149 | WindowButtons* _window_buttons; | ||
4498 | 150 | PanelTitlebarGrabArea* _titlebar_grab_area; | ||
4499 | 159 | glib::Object<BamfApplication> _new_application; | 151 | glib::Object<BamfApplication> _new_application; |
4500 | 160 | 152 | ||
4506 | 161 | WindowButtons* _window_buttons; | 153 | std::map<Window, bool> _decor_map; |
4507 | 162 | PanelTitlebarGrabArea* _panel_titlebar_grab_area; | 154 | std::set<Window> _maximized_set; |
4503 | 163 | |||
4504 | 164 | std::map<guint32, bool> _decor_map; | ||
4505 | 165 | std::set<guint32> _maximized_set; | ||
4508 | 166 | std::list<glib::Object<BamfApplication>> _new_apps; | 155 | std::list<glib::Object<BamfApplication>> _new_apps; |
4515 | 167 | 156 | std::string _panel_title; | |
4516 | 168 | int _padding; | 157 | nux::Geometry _last_geo; |
4517 | 169 | int _last_width; | 158 | |
4518 | 170 | int _last_height; | 159 | bool _overlay_showing; |
4513 | 171 | |||
4514 | 172 | bool _places_showing; | ||
4519 | 173 | bool _switcher_showing; | 160 | bool _switcher_showing; |
4520 | 161 | bool _launcher_keynav; | ||
4521 | 174 | bool _show_now_activated; | 162 | bool _show_now_activated; |
4522 | 175 | bool _we_control_active; | 163 | bool _we_control_active; |
4523 | 176 | bool _new_app_menu_shown; | 164 | bool _new_app_menu_shown; |
4524 | 177 | 165 | ||
4527 | 178 | int _monitor; | 166 | int _monitor; |
4528 | 179 | guint32 _active_xid; | 167 | Window _active_xid; |
4529 | 168 | |||
4530 | 180 | guint32 _active_moved_id; | 169 | guint32 _active_moved_id; |
4531 | 181 | guint32 _update_show_now_id; | 170 | guint32 _update_show_now_id; |
4532 | 182 | guint32 _new_app_show_id; | 171 | guint32 _new_app_show_id; |
4533 | @@ -188,8 +177,9 @@ | |||
4534 | 188 | glib::Signal<void, BamfMatcher*, BamfView*, BamfView*> _active_win_changed_signal; | 177 | glib::Signal<void, BamfMatcher*, BamfView*, BamfView*> _active_win_changed_signal; |
4535 | 189 | glib::Signal<void, BamfMatcher*, BamfApplication*, BamfApplication*> _active_app_changed_signal; | 178 | glib::Signal<void, BamfMatcher*, BamfApplication*, BamfApplication*> _active_app_changed_signal; |
4536 | 190 | glib::Signal<void, BamfView*, gchar*, gchar*> _view_name_changed_signal; | 179 | glib::Signal<void, BamfView*, gchar*, gchar*> _view_name_changed_signal; |
4537 | 180 | sigc::connection _style_changed_connection; | ||
4538 | 191 | 181 | ||
4540 | 192 | std::vector<unsigned int> _ubus_interests; | 182 | UBusManager _ubus_manager; |
4541 | 193 | 183 | ||
4542 | 194 | int _menus_fadein; | 184 | int _menus_fadein; |
4543 | 195 | int _menus_fadeout; | 185 | int _menus_fadeout; |
4544 | @@ -197,10 +187,8 @@ | |||
4545 | 197 | int _menus_discovery_fadein; | 187 | int _menus_discovery_fadein; |
4546 | 198 | int _menus_discovery_fadeout; | 188 | int _menus_discovery_fadeout; |
4547 | 199 | 189 | ||
4552 | 200 | gchar* _panel_title; | 190 | Animator _fade_in_animator; |
4553 | 201 | 191 | Animator _fade_out_animator; | |
4550 | 202 | Animator* _fade_in_animator; | ||
4551 | 203 | Animator* _fade_out_animator; | ||
4554 | 204 | }; | 192 | }; |
4555 | 205 | 193 | ||
4556 | 206 | } | 194 | } |
4557 | 207 | 195 | ||
4558 | === modified file 'plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp' | |||
4559 | --- plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp 2012-02-25 16:19:39 +0000 | |||
4560 | +++ plugins/unityshell/src/PanelTitlebarGrabAreaView.cpp 2012-04-05 23:42:20 +0000 | |||
4561 | @@ -1,6 +1,6 @@ | |||
4562 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
4563 | 2 | /* | 2 | /* |
4565 | 3 | * Copyright (C) 2010-2011 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
4566 | 4 | * | 4 | * |
4567 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
4568 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
4569 | @@ -27,17 +27,41 @@ | |||
4570 | 27 | #include <UnityCore/Variant.h> | 27 | #include <UnityCore/Variant.h> |
4571 | 28 | #include <X11/cursorfont.h> | 28 | #include <X11/cursorfont.h> |
4572 | 29 | 29 | ||
4573 | 30 | namespace unity | ||
4574 | 31 | { | ||
4575 | 32 | namespace | ||
4576 | 33 | { | ||
4577 | 34 | unsigned int MOUSE_DOWN_TIMEOUT = 150; | ||
4578 | 35 | unsigned int MOUSE_MOVEMENT_TOLERANCE = 4; | ||
4579 | 36 | } | ||
4580 | 37 | |||
4581 | 30 | PanelTitlebarGrabArea::PanelTitlebarGrabArea() | 38 | PanelTitlebarGrabArea::PanelTitlebarGrabArea() |
4582 | 31 | : InputArea(NUX_TRACKER_LOCATION) | 39 | : InputArea(NUX_TRACKER_LOCATION) |
4584 | 32 | , _grab_cursor(None) | 40 | , grab_cursor_(None) |
4585 | 41 | , grab_started_(false) | ||
4586 | 42 | , mouse_down_timer_(0) | ||
4587 | 43 | , mouse_down_button_(0) | ||
4588 | 33 | { | 44 | { |
4589 | 34 | EnableDoubleClick(true); | 45 | EnableDoubleClick(true); |
4590 | 46 | |||
4591 | 47 | mouse_down.connect(sigc::mem_fun(this, &PanelTitlebarGrabArea::OnMouseDown)); | ||
4592 | 48 | mouse_up.connect(sigc::mem_fun(this, &PanelTitlebarGrabArea::OnMouseUp)); | ||
4593 | 49 | mouse_drag.connect(sigc::mem_fun(this, &PanelTitlebarGrabArea::OnGrabMove)); | ||
4594 | 50 | |||
4595 | 51 | mouse_double_click.connect([&] (int x, int y, unsigned long button_flags, unsigned long) | ||
4596 | 52 | { | ||
4597 | 53 | if (nux::GetEventButton(button_flags) == 1) | ||
4598 | 54 | restore_request.emit(x, y); | ||
4599 | 55 | }); | ||
4600 | 35 | } | 56 | } |
4601 | 36 | 57 | ||
4602 | 37 | PanelTitlebarGrabArea::~PanelTitlebarGrabArea() | 58 | PanelTitlebarGrabArea::~PanelTitlebarGrabArea() |
4603 | 38 | { | 59 | { |
4606 | 39 | if (_grab_cursor) | 60 | if (grab_cursor_) |
4607 | 40 | XFreeCursor(nux::GetGraphicsDisplay()->GetX11Display(), _grab_cursor); | 61 | XFreeCursor(nux::GetGraphicsDisplay()->GetX11Display(), grab_cursor_); |
4608 | 62 | |||
4609 | 63 | if (mouse_down_timer_) | ||
4610 | 64 | g_source_remove(mouse_down_timer_); | ||
4611 | 41 | } | 65 | } |
4612 | 42 | 66 | ||
4613 | 43 | void PanelTitlebarGrabArea::SetGrabbed(bool enabled) | 67 | void PanelTitlebarGrabArea::SetGrabbed(bool enabled) |
4614 | @@ -48,32 +72,120 @@ | |||
4615 | 48 | if (!panel_window || !display) | 72 | if (!panel_window || !display) |
4616 | 49 | return; | 73 | return; |
4617 | 50 | 74 | ||
4619 | 51 | if (enabled && !_grab_cursor) | 75 | if (enabled && !grab_cursor_) |
4620 | 52 | { | 76 | { |
4623 | 53 | _grab_cursor = XCreateFontCursor(display, XC_fleur); | 77 | grab_cursor_ = XCreateFontCursor(display, XC_fleur); |
4624 | 54 | XDefineCursor(display, panel_window->GetInputWindowId(), _grab_cursor); | 78 | XDefineCursor(display, panel_window->GetInputWindowId(), grab_cursor_); |
4625 | 55 | } | 79 | } |
4627 | 56 | else if (!enabled && _grab_cursor) | 80 | else if (!enabled && grab_cursor_) |
4628 | 57 | { | 81 | { |
4629 | 58 | XUndefineCursor(display, panel_window->GetInputWindowId()); | 82 | XUndefineCursor(display, panel_window->GetInputWindowId()); |
4632 | 59 | XFreeCursor(display, _grab_cursor); | 83 | XFreeCursor(display, grab_cursor_); |
4633 | 60 | _grab_cursor = None; | 84 | grab_cursor_ = None; |
4634 | 61 | } | 85 | } |
4635 | 62 | } | 86 | } |
4636 | 63 | 87 | ||
4637 | 64 | bool PanelTitlebarGrabArea::IsGrabbed() | 88 | bool PanelTitlebarGrabArea::IsGrabbed() |
4638 | 65 | { | 89 | { |
4640 | 66 | return (_grab_cursor != None); | 90 | return (grab_cursor_ != None); |
4641 | 91 | } | ||
4642 | 92 | |||
4643 | 93 | void PanelTitlebarGrabArea::OnMouseDown(int x, int y, unsigned long button_flags, unsigned long) | ||
4644 | 94 | { | ||
4645 | 95 | mouse_down_button_ = nux::GetEventButton(button_flags); | ||
4646 | 96 | |||
4647 | 97 | if (mouse_down_button_ == 2) | ||
4648 | 98 | { | ||
4649 | 99 | lower_request.emit(x, y); | ||
4650 | 100 | } | ||
4651 | 101 | else if (mouse_down_button_ == 1) | ||
4652 | 102 | { | ||
4653 | 103 | mouse_down_point_.x = x; | ||
4654 | 104 | mouse_down_point_.y = y; | ||
4655 | 105 | |||
4656 | 106 | mouse_down_timer_ = | ||
4657 | 107 | g_timeout_add(MOUSE_DOWN_TIMEOUT, [] (gpointer data) -> gboolean { | ||
4658 | 108 | auto self = static_cast<PanelTitlebarGrabArea*>(data); | ||
4659 | 109 | |||
4660 | 110 | if (!self->grab_started_) | ||
4661 | 111 | { | ||
4662 | 112 | nux::Point const& mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); | ||
4663 | 113 | self->grab_started.emit(mouse.x - self->GetAbsoluteX(), mouse.y - self->GetAbsoluteY()); | ||
4664 | 114 | self->grab_started_ = true; | ||
4665 | 115 | } | ||
4666 | 116 | |||
4667 | 117 | self->mouse_down_timer_ = 0; | ||
4668 | 118 | return FALSE; | ||
4669 | 119 | }, this); | ||
4670 | 120 | } | ||
4671 | 121 | } | ||
4672 | 122 | |||
4673 | 123 | void PanelTitlebarGrabArea::OnMouseUp(int x, int y, unsigned long button_flags, unsigned long) | ||
4674 | 124 | { | ||
4675 | 125 | int button = nux::GetEventButton(button_flags); | ||
4676 | 126 | |||
4677 | 127 | if (button == 1) | ||
4678 | 128 | { | ||
4679 | 129 | if (mouse_down_timer_) | ||
4680 | 130 | { | ||
4681 | 131 | g_source_remove(mouse_down_timer_); | ||
4682 | 132 | mouse_down_timer_ = 0; | ||
4683 | 133 | |||
4684 | 134 | activate_request.emit(x, y); | ||
4685 | 135 | } | ||
4686 | 136 | |||
4687 | 137 | if (grab_started_) | ||
4688 | 138 | { | ||
4689 | 139 | grab_end.emit(x, y); | ||
4690 | 140 | grab_started_ = false; | ||
4691 | 141 | } | ||
4692 | 142 | } | ||
4693 | 143 | |||
4694 | 144 | mouse_down_button_ = 0; | ||
4695 | 145 | mouse_down_point_.x = 0; | ||
4696 | 146 | mouse_down_point_.y = 0; | ||
4697 | 147 | } | ||
4698 | 148 | |||
4699 | 149 | void PanelTitlebarGrabArea::OnGrabMove(int x, int y, int, int, unsigned long button_flags, unsigned long) | ||
4700 | 150 | { | ||
4701 | 151 | if (mouse_down_button_ != 1) | ||
4702 | 152 | return; | ||
4703 | 153 | |||
4704 | 154 | if (mouse_down_timer_) | ||
4705 | 155 | { | ||
4706 | 156 | if (abs(mouse_down_point_.x - x) <= MOUSE_MOVEMENT_TOLERANCE && | ||
4707 | 157 | abs(mouse_down_point_.y - y) <= MOUSE_MOVEMENT_TOLERANCE) | ||
4708 | 158 | { | ||
4709 | 159 | return; | ||
4710 | 160 | } | ||
4711 | 161 | |||
4712 | 162 | g_source_remove(mouse_down_timer_); | ||
4713 | 163 | mouse_down_timer_ = 0; | ||
4714 | 164 | } | ||
4715 | 165 | |||
4716 | 166 | if (!grab_started_) | ||
4717 | 167 | { | ||
4718 | 168 | grab_started.emit(x, y); | ||
4719 | 169 | grab_started_ = true; | ||
4720 | 170 | } | ||
4721 | 171 | else | ||
4722 | 172 | { | ||
4723 | 173 | grab_move.emit(x, y); | ||
4724 | 174 | } | ||
4725 | 67 | } | 175 | } |
4726 | 68 | 176 | ||
4727 | 69 | std::string | 177 | std::string |
4728 | 70 | PanelTitlebarGrabArea::GetName() const | 178 | PanelTitlebarGrabArea::GetName() const |
4729 | 71 | { | 179 | { |
4731 | 72 | return "panel-titlebar-grab-area"; | 180 | return "GrabArea"; |
4732 | 73 | } | 181 | } |
4733 | 74 | 182 | ||
4734 | 75 | void | 183 | void |
4735 | 76 | PanelTitlebarGrabArea::AddProperties(GVariantBuilder* builder) | 184 | PanelTitlebarGrabArea::AddProperties(GVariantBuilder* builder) |
4736 | 77 | { | 185 | { |
4738 | 78 | unity::variant::BuilderWrapper(builder).add(GetGeometry()); | 186 | unity::variant::BuilderWrapper(builder) |
4739 | 187 | .add(GetGeometry()) | ||
4740 | 188 | .add("grabbed", IsGrabbed()); | ||
4741 | 189 | } | ||
4742 | 190 | |||
4743 | 79 | } | 191 | } |
4744 | 80 | 192 | ||
4745 | === modified file 'plugins/unityshell/src/PanelTitlebarGrabAreaView.h' | |||
4746 | --- plugins/unityshell/src/PanelTitlebarGrabAreaView.h 2012-02-25 16:19:39 +0000 | |||
4747 | +++ plugins/unityshell/src/PanelTitlebarGrabAreaView.h 2012-04-05 23:42:20 +0000 | |||
4748 | @@ -1,6 +1,6 @@ | |||
4749 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
4750 | 2 | /* | 2 | /* |
4752 | 3 | * Copyright (C) 2010-2011 Canonical Ltd | 3 | * Copyright (C) 2010-2012 Canonical Ltd |
4753 | 4 | * | 4 | * |
4754 | 5 | * This program is free software: you can redistribute it and/or modify | 5 | * This program is free software: you can redistribute it and/or modify |
4755 | 6 | * it under the terms of the GNU General Public License version 3 as | 6 | * it under the terms of the GNU General Public License version 3 as |
4756 | @@ -27,10 +27,13 @@ | |||
4757 | 27 | 27 | ||
4758 | 28 | #include "Introspectable.h" | 28 | #include "Introspectable.h" |
4759 | 29 | 29 | ||
4760 | 30 | namespace unity | ||
4761 | 31 | { | ||
4762 | 32 | |||
4763 | 30 | class PanelTitlebarGrabArea : public nux::InputArea, public unity::debug::Introspectable | 33 | class PanelTitlebarGrabArea : public nux::InputArea, public unity::debug::Introspectable |
4764 | 31 | { | 34 | { |
4767 | 32 | /* This acts a bit like a titlebar, it can be grabbed (such that we can pull | 35 | /* This acts a bit like a decorator, it can be clicked or grabbed (such that |
4768 | 33 | * the window down) */ | 36 | * we can pull the window down) */ |
4769 | 34 | 37 | ||
4770 | 35 | public: | 38 | public: |
4771 | 36 | PanelTitlebarGrabArea(); | 39 | PanelTitlebarGrabArea(); |
4772 | @@ -39,11 +42,29 @@ | |||
4773 | 39 | void SetGrabbed(bool enabled); | 42 | void SetGrabbed(bool enabled); |
4774 | 40 | bool IsGrabbed(); | 43 | bool IsGrabbed(); |
4775 | 41 | 44 | ||
4776 | 45 | sigc::signal<void, int, int> lower_request; | ||
4777 | 46 | sigc::signal<void, int, int> activate_request; | ||
4778 | 47 | sigc::signal<void, int, int> restore_request; | ||
4779 | 48 | sigc::signal<void, int, int> grab_started; | ||
4780 | 49 | sigc::signal<void, int, int> grab_move; | ||
4781 | 50 | sigc::signal<void, int, int> grab_end; | ||
4782 | 51 | |||
4783 | 52 | protected: | ||
4784 | 53 | std::string GetName() const; | ||
4785 | 54 | void AddProperties(GVariantBuilder* builder); | ||
4786 | 55 | |||
4787 | 42 | private: | 56 | private: |
4790 | 43 | std::string GetName() const; | 57 | void OnMouseDown(int x, int y, unsigned long button_flags, unsigned long); |
4791 | 44 | void AddProperties(GVariantBuilder* builder); | 58 | void OnMouseUp(int x, int y, unsigned long button_flags, unsigned long); |
4792 | 59 | void OnGrabMove(int x, int y, int, int, unsigned long button_flags, unsigned long); | ||
4793 | 45 | 60 | ||
4795 | 46 | Cursor _grab_cursor; | 61 | Cursor grab_cursor_; |
4796 | 62 | bool grab_started_; | ||
4797 | 63 | guint mouse_down_timer_; | ||
4798 | 64 | nux::Point mouse_down_point_; | ||
4799 | 65 | unsigned int mouse_down_button_; | ||
4800 | 47 | }; | 66 | }; |
4801 | 48 | 67 | ||
4802 | 68 | } // NAMESPACE | ||
4803 | 69 | |||
4804 | 49 | #endif | 70 | #endif |
4805 | 50 | 71 | ||
4806 | === modified file 'plugins/unityshell/src/PanelTray.cpp' | |||
4807 | --- plugins/unityshell/src/PanelTray.cpp 2012-03-21 12:31:11 +0000 | |||
4808 | +++ plugins/unityshell/src/PanelTray.cpp 2012-04-05 23:42:20 +0000 | |||
4809 | @@ -1,5 +1,5 @@ | |||
4810 | 1 | /* | 1 | /* |
4812 | 2 | * Copyright (C) 2010 Canonical Ltd | 2 | * Copyright (C) 2010-2012 Canonical Ltd |
4813 | 3 | * | 3 | * |
4814 | 4 | * This program is free software: you can redistribute it and/or modify | 4 | * This program is free software: you can redistribute it and/or modify |
4815 | 5 | * it under the terms of the GNU General Public License version 3 as | 5 | * it under the terms of the GNU General Public License version 3 as |
4816 | @@ -14,11 +14,14 @@ | |||
4817 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4818 | 15 | * | 15 | * |
4819 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> |
4820 | 17 | * Marco Trevisan (Treviño) <3v1n0@ubuntu.com> | ||
4821 | 17 | */ | 18 | */ |
4822 | 18 | 19 | ||
4823 | 19 | #include "PanelTray.h" | 20 | #include "PanelTray.h" |
4824 | 21 | #include "PanelStyle.h" | ||
4825 | 20 | 22 | ||
4826 | 21 | #include <NuxCore/Logger.h> | 23 | #include <NuxCore/Logger.h> |
4827 | 24 | #include <UnityCore/Variant.h> | ||
4828 | 22 | 25 | ||
4829 | 23 | namespace | 26 | namespace |
4830 | 24 | { | 27 | { |
4831 | @@ -31,137 +34,118 @@ | |||
4832 | 31 | { | 34 | { |
4833 | 32 | 35 | ||
4834 | 33 | PanelTray::PanelTray() | 36 | PanelTray::PanelTray() |
4873 | 34 | : View(NUX_TRACKER_LOCATION), | 37 | : View(NUX_TRACKER_LOCATION) |
4874 | 35 | _window(0), | 38 | , settings_(g_settings_new(SETTINGS_NAME.c_str())) |
4875 | 36 | _tray(NULL), | 39 | , window_(gtk_window_new(GTK_WINDOW_TOPLEVEL)) |
4876 | 37 | _last_x(0), | 40 | , whitelist_(g_settings_get_strv(settings_, "systray-whitelist")) |
4877 | 38 | _last_y(0), | 41 | { |
4878 | 39 | _tray_icon_added_id(0) | 42 | int panel_height = panel::Style::Instance().panel_height; |
4879 | 40 | { | 43 | |
4880 | 41 | _settings = g_settings_new(SETTINGS_NAME.c_str()); | 44 | whitelist_changed_.Connect(settings_, "changed::systray-whitelist", [&] (GSettings*, gchar*) { |
4881 | 42 | _whitelist = g_settings_get_strv(_settings, "systray-whitelist"); | 45 | g_strfreev(whitelist_); |
4882 | 43 | 46 | whitelist_ = g_settings_get_strv(settings_, "systray-whitelist"); | |
4883 | 44 | RealInit(); | 47 | }); |
4884 | 45 | } | 48 | |
4885 | 46 | 49 | auto gtkwindow = glib::object_cast<GtkWindow>(window_); | |
4886 | 47 | unsigned int | 50 | gtk_window_set_type_hint(gtkwindow, GDK_WINDOW_TYPE_HINT_DOCK); |
4887 | 48 | PanelTray::xid () | 51 | gtk_window_set_has_resize_grip(gtkwindow, FALSE); |
4888 | 49 | { | 52 | gtk_window_set_keep_above(gtkwindow, TRUE); |
4889 | 50 | if (!_window) | 53 | gtk_window_set_skip_pager_hint(gtkwindow, TRUE); |
4890 | 51 | return 0; | 54 | gtk_window_set_skip_taskbar_hint(gtkwindow, TRUE); |
4891 | 52 | 55 | gtk_window_resize(gtkwindow, 1, panel_height); | |
4892 | 53 | return gdk_x11_window_get_xid (gtk_widget_get_window (_window)); | 56 | gtk_window_move(gtkwindow, -panel_height,-panel_height); |
4893 | 54 | } | 57 | gtk_widget_set_name(window_, "UnityPanelApplet"); |
4894 | 55 | 58 | ||
4895 | 56 | void PanelTray::RealInit() | 59 | gtk_widget_set_visual(window_, gdk_screen_get_rgba_visual(gdk_screen_get_default())); |
4896 | 57 | { | 60 | gtk_widget_realize(window_); |
4897 | 58 | _window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 61 | gtk_widget_set_app_paintable(window_, TRUE); |
4898 | 59 | gtk_window_set_type_hint(GTK_WINDOW(_window), GDK_WINDOW_TYPE_HINT_DOCK); | 62 | draw_signal_.Connect(window_, "draw", sigc::mem_fun(this, &PanelTray::OnTrayDraw)); |
4861 | 60 | gtk_window_set_has_resize_grip(GTK_WINDOW(_window), FALSE); | ||
4862 | 61 | gtk_window_set_keep_above(GTK_WINDOW(_window), TRUE); | ||
4863 | 62 | gtk_window_set_skip_pager_hint(GTK_WINDOW(_window), TRUE); | ||
4864 | 63 | gtk_window_set_skip_taskbar_hint(GTK_WINDOW(_window), TRUE); | ||
4865 | 64 | gtk_window_resize(GTK_WINDOW(_window), 1, 24); | ||
4866 | 65 | gtk_window_move(GTK_WINDOW(_window), -24,-24); | ||
4867 | 66 | gtk_widget_set_name(_window, "UnityPanelApplet"); | ||
4868 | 67 | |||
4869 | 68 | gtk_widget_set_visual(_window, gdk_screen_get_rgba_visual(gdk_screen_get_default())); | ||
4870 | 69 | gtk_widget_realize(_window); | ||
4871 | 70 | gtk_widget_set_app_paintable(_window, TRUE); | ||
4872 | 71 | _tray_expose_id = g_signal_connect(_window, "draw", G_CALLBACK(PanelTray::OnTrayDraw), this); | ||
4899 | 72 | 63 | ||
4900 | 73 | if (!g_getenv("UNITY_PANEL_TRAY_DISABLE")) | 64 | if (!g_getenv("UNITY_PANEL_TRAY_DISABLE")) |
4901 | 74 | { | 65 | { |
4903 | 75 | _tray = na_tray_new_for_screen(gdk_screen_get_default(), | 66 | tray_ = na_tray_new_for_screen(gdk_screen_get_default(), |
4904 | 76 | GTK_ORIENTATION_HORIZONTAL, | 67 | GTK_ORIENTATION_HORIZONTAL, |
4905 | 77 | (NaTrayFilterCallback)FilterTrayCallback, | 68 | (NaTrayFilterCallback)FilterTrayCallback, |
4906 | 78 | this); | 69 | this); |
4914 | 79 | na_tray_set_icon_size(_tray, 24); | 70 | na_tray_set_icon_size(tray_, panel_height); |
4915 | 80 | 71 | ||
4916 | 81 | _tray_icon_added_id = g_signal_connect(na_tray_get_manager(_tray), "tray_icon_removed", | 72 | icon_removed_signal_.Connect(na_tray_get_manager(tray_), "tray_icon_removed", |
4917 | 82 | G_CALLBACK(PanelTray::OnTrayIconRemoved), this); | 73 | sigc::mem_fun(this, &PanelTray::OnTrayIconRemoved)); |
4918 | 83 | 74 | ||
4919 | 84 | gtk_container_add(GTK_CONTAINER(_window), GTK_WIDGET(_tray)); | 75 | gtk_container_add(GTK_CONTAINER(window_.RawPtr()), GTK_WIDGET(tray_.RawPtr())); |
4920 | 85 | gtk_widget_show(GTK_WIDGET(_tray)); | 76 | gtk_widget_show(GTK_WIDGET(tray_.RawPtr())); |
4921 | 86 | } | 77 | } |
4922 | 87 | 78 | ||
4925 | 88 | SetMinMaxSize(1, 24); | 79 | SetMinMaxSize(1, panel_height); |
4924 | 89 | |||
4926 | 90 | } | 80 | } |
4927 | 91 | 81 | ||
4928 | 92 | PanelTray::~PanelTray() | 82 | PanelTray::~PanelTray() |
4929 | 93 | { | 83 | { |
4930 | 94 | if (_tray) | ||
4931 | 95 | { | ||
4932 | 96 | g_signal_handler_disconnect(na_tray_get_manager(_tray), _tray_icon_added_id); | ||
4933 | 97 | _tray = NULL; | ||
4934 | 98 | } | ||
4935 | 99 | |||
4936 | 100 | g_idle_remove_by_data(this); | 84 | g_idle_remove_by_data(this); |
4950 | 101 | 85 | g_strfreev(whitelist_); | |
4951 | 102 | if (_tray_expose_id) | 86 | |
4952 | 103 | g_signal_handler_disconnect(_window, _tray_expose_id); | 87 | if (gtk_widget_get_realized(window_)) |
4953 | 104 | 88 | gtk_widget_destroy(window_); | |
4954 | 105 | gtk_widget_destroy(_window); | 89 | } |
4955 | 106 | g_strfreev(_whitelist); | 90 | |
4956 | 107 | g_object_unref(_settings); | 91 | Window PanelTray::xid() |
4957 | 108 | } | 92 | { |
4958 | 109 | 93 | if (!window_) | |
4959 | 110 | void | 94 | return 0; |
4960 | 111 | PanelTray::Draw(nux::GraphicsEngine& gfx_context, bool force_draw) | 95 | |
4961 | 112 | { | 96 | return gdk_x11_window_get_xid(gtk_widget_get_window(window_)); |
4962 | 113 | nux::Geometry geo(GetAbsoluteGeometry()); | 97 | } |
4963 | 98 | |||
4964 | 99 | void PanelTray::Draw(nux::GraphicsEngine& gfx_context, bool force_draw) | ||
4965 | 100 | { | ||
4966 | 101 | nux::Geometry const& geo = GetAbsoluteGeometry(); | ||
4967 | 114 | 102 | ||
4968 | 115 | gfx_context.PushClippingRectangle(geo); | 103 | gfx_context.PushClippingRectangle(geo); |
4969 | 116 | nux::GetPainter().PaintBackground(gfx_context, geo); | 104 | nux::GetPainter().PaintBackground(gfx_context, geo); |
4970 | 117 | gfx_context.PopClippingRectangle(); | 105 | gfx_context.PopClippingRectangle(); |
4971 | 118 | 106 | ||
4973 | 119 | if (geo.x != _last_x || geo.y != _last_y) | 107 | if (geo != last_geo_) |
4974 | 120 | { | 108 | { |
4979 | 121 | _last_x = geo.x; | 109 | last_geo_ = geo; |
4980 | 122 | _last_y = geo.y; | 110 | gtk_window_move(GTK_WINDOW(window_.RawPtr()), geo.x + PADDING, geo.y); |
4977 | 123 | |||
4978 | 124 | gtk_window_move(GTK_WINDOW(_window), geo.x + PADDING, geo.y); | ||
4981 | 125 | } | 111 | } |
4982 | 126 | } | 112 | } |
4983 | 127 | 113 | ||
4986 | 128 | void | 114 | void PanelTray::Sync() |
4985 | 129 | PanelTray::Sync() | ||
4987 | 130 | { | 115 | { |
4989 | 131 | if (_tray) | 116 | if (tray_) |
4990 | 132 | { | 117 | { |
4992 | 133 | SetMinMaxSize(WidthOfTray() + (PADDING * 2), 24); | 118 | SetMinMaxSize(WidthOfTray() + (PADDING * 2), panel::Style::Instance().panel_height); |
4993 | 134 | QueueRelayout(); | 119 | QueueRelayout(); |
4994 | 135 | QueueDraw(); | 120 | QueueDraw(); |
4995 | 136 | 121 | ||
4998 | 137 | if (_children.size()) | 122 | if (!children_.empty()) |
4999 | 138 | gtk_widget_show(_window); | 123 | gtk_widget_show(window_); |
5000 | 139 | else | 124 | else |
OMG, WTF? 7.5k lines in the last week? This had better work :-)