Merge lp:~brandontschaefer/unity/fix-lockscreen-hidpi-support into lp:unity

Proposed by Brandon Schaefer
Status: Work in progress
Proposed branch: lp:~brandontschaefer/unity/fix-lockscreen-hidpi-support
Merge into: lp:unity
Diff against target: 297 lines (+58/-35)
7 files modified
lockscreen/BackgroundSettings.cpp (+5/-2)
lockscreen/LockScreenController.h (+3/-1)
lockscreen/LockScreenPanel.cpp (+2/-0)
lockscreen/LockScreenShield.cpp (+22/-12)
lockscreen/LockScreenShield.h (+1/-1)
lockscreen/UserPromptView.cpp (+23/-18)
lockscreen/UserPromptView.h (+2/-1)
To merge this branch: bzr merge lp:~brandontschaefer/unity/fix-lockscreen-hidpi-support
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+210907@code.launchpad.net

Commit message

Get the scale value from the current monitor, and scale what we need.

Description of the change

* Warning * Need to test on multi monitor :)

Otherwise, this branch looks good on a single monitor. Just get the scale value from the current monitor, and scale what we need. Pretty simple.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

3720. By Brandon Schaefer

* Fix HiDPI in the Lockscreen

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lockscreen/BackgroundSettings.cpp'
2--- lockscreen/BackgroundSettings.cpp 2014-03-07 18:34:03 +0000
3+++ lockscreen/BackgroundSettings.cpp 2014-03-13 21:04:54 +0000
4@@ -25,6 +25,7 @@
5 #include "LockScreenSettings.h"
6 #include "unity-shared/CairoTexture.h"
7 #include "unity-shared/PanelStyle.h"
8+#include "unity-shared/UnitySettings.h"
9 #include "unity-shared/UScreen.h"
10
11 namespace unity
12@@ -51,20 +52,22 @@
13 BaseTexturePtr BackgroundSettings::GetBackgroundTexture(int monitor)
14 {
15 nux::Geometry const& geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
16+ double scale = unity::Settings::Instance().em(monitor)->DPIScale();
17 auto& settings = Settings::Instance();
18
19 nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, geo.width, geo.height);
20+ cairo_surface_set_device_scale(cairo_graphics.GetSurface(), scale, scale);
21 cairo_t* c = cairo_graphics.GetInternalContext();
22
23 cairo_surface_t* bg_surface = nullptr;
24
25 if (settings.use_user_background())
26 {
27- bg_surface = gnome_bg_create_surface(gnome_bg_, gdk_get_default_root_window(), geo.width, geo.height, FALSE);
28+ bg_surface = gnome_bg_create_surface(gnome_bg_, gdk_get_default_root_window(), geo.width / scale, geo.height / scale, FALSE);
29 }
30 else if (!settings.background().empty())
31 {
32- glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file_at_scale(settings.background().c_str(), geo.width, geo.height, FALSE, NULL));
33+ glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file_at_scale(settings.background().c_str(), geo.width / scale, geo.height / scale, FALSE, NULL));
34
35 if (pixbuf)
36 bg_surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, 0, NULL);
37
38=== modified file 'lockscreen/LockScreenController.h'
39--- lockscreen/LockScreenController.h 2014-03-07 19:17:35 +0000
40+++ lockscreen/LockScreenController.h 2014-03-13 21:04:54 +0000
41@@ -57,6 +57,8 @@
42 void OnUnlockRequested();
43 void OnPrimaryShieldMotion(int x, int y);
44
45+ void OnDPIChanged();
46+
47 std::vector<nux::ObjectPtr<AbstractShield>> shields_;
48 nux::ObjectWeakPtr<AbstractShield> primary_shield_;
49 session::Manager::Ptr session_manager_;
50@@ -73,4 +75,4 @@
51 }
52 }
53
54-#endif
55\ No newline at end of file
56+#endif
57
58=== modified file 'lockscreen/LockScreenPanel.cpp'
59--- lockscreen/LockScreenPanel.cpp 2014-03-07 19:02:25 +0000
60+++ lockscreen/LockScreenPanel.cpp 2014-03-13 21:04:54 +0000
61@@ -91,8 +91,10 @@
62
63 void Panel::BuildTexture()
64 {
65+ double scale = unity::Settings::Instance().em(monitor)->DPIScale();
66 int height = panel::Style::Instance().PanelHeight(monitor);
67 nux::CairoGraphics context(CAIRO_FORMAT_ARGB32, 1, height);
68+ cairo_surface_set_device_scale(context.GetSurface(), scale, scale);
69 auto* cr = context.GetInternalContext();
70 cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
71 cairo_paint_with_alpha(cr, 0.4);
72
73=== modified file 'lockscreen/LockScreenShield.cpp'
74--- lockscreen/LockScreenShield.cpp 2014-03-07 19:35:46 +0000
75+++ lockscreen/LockScreenShield.cpp 2014-03-13 21:04:54 +0000
76@@ -28,6 +28,8 @@
77 #include "LockScreenPanel.h"
78 #include "LockScreenSettings.h"
79 #include "UserPromptView.h"
80+#include "unity-shared/RawPixel.h"
81+#include "unity-shared/UnitySettings.h"
82 #include "unity-shared/UScreen.h"
83 #include "unity-shared/WindowManager.h"
84
85@@ -36,6 +38,15 @@
86 namespace lockscreen
87 {
88
89+namespace
90+{
91+ // 10 is just a random number to center the prompt view.
92+ RawPixel const LAYOUT_SPACE = 10_em;
93+ RawPixel const PROMPT_WIDTH = 8_em;
94+ RawPixel const PROMPT_HEIGHT = 3_em;
95+ RawPixel const PROMPT_LR_PAD = 2_em;
96+}
97+
98 Shield::Shield(session::Manager::Ptr const& session_manager, indicator::Indicators::Ptr const& indicators, int monitor_num, bool is_primary)
99 : AbstractShield(session_manager, indicators, monitor_num, is_primary)
100 , bg_settings_(std::make_shared<BackgroundSettings>())
101@@ -104,15 +115,15 @@
102 main_layout->AddView(CreatePanel());
103
104 nux::HLayout* prompt_layout = new nux::HLayout();
105- prompt_layout->SetLeftAndRightPadding(2 * Settings::GRID_SIZE);
106+ double scale = unity::Settings::Instance().em(monitor)->DPIScale();
107+ prompt_layout->SetLeftAndRightPadding(PROMPT_LR_PAD.CP(scale) * Settings::GRID_SIZE);
108
109 prompt_view_ = CreatePromptView();
110 prompt_layout->AddView(prompt_view_);
111
112- // 10 is just a random number to center the prompt view.
113- main_layout->AddSpace(0, 10);
114+ main_layout->AddSpace(0, LAYOUT_SPACE.CP(scale));
115 main_layout->AddLayout(prompt_layout);
116- main_layout->AddSpace(0, 10);
117+ main_layout->AddSpace(0, LAYOUT_SPACE.CP(scale));
118 }
119
120 void Shield::ShowSecondaryView()
121@@ -159,14 +170,13 @@
122
123 UserPromptView* Shield::CreatePromptView()
124 {
125- auto* prompt_view = new UserPromptView(session_manager_);
126-
127- auto width = 8 * Settings::GRID_SIZE;
128- auto height = 3 * Settings::GRID_SIZE;
129-
130- prompt_view->SetMinimumWidth(width);
131- prompt_view->SetMaximumWidth(width);
132- prompt_view->SetMinimumHeight(height);
133+ double scale = unity::Settings::Instance().em(monitor)->DPIScale();
134+ auto* prompt_view = new UserPromptView(session_manager_, scale);
135+
136+ auto width = PROMPT_WIDTH.CP(scale) * Settings::GRID_SIZE;
137+ auto height = PROMPT_HEIGHT.CP(scale) * Settings::GRID_SIZE;
138+
139+ prompt_view->SetMinMaxSize(width, height);
140
141 return prompt_view;
142 }
143
144=== modified file 'lockscreen/LockScreenShield.h'
145--- lockscreen/LockScreenShield.h 2014-03-07 19:17:35 +0000
146+++ lockscreen/LockScreenShield.h 2014-03-13 21:04:54 +0000
147@@ -64,4 +64,4 @@
148 }
149 }
150
151-#endif
152\ No newline at end of file
153+#endif
154
155=== modified file 'lockscreen/UserPromptView.cpp'
156--- lockscreen/UserPromptView.cpp 2014-03-06 21:37:45 +0000
157+++ lockscreen/UserPromptView.cpp 2014-03-13 21:04:54 +0000
158@@ -34,15 +34,16 @@
159 {
160 namespace
161 {
162-const RawPixel PADDING = 10_em;
163-const RawPixel LAYOUT_MARGIN = 10_em;
164-const RawPixel MSG_LAYOUT_MARGIN = 15_em;
165-const RawPixel PROMPT_LAYOUT_MARGIN = 5_em;
166-const int PROMPT_FONT_SIZE = 13;
167+const RawPixel PADDING = 10_em;
168+const RawPixel LAYOUT_MARGIN = 10_em;
169+const RawPixel MSG_LAYOUT_MARGIN = 15_em;
170+const RawPixel PROMPT_LAYOUT_MARGIN = 5_em;
171+const RawPixel PROMPT_FONT_SIZE = 13_em;
172
173-nux::AbstractPaintLayer* CrateBackgroundLayer(int width, int height)
174+nux::AbstractPaintLayer* CreateBackgroundLayer(int width, int height, double scale)
175 {
176 nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height);
177+ cairo_surface_set_device_scale(cg.GetSurface(), scale, scale);
178 cairo_t* cr = cg.GetInternalContext();
179
180 cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 0.4);
181@@ -51,7 +52,7 @@
182 1.0,
183 0, 0,
184 Settings::GRID_SIZE * 0.3,
185- width, height);
186+ width / scale, height / scale);
187
188 cairo_fill_preserve(cr);
189
190@@ -95,9 +96,10 @@
191
192 }
193
194-UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)
195+UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager, double scale)
196 : nux::View(NUX_TRACKER_LOCATION)
197 , session_manager_(session_manager)
198+ , scale_(scale)
199 {
200 user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
201 AddPrompt(message, /* visible */ true, promise);
202@@ -131,24 +133,25 @@
203
204 SetLayout(new nux::VLayout());
205
206- GetLayout()->SetLeftAndRightPadding(PADDING);
207- GetLayout()->SetTopAndBottomPadding(PADDING);
208- static_cast<nux::VLayout*>(GetLayout())->SetVerticalInternalMargin(LAYOUT_MARGIN);
209+ GetLayout()->SetLeftAndRightPadding(PADDING.CP(scale_));
210+ GetLayout()->SetTopAndBottomPadding(PADDING.CP(scale_));
211+ static_cast<nux::VLayout*>(GetLayout())->SetVerticalInternalMargin(LAYOUT_MARGIN.CP(scale_));
212
213 auto const& real_name = session_manager_->RealName();
214 auto const& name = (real_name.empty() ? session_manager_->UserName() : real_name);
215
216 unity::StaticCairoText* username = new unity::StaticCairoText(name);
217+ username->SetScale(scale_);
218 username->SetFont("Ubuntu "+std::to_string(PROMPT_FONT_SIZE));
219 GetLayout()->AddView(username);
220
221 msg_layout_ = new nux::VLayout();
222- msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN);
223+ msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale_));
224 msg_layout_->SetReconfigureParentLayoutOnGeometryChange(true);
225 GetLayout()->AddLayout(msg_layout_);
226
227 prompt_layout_ = new nux::VLayout();
228- prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN);
229+ prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale_));
230 prompt_layout_->SetReconfigureParentLayoutOnGeometryChange(true);
231 GetLayout()->AddLayout(prompt_layout_);
232
233@@ -180,7 +183,7 @@
234 graphics_engine.PushClippingRectangle(geo);
235 nux::GetPainter().PaintBackground(graphics_engine, geo);
236
237- bg_layer_.reset(CrateBackgroundLayer(geo.width, geo.height));
238+ bg_layer_.reset(CreateBackgroundLayer(geo.width, geo.height, scale_));
239 nux::GetPainter().PushDrawLayer(graphics_engine, geo, bg_layer_.get());
240
241 nux::GetPainter().PopBackground();
242@@ -194,7 +197,7 @@
243
244 if (!IsFullRedraw())
245 {
246- bg_layer_.reset(CrateBackgroundLayer(geo.width, geo.height));
247+ bg_layer_.reset(CreateBackgroundLayer(geo.width, geo.height, scale_));
248 nux::GetPainter().PushLayer(graphics_engine, geo, bg_layer_.get());
249 }
250
251@@ -225,13 +228,14 @@
252 auto* text_entry = text_input->text_entry();
253
254 text_input->input_hint = SanitizeMessage(message);
255- text_input->hint_font_size = PROMPT_FONT_SIZE;
256+ text_input->hint_font_size = PROMPT_FONT_SIZE.CP(scale_);
257+ text_entry->SetFontSize(PROMPT_FONT_SIZE.CP(scale_));
258 text_entry->SetPasswordMode(!visible);
259 text_entry->SetPasswordChar("•");
260 text_entry->SetToggleCursorVisibilityOnKeyFocus(true);
261
262- text_input->SetMinimumHeight(Settings::GRID_SIZE);
263- text_input->SetMaximumHeight(Settings::GRID_SIZE);
264+ text_input->SetMinimumHeight(Settings::GRID_SIZE * scale_);
265+ text_input->SetMaximumHeight(Settings::GRID_SIZE * scale_);
266 prompt_layout_->AddView(text_input, 1);
267 focus_queue_.push_back(text_entry);
268
269@@ -266,6 +270,7 @@
270 void UserPromptView::AddMessage(std::string const& message, nux::Color const& color)
271 {
272 auto* view = new unity::StaticCairoText("");
273+ view->SetScale(scale_);
274 view->SetFont(Settings::Instance().font_name());
275 view->SetTextColor(color);
276 view->SetText(message);
277
278=== modified file 'lockscreen/UserPromptView.h'
279--- lockscreen/UserPromptView.h 2014-03-05 04:09:13 +0000
280+++ lockscreen/UserPromptView.h 2014-03-13 21:04:54 +0000
281@@ -48,7 +48,7 @@
282 class UserPromptView : public nux::View
283 {
284 public:
285- UserPromptView(session::Manager::Ptr const& session_manager);
286+ UserPromptView(session::Manager::Ptr const& session_manager, double scale);
287 ~UserPromptView() {};
288
289 nux::View* focus_view();
290@@ -73,6 +73,7 @@
291 StaticCairoText* error_;
292 StaticCairoText* invalid_login_;
293 std::deque<IMTextEntry*> focus_queue_;
294+ double scale_;
295 };
296
297 }