-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux_hdpi.patch
More file actions
1330 lines (1223 loc) · 41 KB
/
linux_hdpi.patch
File metadata and controls
1330 lines (1223 loc) · 41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 42ab12832efe026ebedce7653d1300bbff4a8393 Mon Sep 17 00:00:00 2001
From: Mel McCalla <melmccalla@gmail.com>
Date: Mon, 7 Jan 2019 21:48:50 -0800
Subject: [PATCH 1/1] Added high dpi support for Linux platforms
---
include/cinder/app/Window.h | 32 ++---
include/cinder/app/linux/AppImplLinux.h | 5 +-
include/cinder/app/linux/WindowImplLinux.h | 1 +
include/glload/_int_glx_type.h | 3 +-
include/glload/_int_glx_type.hpp | 3 +-
src/cinder/app/Window.cpp | 56 +++++----
src/cinder/app/linux/AppImplLinuxGlfw.cpp | 54 ++++----
src/cinder/app/linux/PlatformLinux.cpp | 125 +++++++++++++------
src/cinder/app/linux/WindowImplLinuxGlfw.cpp | 28 +++--
src/cinder/app/linux/WindowImplLinuxRpi.cpp | 4 +
src/cinder/params/Params.cpp | 91 ++++++++------
11 files changed, 243 insertions(+), 159 deletions(-)
diff --git a/include/cinder/app/Window.h b/include/cinder/app/Window.h
index bd4b1503c..dbba19b93 100644
--- a/include/cinder/app/Window.h
+++ b/include/cinder/app/Window.h
@@ -305,7 +305,7 @@ class CI_API Window : public std::enable_shared_from_this<Window> {
//! Returns a vec2 mapped from points to pixels by multiplying by getContentScale()
vec2 toPixels( vec2 s ) const { return s * getContentScale(); }
//! Returns a ivec2 mapped from points to pixels by multiplying by getContentScale()
- ivec2 toPixels( ivec2 s ) const { return ivec2( (int32_t)(s.x * getContentScale()), (int32_t)(s.y * getContentScale()) ); }
+ ivec2 toPixels( ivec2 s ) const { return ivec2( (int32_t)(s.x * getContentScale()), (int32_t)(s.y * getContentScale()) ); }
//! Returns an Area mapped from points to pixels by multiplying by getContentScale()
Area toPixels( const Area &a ) const { const float s = getContentScale(); return Area( (int32_t)(a.x1 * s), (int32_t)(a.y1 * s), (int32_t)(a.x2 * s), (int32_t)(a.y2 * s) ); }
//! Returns a Rectf mapped from points to pixels by multiplying by getContentScale()
@@ -317,17 +317,17 @@ class CI_API Window : public std::enable_shared_from_this<Window> {
//! Returns a vec2 mapped from pixels to points by dividing by getContentScale()
vec2 toPoints( vec2 s ) const { return s / getContentScale(); }
//! Returns a ivec2 mapped from pixels to points by dividing by getContentScale()
- ivec2 toPoints( ivec2 s ) const { return ivec2( (int32_t)(s.x / getContentScale()), (int32_t)(s.y / getContentScale()) ); }
+ ivec2 toPoints( ivec2 s ) const { return ivec2( (int32_t)(s.x / getContentScale()), (int32_t)(s.y / getContentScale()) ); }
//! Returns an Area mapped from pixels to points by dividing by getContentScale()
Area toPoints( const Area &a ) const { const float s = 1.0f / getContentScale(); return Area( (int32_t)(a.x1 * s), (int32_t)(a.y1 * s), (int32_t)(a.x2 * s), (int32_t)(a.y2 * s) ); }
//! Returns a Rectf mapped from pixels to points by dividing by getContentScale()
Rectf toPoints( const Rectf &a ) const { return a / getContentScale(); }
-
+
//! Returns the Window's title as a UTF-8 string.
std::string getTitle() const;
//! Sets the Window's title as a UTF-8 string.
void setTitle( const std::string &title );
-
+
//! Returns whether the window has a border (chrome/frame)
bool isBorderless() const;
//! Sets whether the window has a border (chrome/frame)
@@ -427,11 +427,11 @@ class CI_API Window : public std::enable_shared_from_this<Window> {
//! Sets the window-specific data associated with this Window. The variable is \c deleted upon destruction of the Window.
template<typename T>
void setUserData( T *userData ) { mUserData = std::shared_ptr<void>( std::shared_ptr<T>( userData ) ); }
-
+
//! Returns whether this Window is valid. \c false means it should no longer be used (neither read nor write)
bool isValid() const { return mValid; }
void setInvalid() { mValid = false; }
-
+
//! \cond
// This should not be called except by App implementations
#if defined( CINDER_COCOA ) && defined( __OBJC__ )
@@ -451,22 +451,22 @@ class CI_API Window : public std::enable_shared_from_this<Window> {
WindowRef result( new Window );
result->setImpl( impl );
result->setApp( app );
-
+
return result;
}
//! \endcond
AppBase* getApp() const { return mApp; }
-
+
protected:
Window() : mValid( true ), mImpl( 0 ) {}
-
+
void testValid() const {
if( ! mValid )
throw ExcInvalidWindow();
}
- void setApp( AppBase *app ) { mApp = app; }
+ void setApp( AppBase *app ) { mApp = app; }
#if defined( CINDER_COCOA )
#if defined( __OBJC__ )
@@ -479,21 +479,21 @@ class CI_API Window : public std::enable_shared_from_this<Window> {
#elif defined( CINDER_UWP )
void setImpl( WindowImplWinRt *impl ) { mImpl = impl; }
#elif defined( CINDER_ANDROID )
- void setImpl( WindowImplAndroid *impl ) { mImpl = impl; }
+ void setImpl( WindowImplAndroid *impl ) { mImpl = impl; }
#elif defined( CINDER_LINUX )
- void setImpl( WindowImplLinux *impl ) { mImpl = impl; }
+ void setImpl( WindowImplLinux *impl ) { mImpl = impl; }
#endif
AppBase *mApp;
bool mValid;
std::shared_ptr<void> mUserData;
-
+
EventSignalMouse mSignalMouseDown, mSignalMouseDrag, mSignalMouseUp, mSignalMouseWheel, mSignalMouseMove;
EventSignalTouch mSignalTouchesBegan, mSignalTouchesMoved, mSignalTouchesEnded;
EventSignalKey mSignalKeyDown, mSignalKeyUp;
EventSignalWindow mSignalDraw, mSignalPostDraw, mSignalMove, mSignalResize, mSignalDisplayChange, mSignalClose;
EventSignalFileDrop mSignalFileDrop;
-
+
#if defined( CINDER_COCOA )
#if defined( __OBJC__ )
id<WindowImplCocoa> mImpl;
@@ -509,7 +509,7 @@ class CI_API Window : public std::enable_shared_from_this<Window> {
#elif defined( CINDER_LINUX )
WindowImplLinux *mImpl;
#endif
-
+
private:
#if defined( CINDER_ANDROID )
friend class AppImplAndroid;
@@ -517,7 +517,7 @@ private:
#elif defined( CINDER_LINUX )
friend class AppImplLinux;
WindowImplLinux *getImpl() { return mImpl; }
-#endif
+#endif
};
} } // namespace cinder::app
diff --git a/include/cinder/app/linux/AppImplLinux.h b/include/cinder/app/linux/AppImplLinux.h
index 8ccecaa61..457fe5428 100644
--- a/include/cinder/app/linux/AppImplLinux.h
+++ b/include/cinder/app/linux/AppImplLinux.h
@@ -53,7 +53,7 @@ class AppImplLinux {
void setFrameRate( float aFrameRate );
void disableFrameRate();
bool isFrameRateEnabled() const;
-
+ bool getHighDensityDisplayEnabled() const;
WindowRef getWindow() const;
void setWindow( WindowRef window );
@@ -84,6 +84,9 @@ private:
float mFrameRate;
bool mFrameRateEnabled;
+
+ bool mHighDensityDisplayEnabled;
+
bool mShouldQuit = false;
bool mSetupHasBeenCalled = false;
diff --git a/include/cinder/app/linux/WindowImplLinux.h b/include/cinder/app/linux/WindowImplLinux.h
index 9f82180d2..7c743c330 100644
--- a/include/cinder/app/linux/WindowImplLinux.h
+++ b/include/cinder/app/linux/WindowImplLinux.h
@@ -50,6 +50,7 @@ public:
virtual void setSize( const ivec2 &size );
virtual ivec2 getPos() const;
virtual void setPos( const ivec2 &pos );
+ virtual float getContentScale() const;
virtual void close();
virtual std::string getTitle() const { return mTitle; }
virtual void setTitle( const std::string &title );
diff --git a/include/glload/_int_glx_type.h b/include/glload/_int_glx_type.h
index 9e0e14a4e..6025874f4 100644
--- a/include/glload/_int_glx_type.h
+++ b/include/glload/_int_glx_type.h
@@ -1,10 +1,11 @@
#ifndef GLXWIN_GEN_TYPE_H
#define GLXWIN_GEN_TYPE_H
-#ifdef __glxext_h_
+#if defined( __glxext_h_) || defined(__glx_glxext_h_)
#error Attempt to include glx_exts after including glxext.h
#endif
#define __glxext_h_
+#define __glx_glxext_h_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
diff --git a/include/glload/_int_glx_type.hpp b/include/glload/_int_glx_type.hpp
index 5e3b46649..1794bdb77 100644
--- a/include/glload/_int_glx_type.hpp
+++ b/include/glload/_int_glx_type.hpp
@@ -1,10 +1,11 @@
#ifndef GLXWIN_GEN_TYPE_HPP
#define GLXWIN_GEN_TYPE_HPP
-#ifdef __glxext_h_
+#if defined( __glxext_h_) || defined(__glx_glxext_h_)
#error Attempt to include glx_exts after including glxext.h
#endif
#define __glxext_h_
+#define __glx_glxext_h_
#include <X11/Xlib.h>
#include <X11/Xutil.h>
diff --git a/src/cinder/app/Window.cpp b/src/cinder/app/Window.cpp
index 26ca4e450..2bd750208 100644
--- a/src/cinder/app/Window.cpp
+++ b/src/cinder/app/Window.cpp
@@ -43,7 +43,7 @@ namespace cinder { namespace app {
bool Window::isFullScreen() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl isFullScreen];
#else
@@ -54,7 +54,7 @@ bool Window::isFullScreen() const
void Window::setFullScreen( bool fullScreen, const FullScreenOptions &options )
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl setFullScreen:fullScreen options:&options];
#else
@@ -65,7 +65,7 @@ void Window::setFullScreen( bool fullScreen, const FullScreenOptions &options )
ivec2 Window::getSize() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl getSize];
#else
@@ -76,7 +76,7 @@ ivec2 Window::getSize() const
void Window::setSize( const ivec2 &size )
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl setSize:size];
#else
@@ -87,7 +87,7 @@ void Window::setSize( const ivec2 &size )
ivec2 Window::getPos() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl getPos];
#else
@@ -98,7 +98,7 @@ ivec2 Window::getPos() const
void Window::setPos( const ivec2 &pos ) const
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl setPos:pos];
#else
@@ -109,8 +109,8 @@ void Window::setPos( const ivec2 &pos ) const
void Window::spanAllDisplays()
{
Area spanning = Display::getSpanningArea();
-
- setSize( ivec2( spanning.getWidth(), spanning.getHeight() ) );
+
+ setSize( ivec2( spanning.getWidth(), spanning.getHeight() ) );
setPos( spanning.getUL() );
}
@@ -122,11 +122,13 @@ ivec2 Window::getMousePos() const
float Window::getContentScale() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl getContentScale];
#elif defined( CINDER_MSW_DESKTOP )
return mImpl->getContentScale();
+#elif defined( CINDER_LINUX )
+ return mImpl->getContentScale();
#else
return 1.0f;
#endif
@@ -135,7 +137,7 @@ float Window::getContentScale() const
void Window::close()
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl close];
#else
@@ -146,7 +148,7 @@ void Window::close()
std::string Window::getTitle() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
NSString *title = [mImpl getTitle];
return title ? std::string( [title cStringUsingEncoding:NSUTF8StringEncoding] ) : std::string();
@@ -158,7 +160,7 @@ std::string Window::getTitle() const
void Window::setTitle( const std::string &title )
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl setTitle:[NSString stringWithUTF8String:title.c_str()]];
#else
@@ -169,7 +171,7 @@ void Window::setTitle( const std::string &title )
bool Window::isBorderless() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl isBorderless];
#else
@@ -180,7 +182,7 @@ bool Window::isBorderless() const
void Window::setBorderless( bool borderless )
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl setBorderless:borderless];
#else
@@ -191,7 +193,7 @@ void Window::setBorderless( bool borderless )
bool Window::isAlwaysOnTop() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl isAlwaysOnTop];
#else
@@ -202,7 +204,7 @@ bool Window::isAlwaysOnTop() const
void Window::setAlwaysOnTop( bool alwaysOnTop )
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl setAlwaysOnTop:alwaysOnTop];
#else
@@ -213,7 +215,7 @@ void Window::setAlwaysOnTop( bool alwaysOnTop )
void Window::hide()
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl hide];
#else
@@ -224,7 +226,7 @@ void Window::hide()
void Window::show()
{
testValid();
-
+
#if defined( CINDER_COCOA )
[mImpl show];
#else
@@ -235,12 +237,12 @@ void Window::show()
bool Window::isHidden() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl isHidden];
#else
return mImpl->isHidden();
-#endif
+#endif
}
DisplayRef Window::getDisplay() const
@@ -251,13 +253,13 @@ DisplayRef Window::getDisplay() const
return [mImpl getDisplay];
#else
return mImpl->getDisplay();
-#endif
+#endif
}
RendererRef Window::getRenderer() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl getRenderer];
#else
@@ -396,7 +398,7 @@ void Window::emitTouchesEnded( TouchEvent *event )
const std::vector<TouchEvent::Touch>& Window::getActiveTouches() const
{
testValid();
-
+
#if defined( CINDER_COCOA )
return [mImpl getActiveTouches];
#elif defined( CINDER_MSW_DESKTOP )
@@ -404,9 +406,9 @@ const std::vector<TouchEvent::Touch>& Window::getActiveTouches() const
#elif defined( CINDER_UWP )
return mImpl->getActiveTouches();
#elif defined( CINDER_ANDROID )
- return mImpl->getActiveTouches();
+ return mImpl->getActiveTouches();
#elif defined( CINDER_LINUX )
- return mImpl->getActiveTouches();
+ return mImpl->getActiveTouches();
#endif
}
@@ -437,8 +439,8 @@ void Window::emitDraw()
getRenderer()->makeCurrentContext( true );
#else
getRenderer()->makeCurrentContext( false );
-#endif
-
+#endif
+
mSignalDraw.emit();
getApp()->draw();
mSignalPostDraw.emit();
diff --git a/src/cinder/app/linux/AppImplLinuxGlfw.cpp b/src/cinder/app/linux/AppImplLinuxGlfw.cpp
index 9996720c5..970e804b9 100644
--- a/src/cinder/app/linux/AppImplLinuxGlfw.cpp
+++ b/src/cinder/app/linux/AppImplLinuxGlfw.cpp
@@ -33,10 +33,10 @@ namespace cinder { namespace app {
class GlfwCallbacks {
public:
-
+
static std::map<GLFWwindow*, std::pair<AppImplLinux*,WindowRef>> sWindowMapping;
static bool sCapsLockDown, sNumLockDown, sScrollLockDown;
-
+
static void registerWindowEvents( GLFWwindow *glfwWindow, AppImplLinux* cinderAppImpl, const WindowRef& cinderWindow ) {
sWindowMapping[glfwWindow] = std::make_pair( cinderAppImpl, cinderWindow );
@@ -187,7 +187,7 @@ public:
int32_t nativeKeyCode = KeyEvent::translateNativeKeyCode( key );
uint32_t char32 = 0;
-
+
if( glfwGetKey( glfwWindow, GLFW_KEY_CAPS_LOCK ) )
sCapsLockDown = ! sCapsLockDown;
if( glfwGetKey( glfwWindow, GLFW_KEY_NUM_LOCK ) )
@@ -204,7 +204,7 @@ public:
}
else if( GLFW_RELEASE == action ) {
cinderWindow->emitKeyUp( &event );
- }
+ }
}
}
@@ -248,10 +248,10 @@ public:
if( 0 != initiator ) {
MouseEvent event( getWindow(), initiator, (int)mouseX, (int)mouseY, modifiers, 0.0f, 0 );
if( GLFW_PRESS == action ) {
- cinderWindow->emitMouseDown( &event );
+ cinderWindow->emitMouseDown( &event );
}
else if( GLFW_RELEASE == action ) {
- cinderWindow->emitMouseUp( &event );
+ cinderWindow->emitMouseUp( &event );
}
}
}
@@ -271,7 +271,7 @@ public:
float wheelDelta = xoffset + yoffset;
MouseEvent event( getWindow(), 0, (int)mouseX, (int)mouseY, modifiers, wheelDelta , 0 );
- cinderWindow->emitMouseWheel( &event );
+ cinderWindow->emitMouseWheel( &event );
}
}
@@ -310,8 +310,11 @@ AppImplLinux::AppImplLinux( AppLinux *aApp, const AppLinux::Settings &settings )
mFrameRate = settings.getFrameRate();
mFrameRateEnabled = settings.isFrameRateEnabled();
+
+ mHighDensityDisplayEnabled = settings.isHighDensityDisplayEnabled();
+
mQuitOnLastWindowClosed = settings.isQuitOnLastWindowCloseEnabled();
-
+
auto formats = settings.getWindowFormats();
if( formats.empty() ) {
formats.push_back( settings.getDefaultWindowFormat() );
@@ -385,14 +388,14 @@ void AppImplLinux::run()
// issue initial app activation event
mApp->emitDidBecomeActive();
-
+
// isse initial resize revent
for( auto &window : mWindows ) {
window->resize();
}
// initialize our next frame time
- mNextFrameTime = getElapsedSeconds();
+ mNextFrameTime = getElapsedSeconds();
while( ! mShouldQuit ) {
// update and draw
@@ -406,7 +409,7 @@ void AppImplLinux::run()
glfwPollEvents();
// Sleep until the next frame
- sleepUntilNextFrame();
+ sleepUntilNextFrame();
// Check if a window should be closed / destroyed or if we should exit.
auto shouldCloseWindow = [ this ] ( WindowImplLinux* window ) {
@@ -467,14 +470,14 @@ WindowRef AppImplLinux::createWindow( Window::Format format )
void AppImplLinux::quit()
{
for( auto &window : mWindows ) {
- ::glfwSetWindowShouldClose( window->getNative(), true );
+ ::glfwSetWindowShouldClose( window->getNative(), true );
}
mShouldQuit = true;
}
-float AppImplLinux::getFrameRate() const
-{
- return mFrameRate;
+float AppImplLinux::getFrameRate() const
+{
+ return mFrameRate;
}
void AppImplLinux::setFrameRate( float frameRate )
@@ -494,14 +497,19 @@ bool AppImplLinux::isFrameRateEnabled() const
return mFrameRateEnabled;
}
-WindowRef AppImplLinux::getWindow() const
-{
- return mActiveWindow;
+bool AppImplLinux::getHighDensityDisplayEnabled() const
+{
+ return mHighDensityDisplayEnabled;
}
-void AppImplLinux::setWindow( WindowRef window )
-{
- mActiveWindow = window;
+WindowRef AppImplLinux::getWindow() const
+{
+ return mActiveWindow;
+}
+
+void AppImplLinux::setWindow( WindowRef window )
+{
+ mActiveWindow = window;
}
size_t AppImplLinux::getNumWindows() const
@@ -514,7 +522,7 @@ WindowRef AppImplLinux::getWindowIndex( size_t index ) const
if( index >= mWindows.size() ) {
return cinder::app::WindowRef();
}
-
+
auto winIt = mWindows.begin();
std::advance( winIt, index );
return (*winIt)->mWindowRef;
@@ -542,7 +550,7 @@ void AppImplLinux::showCursor()
ivec2 AppImplLinux::getMousePos() const
{
- return mActiveWindow->getImpl()->getMousePos();
+ return mActiveWindow->getImpl()->getMousePos();
}
void AppImplLinux::registerWindowEvents( WindowImplLinux* window )
diff --git a/src/cinder/app/linux/PlatformLinux.cpp b/src/cinder/app/linux/PlatformLinux.cpp
index 718b98089..39b3bd758 100644
--- a/src/cinder/app/linux/PlatformLinux.cpp
+++ b/src/cinder/app/linux/PlatformLinux.cpp
@@ -38,6 +38,16 @@
#include <pwd.h>
#include <pthread.h>
+#include <string>
+#include <sstream>
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/Xresource.h>
+
+#define NORMAL_DPI 96.0f
+
+
namespace cinder {
extern void FontManager_destroyStaticInstance();
@@ -65,9 +75,9 @@ PlatformLinux::~PlatformLinux()
{
}
-PlatformLinux* PlatformLinux::get()
-{
- return reinterpret_cast<PlatformLinux*>( Platform::get() );
+PlatformLinux* PlatformLinux::get()
+{
+ return reinterpret_cast<PlatformLinux*>( Platform::get() );
}
void PlatformLinux::cleanupLaunch()
@@ -75,19 +85,19 @@ void PlatformLinux::cleanupLaunch()
cinder::FontManager_destroyStaticInstance();
}
-DataSourceRef PlatformLinux::loadResource( const fs::path &resourcePath )
+DataSourceRef PlatformLinux::loadResource( const fs::path &resourcePath )
{
fs::path fullPath = getResourcePath( resourcePath );
if( fullPath.empty() )
throw ResourceLoadExc( std::string( "Could not resolve absolute path for: " ) + resourcePath.string() );
else
- return DataSourcePath::create( fullPath );
+ return DataSourcePath::create( fullPath );
}
-fs::path PlatformLinux::getResourceDirectory() const
+fs::path PlatformLinux::getResourceDirectory() const
{
// @TODO: Implement
- return fs::path();
+ return fs::path();
}
fs::path PlatformLinux::getResourcePath( const fs::path &rsrcRelativePath ) const
@@ -126,7 +136,7 @@ fs::path PlatformLinux::getResourcePath( const fs::path &rsrcRelativePath ) cons
return fullPath;
}
- return fs::path(); // empty implies failure
+ return fs::path(); // empty implies failure
}
struct DialogHelper {
@@ -166,7 +176,7 @@ struct DialogHelper {
ss << " ";
}
}
-
+
std::string cmd = ss.str();
if( ! cmd.empty() ) {
FILE* pipe = popen( cmd.c_str(), "r" );
@@ -190,7 +200,7 @@ struct DialogHelper {
result = value;
}
}
- pclose(pipe);
+ pclose(pipe);
}
return result;
@@ -324,22 +334,22 @@ struct DialogHelper {
};
-fs::path PlatformLinux::getOpenFilePath( const fs::path &initialPath, const std::vector<std::string> &extensions )
+fs::path PlatformLinux::getOpenFilePath( const fs::path &initialPath, const std::vector<std::string> &extensions )
{
return DialogHelper::getOpenFilePath( initialPath, extensions );
}
-fs::path PlatformLinux::getFolderPath( const fs::path &initialPath )
+fs::path PlatformLinux::getFolderPath( const fs::path &initialPath )
{
return DialogHelper::getFolderPath( initialPath );
}
-fs::path PlatformLinux::getSaveFilePath( const fs::path &initialPath, const std::vector<std::string> &extensions )
+fs::path PlatformLinux::getSaveFilePath( const fs::path &initialPath, const std::vector<std::string> &extensions )
{
return DialogHelper::getSaveFilePath( initialPath, extensions );
}
-std::map<std::string, std::string> PlatformLinux::getEnvironmentVariables()
+std::map<std::string, std::string> PlatformLinux::getEnvironmentVariables()
{
std::map<std::string, std::string> result;
@@ -356,21 +366,21 @@ std::map<std::string, std::string> PlatformLinux::getEnvironmentVariables()
return result;
}
-fs::path PlatformLinux::expandPath( const fs::path &path )
+fs::path PlatformLinux::expandPath( const fs::path &path )
{
fs::path filename = path.filename();
char actualPath[PATH_MAX];
- if( ::realpath( path.parent_path().c_str(), actualPath ) ) {
+ if( ::realpath( path.parent_path().c_str(), actualPath ) ) {
fs::path expandedPath = fs::path( std::string( actualPath ) );
expandedPath /= filename;
- return expandedPath;
- }
+ return expandedPath;
+ }
- return fs::path();
+ return fs::path();
}
-fs::path PlatformLinux::getHomeDirectory() const
+fs::path PlatformLinux::getHomeDirectory() const
{
fs::path result;
@@ -406,7 +416,7 @@ fs::path PlatformLinux::getHomeDirectory() const
return result;
}
-fs::path PlatformLinux::getDocumentsDirectory() const
+fs::path PlatformLinux::getDocumentsDirectory() const
{
fs::path result;
@@ -421,7 +431,7 @@ fs::path PlatformLinux::getDocumentsDirectory() const
return result;
}
-fs::path PlatformLinux::getDefaultExecutablePath() const
+fs::path PlatformLinux::getDefaultExecutablePath() const
{
std::vector<char> buf( PATH_MAX );
std::memset( &(buf[0]), 0, buf.size() );
@@ -432,13 +442,13 @@ fs::path PlatformLinux::getDefaultExecutablePath() const
return fs::path( std::string( &(buf[0]), len ) ).parent_path();
}
-void PlatformLinux::sleep( float milliseconds )
+void PlatformLinux::sleep( float milliseconds )
{
unsigned long sleepMicroSecs = milliseconds*1000L;
- usleep( sleepMicroSecs );
+ usleep( sleepMicroSecs );
}
-void PlatformLinux::launchWebBrowser( const Url &url )
+void PlatformLinux::launchWebBrowser( const Url &url )
{
pid_t pid = fork();
@@ -457,10 +467,10 @@ void PlatformLinux::launchWebBrowser( const Url &url )
}
}
-std::vector<std::string> PlatformLinux::stackTrace()
+std::vector<std::string> PlatformLinux::stackTrace()
{
// @TODO: Implement
- return std::vector<std::string>();
+ return std::vector<std::string>();
}
void PlatformLinux::setThreadName( const std::string &name )
@@ -484,7 +494,7 @@ void PlatformLinux::removeDisplay( const DisplayRef &display )
{
DisplayRef displayCopy = display;
mDisplays.erase( std::remove( mDisplays.begin(), mDisplays.end(), displayCopy ), mDisplays.end() );
-
+
if( app::AppBase::get() )
app::AppBase::get()->emitDisplayDisconnected( displayCopy );
}
@@ -518,6 +528,45 @@ DisplayRef PlatformLinux::findDisplayFromGlfwMonitor( GLFWmonitor *monitor )
#endif
}
+float getDisplayScale() {
+ _XDisplay* display = XOpenDisplay(NULL);
+
+ char *resourceString = XResourceManagerString(display);
+
+ XCloseDisplay(display);
+
+ if (resourceString == NULL) {
+ return 1.0;
+ }
+
+ XrmInitialize(); /* Need to initialize the DB before calling Xrm* functions */
+ XrmDatabase db = XrmGetStringDatabase(resourceString);
+
+ std::istringstream iss(resourceString);
+
+// CI_LOG_V("Entire DB:");
+// for (std::string line; std::getline(iss, line); ){
+// CI_LOG_V(" " + line);
+// }
+
+ XrmValue value;
+ char* type = NULL;
+ if (!XrmGetResource(db, "Xft.dpi", "String", &type, &value)) {
+ return 1.0;
+ }
+ if (!value.addr) {
+ return 1.0;
+ }
+
+ float dpi = atof(value.addr);
+// CI_LOG_D("DPI:\t" + std::to_string(dpi));
+
+ float scale = dpi / NORMAL_DPI;
+// CI_LOG_D("Scale:\t" + std::to_string(scale));
+ return scale;
+}
+
+
#if ! defined( CINDER_LINUX_EGL_ONLY ) && ! defined( CINDER_HEADLESS )
void DisplayLinux::displayReconfiguredCallback( GLFWmonitor* monitor, int event )
{
@@ -527,7 +576,7 @@ void DisplayLinux::displayReconfiguredCallback( GLFWmonitor* monitor, int event
if( display )
platform->removeDisplay( display ); // this will signal
else
- CI_LOG_W( "Received removed from displayReconfiguredCallback() on unknown display" );
+ CI_LOG_W( "Received removed from displayReconfiguredCallback() on unknown display" );
}
else if( event == GLFW_CONNECTED ) {
auto display = platform->findDisplayFromGlfwMonitor( monitor );
@@ -539,18 +588,20 @@ void DisplayLinux::displayReconfiguredCallback( GLFWmonitor* monitor, int event
ivec2 pos;
glfwGetMonitorPos(monitor, &pos.x, &pos.y);
- newDisplay->mArea = Area( pos.x, pos.y,
+ newDisplay->mArea = Area( pos.x, pos.y,
pos.x + size.x, pos.y + size.y );
newDisplay->mBitsPerPixel = videoMode->redBits + videoMode->greenBits + videoMode->blueBits;
// TODO: figure out content scaling.
//const double dpi = mode->width / (widthMM / 25.4);
- newDisplay->mContentScale = 1.0;
+
+ newDisplay->mContentScale = getDisplayScale();
+
platform->addDisplay( DisplayRef( newDisplay ) ); // this will signal
}
else
- CI_LOG_W( "Received add from displayReconfiguredCallback() for already known display" );
+ CI_LOG_W( "Received add from displayReconfiguredCallback() for already known display" );
}
}
@@ -558,7 +609,7 @@ const std::vector<DisplayRef>& app::PlatformLinux::getDisplays()
{
auto glfwInitialized = ::glfwInit();
if( ! mDisplaysInitialized && glfwInitialized ) {
- // this is our first call; register a callback with CoreGraphics for any
+ // this is our first call; register a callback with CoreGraphics for any
// display changes. Note that this only works with a run loop
::glfwSetMonitorCallback( DisplayLinux::displayReconfiguredCallback );
int32_t numMonitors, nonPrimaryIndex = 1;
@@ -568,7 +619,7 @@ const std::vector<DisplayRef>& app::PlatformLinux::getDisplays()
for( size_t i = 0; i < numMonitors; ++i ) {
GLFWmonitor *monitor = monitors[i];
auto newDisplay = std::make_shared<DisplayLinux>();
-
+
const auto *videoMode = ::glfwGetVideoMode( monitor );
auto size = ivec2( videoMode->width, videoMode->height );
ivec2 pos;
@@ -579,7 +630,7 @@ const std::vector<DisplayRef>& app::PlatformLinux::getDisplays()
// TODO: figure out content scaling.
//const double dpi = mode->width / (widthMM / 25.4);
- newDisplay->mContentScale = 1.0f;
+ newDisplay->mContentScale = getDisplayScale();
newDisplay->mMonitor = monitor;
if( mainScreen == monitor )
mDisplays[0] = std::move( newDisplay );
@@ -587,9 +638,9 @@ const std::vector<DisplayRef>& app::PlatformLinux::getDisplays()
mDisplays[nonPrimaryIndex++] = std::move( newDisplay );
}
- mDisplaysInitialized = true;
+ mDisplaysInitialized = true;
}
-
+
return mDisplays;
}
#else // EGL
diff --git a/src/cinder/app/linux/WindowImplLinuxGlfw.cpp b/src/cinder/app/linux/WindowImplLinuxGlfw.cpp
index 269aa85ab..d7fb70f7c 100644
--- a/src/cinder/app/linux/WindowImplLinuxGlfw.cpp
+++ b/src/cinder/app/linux/WindowImplLinuxGlfw.cpp
@@ -34,7 +34,7 @@ WindowImplLinux::WindowImplLinux( const Window::Format &format, WindowImplLinux
{
mFullScreen = format.isFullScreen();
mDisplay = format.getDisplay();
-
+
if( ! mDisplay )
mDisplay = Display::getMainDisplay();
@@ -51,20 +51,20 @@ WindowImplLinux::WindowImplLinux( const Window::Format &format, WindowImplLinux
::glfwWindowHint( GLFW_CLIENT_API, GLFW_OPENGL_ES_API );
#if CINDER_GL_ES_VERSION >= CINDER_GL_ES_VERSION_3_2
::glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
- ::glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 2 );
- std::cout << "Rendering with OpenGL ES 3.2" << std::endl;
+ ::glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 2 );
+ std::cout << "Rendering with OpenGL ES 3.2" << std::endl;
#elif CINDER_GL_ES_VERSION >= CINDER_GL_ES_VERSION_3_1
::glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
- ::glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 );
- std::cout << "Rendering with OpenGL ES 3.1" << std::endl;
+ ::glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 );
+ std::cout << "Rendering with OpenGL ES 3.1" << std::endl;
#elif CINDER_GL_ES_VERSION >= CINDER_GL_ES_VERSION_3
::glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
::glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 0 );
- std::cout << "Rendering with OpenGL ES 3.0" << std::endl;
+ std::cout << "Rendering with OpenGL ES 3.0" << std::endl;
#elif CINDER_GL_ES_VERSION >= CINDER_GL_ES_VERSION_2
::glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 2 );
::glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 0 );
- std::cout << "Rendering with OpenGL ES 2.0" << std::endl;
+ std::cout << "Rendering with OpenGL ES 2.0" << std::endl;
#endif
#else // Desktop
@@ -77,7 +77,7 @@ WindowImplLinux::WindowImplLinux( const Window::Format &format, WindowImplLinux
std::cout << "Rendering with OpenGL Core Profile " << majorVersion << "." << minorVersion << std::endl;
}
else {
- std::cout << "Rendering with OpenGL " << majorVersion << "." << minorVersion << std::endl;
+ std::cout << "Rendering with OpenGL " << majorVersion << "." << minorVersion << std::endl;
}
if( options.getDebug() )
::glfwWindowHint( GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE );
@@ -139,7 +139,7 @@ ivec2 WindowImplLinux::getSize() const
{
int xsize, ysize;
::glfwGetWindowSize( mGlfwWindow, &xsize, &ysize );
- return ivec2( xsize, ysize );
+ return ivec2( xsize, ysize );
}
void WindowImplLinux::setSize( const ivec2 &size )
@@ -155,10 +155,14 @@ ivec2 WindowImplLinux::getPos() const
}
void WindowImplLinux::setPos( const ivec2 &pos )
-{
+{
::glfwSetWindowPos( mGlfwWindow, pos.x, pos.y );
}
+float WindowImplLinux::getContentScale() const {
+ return ( mAppImpl->getHighDensityDisplayEnabled() ) ? mDisplay->getContentScale() : 1.0f;
+}
+
void WindowImplLinux::close()
{
}
@@ -186,13 +190,13 @@ const std::vector<TouchEvent::Touch>& WindowImplLinux::getActiveTouches() const
void WindowImplLinux::setBorderless( bool borderless )
{
CI_LOG_W( "Window::setBorderless() currently unimplemented in GLFW" );
- // TODO: Find a way to do this w/o recreating
+ // TODO: Find a way to do this w/o recreating
}
void WindowImplLinux::setAlwaysOnTop( bool alwaysOnTop )
{
CI_LOG_W( "Window::setAlwaysOnTop() currently unimplemented in GLFW" );
- // TODO: Find a way to do this w/o recreating
+ // TODO: Find a way to do this w/o recreating
}
void WindowImplLinux::keyDown( const KeyEvent &event )
diff --git a/src/cinder/app/linux/WindowImplLinuxRpi.cpp b/src/cinder/app/linux/WindowImplLinuxRpi.cpp