Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Getting all available screen resolutions on Linux  (Read 1599 times)
0 Members and 1 Guest are viewing this topic.
Offline myrealityde

Senior Newbie


Medals: 1


Blogger, GameMaker, Creator.


« Posted 2013-03-11 20:57:19 »

Hey everyone,
I'm trying to fetch all currently available resolutions of the screen. The problem: I'm only getting the active screen resolution (on Linux).  the following code works on Mac & Windows but not on Linux:

1  
2  
3  
4  
5  
6  
7  
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice display = ge.getDefaultScreenDevice();
DisplayMode[] availableModes = display.getDisplayModes();
     
for (DisplayMode mode : availableModes) {
    System.out.println(mode.getWidth() + "x" + mode.getHeight());
}

Any suggestions?  Huh

Blogger, GameMaker, Creator.
Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #1 - Posted 2013-04-18 11:20:51 »

I do pretty much the same. It does work, but results differ between Windows and Ubuntu.

Maybe you could try to retrieve all the display devices instead of just the default one?

Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #2 - Posted 2013-04-18 16:01:06 »

Hi

Sorry to say that but AWT has some bugs and limitations, not only under GNU Linux. I get all screen resolutions with NEWT (JOGL 2.0). NEWT will even support XrandR 1.3 soon which means that it will be able to expose a lot more information about virtual and physical screens/monitors. Maybe this limitation has disappeared in JavaFX, look at the class javafx.stage.Screen.

Edit.: I think that your code doesn't look at all cases, it can be fixed...

Edit.2: Maybe Oskuro is right, you should look at all devices.

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #3 - Posted 2013-04-18 16:27:09 »

My experience is that it is indeed unpredictable, probably requiring some low level wizardry to get actual results, which kind of defeats the multi-platform approach.


I did some research trying to determine the screen rotation angle, which lead me to compiling system-dependent libraries that would query the information from the system.

Something worth noting I found was that even on the official libraries, many low level features are just ignored. The rotation parameter, for example, was ignored as it wasn't completely reliable (driver issues) and wasn't very important when implemented.

With this, what I'm trying to say is that, if accessing system configuration parameters is crucial, you can't really rely on standard multi-platform libraries entirely, if only because time constraints (deadlines) probably mean the developers couldn't fit everything in.




Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #4 - Posted 2013-04-19 12:36:36 »

Something worth noting I found was that even on the official libraries, many low level features are just ignored. The rotation parameter, for example, was ignored as it wasn't completely reliable (driver issues) and wasn't very important when implemented.

With this, what I'm trying to say is that, if accessing system configuration parameters is crucial, you can't really rely on standard multi-platform libraries entirely, if only because time constraints (deadlines) probably mean the developers couldn't fit everything in.
You can rely on NEWT which is not concerned by your affirmations.

Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #5 - Posted 2013-04-19 23:05:43 »

 Cool! I'll have to check it out then!


@myrealityde
Oh, by the way, here's the output for my laptop running Ubuntu 12.04:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
// Recover the Graphics Environment (usually no need to store it, but just being verbose for clarity)
java.awt.GraphicsEnvironment localEnvironment = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();

// Recover Device List
java.awt.GraphicsDevice[] deviceList = localEnvironment.getScreenDevices();

// Recover Display Modes for Device 'i'
java.awt.DisplayMode[] modeList = deviceList[i].getDisplayModes();

// Recover Graphics Configurations for Device 'i'
java.awt.GraphicsConfiguration[] gfxConfigList = deviceList[i].getConfigurations();


