Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ar_sandbox_lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AR_Sandbox
ar_sandbox_lib
Commits
ede48885
Commit
ede48885
authored
4 years ago
by
simon.fanetti
Browse files
Options
Downloads
Patches
Plain Diff
fixed xrandr with lib instead of parsing output
parent
a1464dff
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/SandboxSetup/SandboxSetup.pro
+4
-1
4 additions, 1 deletion
app/SandboxSetup/SandboxSetup.pro
app/SandboxSetup/monitorgui.cpp
+34
-34
34 additions, 34 deletions
app/SandboxSetup/monitorgui.cpp
app/SandboxSetup/monitorgui.h
+1
-3
1 addition, 3 deletions
app/SandboxSetup/monitorgui.h
with
39 additions
and
38 deletions
app/SandboxSetup/SandboxSetup.pro
+
4
−
1
View file @
ede48885
...
...
@@ -65,7 +65,10 @@ FORMS += \
INCLUDEPATH
+=
..
/../
inc
LIBS
+=
-
L
"../../build"
-
lsandbox
-
lrealsense2
-
lyaml
-
cpp
LIBS
+=
-
L
"../../build"
-
lsandbox
LIBS
+=
-
lrealsense2
LIBS
+=
-
lyaml
-
cpp
LIBS
+=
-
lXrandr
-
lX11
LIBS
+=
$
(
shell
pkg
-
config
--
libs
--
cflags
opencv
)
#
QMAKE_CXXFLAGS
+=
-
fsanitize
=
address
-
fsanitize
=
leak
-
fsanitize
=
undefined
This diff is collapsed.
Click to expand it.
app/SandboxSetup/monitorgui.cpp
+
34
−
34
View file @
ede48885
#include
"monitorgui.h"
#include
"ui_monitorgui.h"
#include
<X11/Xlib.h>
#include
<X11/extensions/Xrandr.h>
MonitorGui
::
MonitorGui
(
SandboxSetup
*
_setup
,
QWidget
*
parent
)
:
SubApp
(
"Monitors"
,
"Cancel resolution"
,
parent
),
...
...
@@ -11,7 +13,7 @@ MonitorGui::MonitorGui(SandboxSetup *_setup, QWidget *parent) :
std
::
string
path
=
".monitors.tmp"
;
monitors
=
std
::
map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
();
initMonitorMap
WithFile
(
path
);
initMonitorMap
(
);
QList
<
QScreen
*>
screens
=
QApplication
::
screens
();
for
(
int
i
=
0
;
i
<
screens
.
size
();
i
++
){
...
...
@@ -80,17 +82,40 @@ void MonitorGui::on_cbxOutputs_currentIndexChanged(int index)
showMonitorsScreenshot
(
sc
);
}
void
MonitorGui
::
initMonitorMap
(){
void
MonitorGui
::
initMonitorMapWithFile
(
std
::
string
path
){
Display
*
dp
=
XOpenDisplay
(
NULL
);
if
(
dp
){
XRRScreenResources
*
screen
=
XRRGetScreenResources
(
dp
,
DefaultRootWindow
(
dp
));
// Save in file the monitors and their resolutions
int
err
=
system
(
(
"xrandr | sed -n '1!p' > "
+
path
).
c_str
()
);
if
(
err
){
std
::
cout
<<
"Couldn't get screens and their resolutions"
<<
std
::
endl
;
exit
(
err
);
// 4 display ports
for
(
int
i
=
0
;
i
<
screen
->
ncrtc
;
i
++
){
XRRCrtcInfo
*
info
=
XRRGetCrtcInfo
(
dp
,
screen
,
screen
->
crtcs
[
i
]);
// 2 display port ON
for
(
int
j
=
0
;
j
<
info
->
noutput
;
j
++
){
XRROutputInfo
*
output
=
XRRGetOutputInfo
(
dp
,
screen
,
info
->
outputs
[
j
]);
if
(
output
->
nmode
>
0
){
std
::
string
key
=
std
::
string
(
output
->
name
);
monitors
[
key
]
=
std
::
vector
<
std
::
string
>
();
for
(
int
k
=
0
;
k
<
output
->
nmode
;
k
++
){
XRRModeInfo
resolution
=
screen
->
modes
[
k
];
std
::
string
res
=
std
::
string
(
std
::
to_string
(
resolution
.
width
)
+
"x"
+
std
::
to_string
(
resolution
.
height
));
if
(
std
::
find
(
monitors
[
key
].
begin
(),
monitors
[
key
].
end
(),
res
)
==
monitors
[
key
].
end
())
monitors
[
key
].
push_back
(
res
);
}
}
XRRFreeOutputInfo
(
output
);
}
XRRFreeCrtcInfo
(
info
);
}
XRRFreeScreenResources
(
screen
);
XCloseDisplay
(
dp
);
}
loadResolutionsFromFile
(
path
);
std
::
remove
(
path
.
c_str
());
}
// load resolutions into GUI
...
...
@@ -119,31 +144,6 @@ std::vector<std::string> MonitorGui::splitResolution(std::string s){
return
res
;
}
bool
MonitorGui
::
isResolution
(
std
::
string
s
){
return
splitResolution
(
s
).
size
()
==
2
;
}
void
MonitorGui
::
loadResolutionsFromFile
(
std
::
string
path
){
// Get monitors and their resolutions into a Map
std
::
ifstream
infile
(
path
);
std
::
string
line
;
std
::
string
key
;
while
(
std
::
getline
(
infile
,
line
)){
std
::
istringstream
iss
(
line
);
std
::
string
l
;
iss
>>
l
;
if
(
!
isResolution
(
l
)){
key
=
l
;
monitors
[
key
]
=
std
::
vector
<
std
::
string
>
();
}
else
{
monitors
[
key
].
push_back
(
l
);
}
}
}
void
MonitorGui
::
showMonitorsScreenshot
(
QScreen
*
screen
){
QPixmap
px
=
screen
->
grabWindow
(
0
);
ui
->
lblScreenshot
->
setPixmap
(
px
);
...
...
This diff is collapsed.
Click to expand it.
app/SandboxSetup/monitorgui.h
+
1
−
3
View file @
ede48885
...
...
@@ -50,10 +50,8 @@ private:
QScreen
*
getMonitor
();
void
loadResolutionsOf
(
QScreen
*
screen
);
std
::
vector
<
std
::
string
>
splitResolution
(
std
::
string
s
);
bool
isResolution
(
std
::
string
s
);
void
loadResolutionsFromFile
(
std
::
string
path
);
void
initMonitorMapWithFile
(
std
::
string
path
);
void
showMonitorsScreenshot
(
QScreen
*
screen
);
void
initMonitorMap
();
};
#endif // MONITORGUI_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment