Discrepancy between command line XRandR and own code - c++

I need to programatically get the refresh rate of a monitor.
When I type xrandr (1.4.1, opensuse 13) on the command line I get:
Screen 0: minimum 8 x 8, current 1920 x 1200, maximum 16384 x 16384
VGA-0 disconnected primary (normal left inverted right x axis y axis)
DVI-D-0 connected 1920x1200+0+0 (normal left inverted right x axis y axis) 518mm x 324mm
1920x1200 60.0*+
1920x1080 60.0
1680x1050 60.0
1600x1200 60.0
1280x1024 60.0
1280x960 60.0
1024x768 60.0
800x600 60.3
640x480 59.9
HDMI-0 disconnected (normal left inverted right x axis y axis)
This result is confirmed by nvidia-settings -q RefreshRate, among other things.
But ...
when I run the following code (origin: https://github.com/raboof/xrandr/blob/master/xrandr.c), compiled with g++ 4.8.1 (with -lX11 -lXext -lXrandr) :
int nsize;
int nrate;
short *rates;
XRRScreenSize *sizes;
Display *dpy = XOpenDisplay(NULL);
Window root = DefaultRootWindow(dpy);
XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root);
printf ("Current rate: %d\n",XRRConfigCurrentRate(conf));
sizes = XRRConfigSizes(conf, &nsize);
printf(" SZ: Pixels Refresh\n");
for (int i = 0; i < nsize; i++) {
printf("%-2d %5d x %-5d", i, sizes[i].width, sizes[i].height);
rates = XRRConfigRates(conf, i, &nrate);
if (nrate)
printf(" ");
for (int j = 0; j < nrate; j++)
printf("%-4d", rates[j]);
printf("\n");
}
XRRFreeScreenConfigInfo(conf);
I get:
Current rate: 50
SZ: Pixels Refresh
0 1920 x 1200 50
1 1920 x 1080 51
2 1680 x 1050 52
3 1600 x 1200 53
4 1280 x 1024 54
5 1280 x 960 55
6 1024 x 768 56
7 800 x 600 57
8 640 x 480 58
9 1440 x 900 59
10 1366 x 768 60
11 1280 x 800 61
12 1280 x 720 62
Why am I getting this result?
What I am doing wrong?
The software uses OpenGL with GLEW. can this have any influence?
We do call glXQueryDrawable(dpy, drawable, GLX_SWAP_INTERVAL_EXT, &val) but afterwards, and I do not think this should have any influence.