This is the result. The first list is a log of all the graphics modes (my laptop only returns a single device), and then the first log of the many graphics configurations (didn't want to post them all).

Note that I parse the data a bit, you can't just .toString() this stuff. Tongue

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  
20130419-223847 - [DEBUG]: -----------------------------------------------Display Info:
Device [0]: :0.0
     nk0.doom4k.system.display.DisplayDevice@70c722ad
  Compatible Modes:
    Mode [0] Size[1920x1080] Depth[-1] Refresh[60]
    Mode [1] Size[1600x1200] Depth[-1] Refresh[60]
    Mode [2] Size[1680x1050] Depth[-1] Refresh[60]
    Mode [3] Size[1280x1024] Depth[-1] Refresh[75]
    Mode [4] Size[1280x1024] Depth[-1] Refresh[60]
    Mode [5] Size[1440x900] Depth[-1] Refresh[75]
    Mode [6] Size[1440x900] Depth[-1] Refresh[60]  ACTIVE
    Mode [7] Size[1280x960] Depth[-1] Refresh[60]
    Mode [8] Size[1280x800] Depth[-1] Refresh[60]
    Mode [9] Size[1152x864] Depth[-1] Refresh[75]
    Mode [10] Size[1024x768] Depth[-1] Refresh[75]
    Mode [11] Size[1024x768] Depth[-1] Refresh[70]
    Mode [12] Size[1024x768] Depth[-1] Refresh[60]
    Mode [13] Size[832x624] Depth[-1] Refresh[75]
    Mode [14] Size[800x600] Depth[-1] Refresh[72]
    Mode [15] Size[800x600] Depth[-1] Refresh[75]
    Mode [16] Size[800x600] Depth[-1] Refresh[60]
    Mode [17] Size[800x600] Depth[-1] Refresh[56]
    Mode [18] Size[640x480] Depth[-1] Refresh[73]
    Mode [19] Size[640x480] Depth[-1] Refresh[75]
    Mode [20] Size[640x480] Depth[-1] Refresh[67]
    Mode [21] Size[640x480] Depth[-1] Refresh[60]
    Mode [22] Size[720x400] Depth[-1] Refresh[70]

20130419-223847 - [DEBUG]: -------------------------------------Device [ :0.0 ] Info:

GraphicsConfig[0]:  DEFAULT
Configuration [ X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21] ]:
   Bounds:                java.awt.Rectangle[x=0,y=0,width=1440,height=900]
   BufferCapabilities:    sun.awt.X11GraphicsConfig$XDBECapabilities@3cca6f82
   ColorModel:            DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0

   DefaultTransform:      AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
                          Type:        0
                          Scale X:     1.0
                          Scale Y:     1.0
                          Shear X:     0.0
                          Shear Y:     0.0
                          Translate X: 0.0
                          Translate Y: 0.0

   ImageCapabilities:     java.awt.ImageCapabilities@1c78014a

   NormalizingTransform:  AffineTransform[[1.333333333333333, 0.0, 0.0], [0.0, 1.334033613445378, 0.0]]
                          Type:        4
                          Scale X:     1.3333333333333333
                          Scale Y:     1.3340336134453783
                          Shear X:     0.0
                          Shear Y:     0.0
                          Translate X: 0.0
                          Translate Y: 0.0

   isTranslucencyCapable: NO

   ImageCapabilities:     IsAccelerated:  YES
                          IsTrueVolatile: NO



As you can see, a pretty simple code results in a lot of data that you don't seem to be getting. Probably the drivers are to blame (HP laptop with hybrid Intel/ATI card in my case).

Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #6 - Posted 2013-04-23 13:16:05 »

I don't know what you have chosen to hide when using AWT but NEWT is able to return the size of the physical/virtual monitor in mm, the rotation (more useful for tablets), ... and it has a really reliable full screen support under GNU Linux  Grin

Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #7 - Posted 2013-04-24 13:33:57 »

I don't know what you have chosen to hide when using AWT

 Huh

Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #8 - Posted 2013-04-24 13:49:14 »

Huh
You said "you can't just .toString()", didn't you?

Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #9 - Posted 2013-04-24 16:57:15 »

Oh, just meant the fancy formatting of all the data was my doing (as in manually), to avoid anyone thinking that there is some fast method to print it out like that.


Been checking NEWT. It's part of JOGL right? Is there a stand-alone version that can be plugged in into something else?


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #10 - Posted 2013-04-24 17:10:08 »

Been checking NEWT. It's part of JOGL right? Is there a stand-alone version that can be plugged in into something else?
Yes NEWT is a "part" of JOGL but you can use GLG2D with it if you want to use Java2D for example. NEWT is very cross-platform, it works under Android too and at least one developer has worked for some months to port it to iOS.

Offline Oskuro

JGO Coder


Medals: 16


Coding in Style


« Reply #11 - Posted 2013-04-24 17:13:35 »

Intriguing. Thanks, it is now part of my "To Check Out" list  Grin

Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (32 views)
2013-05-17 21:29:12

alaslipknot (40 views)
2013-05-16 21:24:48

gouessej (70 views)
2013-05-16 00:53:38

gouessej (69 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (73 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (137 views)
2013-05-12 17:10:36

kutucuk (136 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.121 seconds with 20 queries.