Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 5233 times)
0 Members and 1 Guest are viewing this topic.
Offline myrealityde

Senior Newbie


Medals: 1
Exp: 3 years


Blogger, GameMaker, Creator.


« Posted 2013-03-11 19: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 Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #1 - Posted 2013-04-18 09: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
« Reply #2 - Posted 2013-04-18 14: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!
Legends of Yore - The Casual Retro Roguelike
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #3 - Posted 2013-04-18 14: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
« Reply #4 - Posted 2013-04-19 10: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 Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #5 - Posted 2013-04-19 21: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
« Reply #6 - Posted 2013-04-23 11: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 Knight


Medals: 39
Exp: 6 years


Coding in Style


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

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

 Huh

Offline gouessej
« Reply #8 - Posted 2013-04-24 11:49:14 »

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

Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #9 - Posted 2013-04-24 14: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
« Reply #10 - Posted 2013-04-24 15: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 Knight


Medals: 39
Exp: 6 years


Coding in Style


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

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

Offline myrealityde

Senior Newbie


Medals: 1
Exp: 3 years


Blogger, GameMaker, Creator.


« Reply #12 - Posted 2013-10-21 11:14:57 »

Thanks a lot for all the answers! I'll have a look over my code.  Wink

Blogger, GameMaker, Creator.
Offline delt0r

JGO Knight


Medals: 27
Exp: 18 years


Computers can do that?


« Reply #13 - Posted 2013-10-22 14:20:17 »

On linux you will often need some mode lines in your xorg config file. Since these days there isn't one. You end up with just one valid mode, the current one. I have always had to add modelines when i want to use more than the current mode on my linux distros with nvidia drivers.

I have no special talents. I am only passionately curious.--Albert Einstein
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (16 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (34 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (31 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (44 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!