I found the answer:
If the XRandR sever supports version 1.2 of the protocol, then the appropriate functions need to be used (wich I plan to do by copying snippets of code from https://github.com/raboof/xrandr/blob/master/xrandr.c where has_1_2 is true).
My code in the question uses functions for the version 1.1 of the protocol, and therefore only the metamodes are returned.
As a simple check, I tried the following two commands:
xrandr --q1
xrandr --q12.
And indeed the 1st one gives me the same result I programatically get.
Credits go to http://www.ogre3d.org/forums/viewtopic.php?f=4&t=65010&start=200

Related

Showing data in power Bi matrix as percentage

In the matrix, I have this representation -
X Y Z TOTAL
A 3 4 6 13
B 6 44 55 105
C 0 4 8 12
TOTAL 9 52 69 130
I want to show this as the following -
X Y Z
A 23% 31% 46%
B 6% 42% 52%
C 0% 33% 67%
example, for row A - (X/Total)*100 , (Y/Total)*100 ,(Z/Total)*100.
How do i do it?
Thanks in advance for your hep !
Select values field and show value as pecentage of row total

Get constituent dataframes from one with multiple values in a column

I have a sample data frame below which has two values (Bus and Car+Minibus) in the mode column I have two questions, the first is how can I break this up into two data frames with single values as seen below. The second question is since I have a list of data frames with some occurring in the input format, how can I write a condition statement them.
input
Dest a b c
Orig Variable Time Mode
1 x y Bus 5.00 17.32 12.61
Car+Minibus 0.87 15.34 12.01
2 x y Bus 5.00 14.72 10.15
Car+Minibus 10.47 3.03 11.05
3 x y Bus 14.72 5.00 15.98
Car+Minibus 11.64 11.25 2.08
4 x y Bus 15.15 14.62 5.94
Car+Minibus 12.02 9.25 5.80
outputs:
Dest a b c
Orig Variable Time Mode
1 x y Bus 5.00 17.32 12.61
2 x y Bus 5.00 14.72 10.15
3 x y Bus 14.72 5.00 15.98
4 x y Bus 15.15 14.62 5.94
Dest a b c
Orig Variable Time Mode
1 x y Car+Minibus 0.87 15.34 12.01
2 x y Car+Minibus 10.47 3.03 11.05
3 x y Car+Minibus 11.64 11.25 2.08
4 x y Car+Minibus 12.02 9.25 5.80
I believe you need check fourth level of MultiIndex and filter by boolean indexing:
mask = df.index.get_level_values(3) == 'Bus'
df1 = df[mask]
df2 = df[~mask]
But if want working with list of DataFrames:
dfs = [df11,df12,df13]
for df in dfs:
mask = df.index.get_level_values(3) == 'Bus'
df1 = df[mask]
print (df1)
df2 = df[~mask]
print (df2)

Solid fill of an ellipse in python dxf

I'd like to draw filled ellipse with python. This would be easy if I could use PIL oder some other libraries. The problem is I need the ellipse in a .dxf file format. Therefore I used the dxfwrite package. This allows me to draw an ellipse but I couldn't find a way to fill it with a solid color. The following code does draw an ellipse line, but does not fill it.
import dxfwrite
from dxfwrite import DXFEngine as dxf
name = 'ellipse.dxf'
dwg = dxf.drawing(name)
dwg.add(dxf.ellipse((0,0), 5., 10., segments=200))
dwg.save()
Does anybody of you guys know a solution?
The HATCH entity is not supported by dxfwrite, if you use ezdxf this is the solution:
import ezdxf
dwg = ezdxf.new('AC1015') # hatch requires the DXF R2000 (AC1015) format or later
msp = dwg.modelspace() # adding entities to the model space
# important: major axis >= minor axis (ratio <= 1.) else AutoCAD crashes
msp.add_ellipse((0, 0), major_axis=(0, 10), ratio=0.5)
hatch = msp.add_hatch(color=2)
with hatch.edit_boundary() as boundary: # edit boundary path (context manager)
edge_path = boundary.add_edge_path()
# an edge path can contain line, arc, ellipse or spline elements
edge_path.add_ellipse((0, 0), major_axis_vector=(0, 10), minor_axis_length=0.5)
# upcoming ezdxf 0.7.7:
# renamed major_axis_vector to major_axis
# renamed minor_axis_length to ratio
dwg.saveas("solid_hatch_ellipse.dxf")
You could fill an ellipse by using a solid hatch object:
For the above example, here is a snippet from the DXF file that contains the ellipse and the hatch:
AcDbEntity
8
0
100
AcDbEllipse
10
2472.192919
20
1311.37942
30
0.0
11
171.0698134145308
21
-27.61597470964863
31
0.0
210
0.0
220
0.0
230
1.0
40
0.2928953354556341
41
0.0
42
6.283185307179586
0
HATCH
5
5A
330
2
100
AcDbEntity
8
0
100
AcDbHatch
10
0.0
20
0.0
30
0.0
210
0.0
220
0.0
230
1.0
2
SOLID
70
1
71
1
91
1
92
5
93
1
72
3
10
2472.192919357234
20
1311.379420138197
11
171.0698134145308
21
-27.61597470964863
40
0.2928953354556341
50
0.0
51
360.0
73
1
97
1
330
59
75
1
76
1
47
0.794178
98
1
10
2428.34191358924
20
1317.777876434349
450
0
451
0
460
0.0
461
0.0
452
0
462
1.0
453
2
463
0.0
63
5
421
255
463
1.0
63
2
421
16776960
470
LINEAR
1001
GradientColor1ACI
1070
5
1001
GradientColor2ACI
1070
2
1001
ACAD
1010
0.0
1020
0.0
1030
0.0
There are a lot of DXF codes involved. This is the information Autodesk provide:
Hatch group codes
Group code
Description
100
Subclass marker (AcDbHatch)
10
Elevation point (in OCS)
DXF: X value = 0; APP: 3D point (X and Y always equal 0, Z represents the elevation)
20, 30
DXF: Y and Z values of elevation point (in OCS)
Y value = 0, Z represents the elevation
210
Extrusion direction (optional; default = 0, 0, 1)
DXF: X value; APP: 3D vector
220, 230
DXF: Y and Z values of extrusion direction
2
Hatch pattern name
70
Solid fill flag (solid fill = 1; pattern fill = 0); for MPolygon, the version of MPolygon
63
For MPolygon, pattern fill color as the ACI
71
Associativity flag (associative = 1; non-associative = 0); for MPolygon, solid-fill flag (has solid fill = 1; lacks solid fill = 0)
91
Number of boundary paths (loops)
varies
Boundary path data. Repeats number of times specified by code 91. See Boundary Path Data
75
Hatch style:
0 = Hatch “odd parity” area (Normal style)
1 = Hatch outermost area only (Outer style)
2 = Hatch through entire area (Ignore style)
76
Hatch pattern type:
0 = User-defined; 1 = Predefined; 2 = Custom
52
Hatch pattern angle (pattern fill only)
41
Hatch pattern scale or spacing (pattern fill only)
73
For MPolygon, boundary annotation flag (boundary is an annotated boundary = 1; boundary is not an annotated boundary = 0)
77
Hatch pattern double flag (pattern fill only):
0 = not double; 1 = double
78
Number of pattern definition lines
varies
Pattern line data. Repeats number of times specified by code 78. See Pattern Data
47
Pixel size used to determine the density to perform various intersection and ray casting operations in hatch pattern computation for associative hatches and hatches created with the Flood method of hatching
98
Number of seed points
11
For MPolygon, offset vector
99
For MPolygon, number of degenerate boundary paths (loops), where a degenerate boundary path is a border that is ignored by the hatch
10
Seed point (in OCS)
DXF: X value; APP: 2D point (multiple entries)
20
DXF: Y value of seed point (in OCS); (multiple entries)
450
Indicates solid hatch or gradient; if solid hatch, the values for the remaining codes are ignored but must be present. Optional; if code 450 is in the file, then the following codes must be in the file: 451, 452, 453, 460, 461, 462, and 470. If code 450 is not in the file, then the following codes must not be in the file: 451, 452, 453, 460, 461, 462, and 470
0 = Solid hatch
1 = Gradient
451
Zero is reserved for future use
452
Records how colors were defined and is used only by dialog code:
0 = Two-color gradient
1 = Single-color gradient
453
Number of colors:
0 = Solid hatch
2 = Gradient
460
Rotation angle in radians for gradients (default = 0, 0)
461
Gradient definition; corresponds to the Centered option on the Gradient Tab of the Boundary Hatch and Fill dialog box. Each gradient has two definitions, shifted and unshifted. A Shift value describes the blend of the two definitions that should be used. A value of 0.0 means only the unshifted version should be used, and a value of 1.0 means that only the shifted version should be used.
462
Color tint value used by dialog code (default = 0, 0; range is 0.0 to 1.0). The color tint value is a gradient color and controls the degree of tint in the dialog when the Hatch group code 452 is set to 1.
463
Reserved for future use:
0 = First value
1 = Second value
470
String (default = LINEAR)
I hope this may be of some use to you. I apologize if I missunderstood your issue.

C++ How to get the window size (width and height)?

I'm trying to create a graph and I need to know the size of the window the user is running the code in. I'm trying to scale the data so the data shows only on the size of the window, without wrapping or scrolling. I'm on windows but I want to use something similar to Linux equivalent
int lines = atoi(getenv("LINES") ;
int cols = atoi(getenv("COLUMNS") ;
So I can scale numbers and show a graph like this
320 a ============================================================
160 b ==============================
80 c ===============
40 d =======
20 e ===
10 f =
5 g
2 h
1 i
2 j
17 k ===
41 l =======
67 m ============
97 n ==================
127 o ========================
157 p =============================
191 q ====================================
227 r ===========================================
257 s ================================================
283 t =====================================================
331 u ==============================================================
367 v =====================================================================
373 w ======================================================================
379 x ========================================================================
383 y ========================================================================
389 z ==========================================================================
Is there something that will work on Windows and Linux? I'm using Visual Studio 2012.
Use GetWindowRect
RECT rect;
if(GetWindowRect(hwnd, &rect))
{
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
}
Use GetConsoleScreenBufferInfo or one of its siblings.
You are interrested in the dzSize field of the "returned" struct.
Read documentation here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx
You already have a solution for Linux.
On Windows the API call you need is GetConsoleScreenBufferInfo.
This returns a CONSOLE_SCREEN_BUFFER_INFO struct, from which you read out the dwSize member:
A COORD structure that contains the size of the console screen buffer, in character columns and rows.

Haskell OpenGL won't open in Ubuntu

This one is a bit weird, but I will start at the beginning:
As far as I gathered, there are 3 ways to open up an OpenGL window in Haskell: GLUT, GLFW and SDL. I don't want to use GLUT at all, because it forces you to use IORefs and basically work in the IO monad only. So I tried GLFW and made a little thingie on my laptop, which uses Xubuntu with the XFCE desktop system.
Now I was happy and copied it to my desktop, a fairly fresh installed standard Ubuntu with Unity, and was amazed to see nothing. The very same GLFW code that worked fine on the laptop was caught in an endless loop before it opened the window.
Right then I ported it all to SDL. Same code, same window, and SDL crashes with
Main.hs: user error (SDL_SetVideoMode
SDL message: Couldn't find matching GLX visual)
I have checked back with SDLgears, using the same method to open a window, and it works fine. Same with some other 3D application, and OpenGL is enabled fine.
What baffles me is that it works under a XUbuntu but not on an Ubuntu. Am I missing something here? Oh, and if it helps, the window opening function:
runGame w h (Game g) = withInit [InitVideo] $ do
glSetAttribute glRedSize 8
glSetAttribute glGreenSize 8
glSetAttribute glBlueSize 8
glSetAttribute glAlphaSize 8
glSetAttribute glDepthSize 16
glSetAttribute glDoubleBuffer 1
_ <- setVideoMode w h 32 [OpenGL, Resizable]
matrixMode $= Projection
loadIdentity
perspective 45 (fromIntegral w / fromIntegral h) 0.1 10500.0
matrixMode $= Modelview 0
loadIdentity
shadeModel $= Smooth
hint PerspectiveCorrection $= Nicest
depthFunc $= Just Lequal
clearDepth $= 1.0
g
This error message is trying to tell you that your combination of bit depths for the color, depth and alpha buffers (a "GLX visual") is not supported. To see which ones you can use on your system, try running glxinfo.
$ glxinfo
...
65 GLX Visuals
visual x bf lv rg d st colorbuffer sr ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a F gb bf th cl r g b a ns b eat
----------------------------------------------------------------------------
0x023 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 16 16 16 16 0 0 None
0x024 24 tc 0 32 0 r . . 8 8 8 8 . . 0 24 8 16 16 16 16 0 0 None
0x025 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 0 16 16 16 16 0 0 None
0x026 24 tc 0 32 0 r . . 8 8 8 8 . . 0 24 0 16 16 16 16 0 0 None
0x027 24 tc 0 32 0 r y . 8 8 8 8 . . 0 24 8 0 0 0 0 0 0 None
...