34
\$\begingroup\$

Output the device's screen resolution in the specific format of [width]x[height] where [width] is replaced by the horizontal number of pixels and [height] is replaced by the vertical number of pixels. For example, an output could read 1440x900. Should there be multiple screens, report about the primary screen. You may not change the resolution as part of your inquiry.

Here is a non‑golfed ECMAScript code snippet achieving this task (unless privacy settings kick in).

console.log(window.screen.width + 'x' + window.screen.height)

\$\endgroup\$
13
  • 17
    \$\begingroup\$ The specific output format is no fun, but it's probably too late to change now \$\endgroup\$
    – Luis Mendo
    Commented May 2, 2017 at 13:29
  • 3
    \$\begingroup\$ What should the behaviour be if multiple displays are connected? \$\endgroup\$ Commented May 2, 2017 at 13:40
  • 4
    \$\begingroup\$ I suppose we're not allowed to first change your resolution and then tell you those values, right? \$\endgroup\$ Commented May 2, 2017 at 15:12
  • 4
    \$\begingroup\$ APL\360 (can only be run on IBM/360 typewriter environment), 5 bytes: '0x0' \$\endgroup\$
    – Adám
    Commented May 2, 2017 at 16:14
  • 4
    \$\begingroup\$ I like that this one disqualifies most golfing languages and encourages people to explore the limits of practical ones. \$\endgroup\$
    – robbie
    Commented May 4, 2017 at 14:31

48 Answers 48

38
\$\begingroup\$

JavaScript (ES6), 32 bytes

(_=screen)=>_.width+"x"+_.height

Outputs as function return. Add f= at the beginning and invoke like f(). Uses parameter-initializing to initialize the parameter _ to screen object. The rest is self-explanatory.

f=(_=screen)=>_.width+"x"+_.height
console.log(f())

Note: Passing an argument to this function will cause it to fail.


JavaScript (Previous Solution), 35 bytes

with(screen)alert(width+"x"+height)

Never thought I will one day use with! I don't think this can be golfed further.

\$\endgroup\$
19
  • \$\begingroup\$ If REPLs are allowed, s=screen,s.width+"x"+s.height (29 characters) also works. \$\endgroup\$
    – Kobi
    Commented May 3, 2017 at 12:35
  • \$\begingroup\$ Oooh. Good use of default argument value. \$\endgroup\$ Commented May 3, 2017 at 12:54
  • \$\begingroup\$ The 35-byte solution can save five bytes by not bothering to alert: with(screen)(width+'x'+height) just returns the appropriate string. \$\endgroup\$
    – KRyan
    Commented May 4, 2017 at 1:58
  • 2
    \$\begingroup\$ This answer is fundamentally flawed. I can cheat it by zooming my browser in and out! \$\endgroup\$
    – user64742
    Commented May 4, 2017 at 16:12
  • 1
    \$\begingroup\$ Come on, are you guys even trying: _=screen,_.width+"x"+_.height, 29 bytes \$\endgroup\$
    – M28
    Commented May 7, 2017 at 6:38
34
\$\begingroup\$

TI-BASIC, 30 32 29 bytes (non-competing?)

*sigh* TI-BASIC takes an extra byte for every lowercase letter.

+2 thanks to @Timtech

-3 thanks to @Timtech

:If ΔX>.1
:Then
:Disp "96x64
:Else
:Disp "320x240

This only works because TI-BASIC can only be run on calculators with two different screen resolutions: 96 by 64 and 320 by 240. I just test to see which screen I have by setting the Zoom to something that is different depending on screen resolution then outputting the correct resolution.

I'm marking this as non-competing for now, since it is hard coded.

\$\endgroup\$
8
  • 6
    \$\begingroup\$ Thats a clever abuse ;) \$\endgroup\$ Commented May 2, 2017 at 15:38
  • 1
    \$\begingroup\$ You can save by not using ZDecimal and then using a different Xmax comparison, at least one byte. Also, I think you need to use lowercase x which is two bytes (x2) instead of the one-byte uppercase equivalent. \$\endgroup\$
    – Timtech
    Commented May 2, 2017 at 18:22
  • \$\begingroup\$ @Timtech I have to use a two byte Zoom (like ZDecimal) because the default zoom (ZStandard) is the same on both calculators. I'll fix the capitalization, though. \$\endgroup\$ Commented May 2, 2017 at 22:47
  • 1
    \$\begingroup\$ Oh, I see what you mean. If you use ZStandard though, would ΔX be different then between the calculators? Also, ZDecimal is only one byte, so this is 31 bytes. \$\endgroup\$
    – Timtech
    Commented May 3, 2017 at 10:18
  • 2
    \$\begingroup\$ For some reason, my instant reaction is "that's valid, but wouldn't be valid if there were only one possible screen resolution", but that point of view seems internally inconsistent. So I'm really unsure as to whether this is cheating or not. \$\endgroup\$
    – user62131
    Commented May 4, 2017 at 1:08
20
\$\begingroup\$

JavaScript (ES6), 32 bytes

_=>(s=screen).width+'x'+s.height

console.log((_=>(s=screen).width+'x'+s.height)())

\$\endgroup\$
5
  • 2
    \$\begingroup\$ the lambda version is acceptable \$\endgroup\$ Commented May 2, 2017 at 14:35
  • 6
    \$\begingroup\$ _=>(s=screen).width+'x'+s.height saves a byte \$\endgroup\$ Commented May 2, 2017 at 14:38
  • \$\begingroup\$ @FelipeNardiBatista Thanks, the thought just occurred to me as well :) \$\endgroup\$
    – SethWhite
    Commented May 2, 2017 at 14:40
  • 1
    \$\begingroup\$ Good job! +1 :) \$\endgroup\$
    – Arjun
    Commented May 2, 2017 at 14:42
  • 5
    \$\begingroup\$ I love how all the JS entries have been consistently shorter than a large number of the other answers. Almost never happens. \$\endgroup\$ Commented May 2, 2017 at 17:29
11
\$\begingroup\$

macOS, bash, awk, grep, tr, 51 52 bytes

/*/*/sy*r SPDisplaysDataType|awk '/so/{print$2$3$4}'

Runs system_profiler, gets the SPDisplaysDataType information, searches for the first so in Resolution, and prints the screen resolution. For multiple screens, this prints all resolutions.

Example of the command running.


The prior, malcompliant variant:

/*/*/sy*r SPDisplaysDataType|grep so|tr -d 'R :a-w'
\$\endgroup\$
5
  • \$\begingroup\$ I just ran this on my MacBook Pro with a second display attached. I got 2880x1800\n1920x1080@60Hz (two lines). I don't know if that disqualifies this... or? \$\endgroup\$
    – Floris
    Commented May 2, 2017 at 16:15
  • \$\begingroup\$ @Floris did OP specify how to behave when there are multiple screens? \$\endgroup\$ Commented May 2, 2017 at 16:26
  • \$\begingroup\$ No - but the format @60Hz is clearly not in spec. \$\endgroup\$
    – Floris
    Commented May 2, 2017 at 16:28
  • \$\begingroup\$ I guess you could tack on a |sed 1q, bringing the byte count up to 58 bytes. \$\endgroup\$
    – zgrep
    Commented May 2, 2017 at 20:33
  • \$\begingroup\$ I fixed the non-compliance by switching to awk and having one extra byte. :) \$\endgroup\$
    – zgrep
    Commented May 2, 2017 at 20:52
9
\$\begingroup\$

Javascript, 36 bytes

s=screen;alert(s.width+"x"+s.height)

\$\endgroup\$
0
9
\$\begingroup\$

Processing 3, 37 bytes

fullScreen();print(width+"x"+height);

fullScreen() causes the app to launch with the maximum dimensions - the display resolution. One byte less than the obvious

print(displayWidth+"x"+displayHeight);
\$\endgroup\$
9
\$\begingroup\$

AutoHotKey, 34 bytes

SysGet,w,0
SysGet,h,1
Send,%w%x%h%

Save this in a file with extension .AHK and run it from a command prompt

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Why not use Send rather than MsgBox? \$\endgroup\$ Commented May 2, 2017 at 14:57
  • \$\begingroup\$ @EngineerToast thanks! That saved two bytes \$\endgroup\$
    – jmriego
    Commented May 2, 2017 at 15:01
7
\$\begingroup\$

C (Windows), 79 78 77 bytes

Thanks to @Johan du Toit for saving a byte!

#import<windows.h>
#define G GetSystemMetrics
f(){printf("%dx%d",G(0),G(1));}
\$\endgroup\$
1
  • 2
    \$\begingroup\$ I was still messing around with 'GetDeviceCaps' until I saw your answer :-) You can still save 1 byte by using the following: #define G GetSystemMetrics f(){printf("%dx%d",G(0),G(1));} \$\endgroup\$
    – jdt
    Commented May 3, 2017 at 18:45
7
\$\begingroup\$

PowerShell, 67 60 55 Bytes

-7 thanks to Martin Ender

-5 (actually 12!) from Leaky Nun , Regex wizardry is beyond me.

This is long but not longer than the horrendous System.Windows.Forms.SystemInformation.PrimaryMonitorSize solution

(gwmi win32_videocontroller|% v*n)-replace" |x \d+\D+$"

first we Get-WmiObject(gwmi) to retrieve the Win32_VideoController object, which contains a member named VideoModeDescription, which is a string in the format of 1920 x 1080 x 4294967296 colors, then I run a regex replace to get correct format.

PS H:\> (gwmi win32_videocontroller|% v*n)-replace" |x \d+\D+$"
1920x1080
\$\endgroup\$
1
  • \$\begingroup\$ I think (gwmi win32_videocontroller|% v*n)-replace" |x[^x]+$" shaves a couple of bytes by tweaking the regex. \$\endgroup\$ Commented May 11, 2017 at 16:49
6
\$\begingroup\$

Mathematica, 51 bytes

SystemInformation[][[1,5,2,1,2,1,2,2,;;,2]]~Infix~x

This may not work for you depending on what devices you have connected (I don't know). This should always work (assuming you have at least one screen hooked up):

Infix[Last/@("FullScreenArea"/.SystemInformation["Devices","ScreenInformation"][[1]]),x]

Explanation

SystemInformation[] returns an expression of the form

SystemInformationData[{
  "Kernel" -> {__},
  "FrontEnd" -> {__},
  "Links" -> {__},
  "Parallel" -> {__},
  "Devices" -> {__},
  "Network" -> {__},
}]

We are interested in "Devices", which can be accessed directly as SystemInformation["Devices"] or as SystemInformation[][[1,5,2]]. The result will be a list of the form

{
  "ScreenInformation" -> {__},
  "GraphicsDevices" -> {__},
  "ControllerDevices" -> {__}
}

We want "ScreenInformation", which can be accessed either as SystemInformation["Devices","ScreenInformation"] or more succinctly as SystemInformation[][[1,5,2,1,2]]. The result will be of the form

{
  {
  "ScreenArea" -> {__},
  "FullScreenArea" -> {{0,w_},{0,h_}},
  "BitDepth" -> _,
  "Resolution" -> _
  },
  ___
}

The length of the list will be the number of screens you have connected. The first screen is SystemInformation[][[1,5,2,1,2,1]] and the width and height can be extracted as SystemInformation[][[1,5,2,1,2,1,2,2,;;,2]] Then we just insert an Infix x for the output format.

\$\endgroup\$
6
\$\begingroup\$

Java 7, 123 114 bytes

String f(){java.awt.Dimension s=java.awt.Toolkit.getDefaultToolkit().getScreenSize();return s.width+"x"+s.height;}

This method will not work in a headless installation of Java (like on TIO) because it uses the awt libraries. Under the hood, calling getScreenSize uses the Java Native Interface to call out (typically into a C library) for the screen width and screen height.

-9 bytes thanks to Olivier Grégoire for reminding me that I can return the string instead of printing it.

\$\endgroup\$
8
  • 2
    \$\begingroup\$ I was just about to post... \$\endgroup\$
    – Leaky Nun
    Commented May 2, 2017 at 13:24
  • \$\begingroup\$ @LeakyNun You and me both. +1 Poke. \$\endgroup\$ Commented May 2, 2017 at 13:46
  • \$\begingroup\$ Too bad the output is restricted to ...x..., because void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll("[^\\d,]",""));} which outputs 1920,1200 is shorter.. \$\endgroup\$ Commented May 2, 2017 at 14:21
  • 1
    \$\begingroup\$ @KevinCruijssen yeah I did try playing with that as well. The real "too bad" is that using regex in java is so heavy in terms of byte count. \$\endgroup\$
    – Poke
    Commented May 2, 2017 at 14:56
  • 1
    \$\begingroup\$ @Poke You're indeed right. I have been able to use that what I show above with an x instead of , by using some regex replacement, but it's five bytes more than your current answer: void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll("[^\\d,]","").replace(",","x"));} or void f(){System.out.print((java.awt.Toolkit.getDefaultToolkit().getScreenSize()+"").replaceAll(".*?(\\d+).*?(\\d+).*","$1x$2"));} Ah well, what isn't heavy in Java.. ;p \$\endgroup\$ Commented May 2, 2017 at 15:02
6
\$\begingroup\$

C#, 101 95 89 bytes

_=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};

-6 bytes thanks to @TheLethalCoder by reminding me OP didn't mention about printing, so returning a string is also fine. And an additional -6 bytes by changing it to a lambda.

\$\endgroup\$
4
  • \$\begingroup\$ You can save 11 bytes by compiling to a Func<string>: ()=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;};. However, you have a return of void but you are returning a string so you need to add 2 bytes for that. \$\endgroup\$ Commented May 3, 2017 at 9:48
  • 1
    \$\begingroup\$ The challenge also doesn't state that you can't take input so you could add an unused input to save another byte i.e. _=>{var s=System.Windows.Forms.Screen.PrimaryScreen.Bounds;return s.Width+"x"+s.Height;}; \$\endgroup\$ Commented May 3, 2017 at 9:49
  • 1
    \$\begingroup\$ Oh ignore the return comment you're writing the result out, you can save 6 bytes by returning it. \$\endgroup\$ Commented May 3, 2017 at 9:49
  • \$\begingroup\$ And unless you can think of a way to get it shorter var s=System.Windows.Forms.Screen.AllScreens[0].Bounds; would also be the same count but you could golf it with that idea in mind. \$\endgroup\$ Commented May 3, 2017 at 9:52
6
\$\begingroup\$

Bash + xrandr, 44 characters

read -aa<<<`xrandr`
echo ${a[7]}x${a[9]::-1}

xrandr belongs to the X server, on Ubuntu is provided by x11-xserver-utils package.

Sample run:

bash-4.3$ read -aa<<<`xrandr`;echo ${a[7]}x${a[9]::-1}
1920x1080

xrandr + grep + util-linux, 30 characters

xrandr|grep -oP '\d+x\d+'|line

Thanks to:

Sample run:

bash-4.3$ xrandr|grep -oP '\d+x\d+'|line
1920x1080
\$\endgroup\$
10
  • \$\begingroup\$ I have no bash with a display, would xrandr|grep * work? \$\endgroup\$ Commented May 2, 2017 at 13:13
  • \$\begingroup\$ Sure. But for now the my grep and sed attempts to parse xrandr's output (pastebin.com/uTVcjWCq) were longer. \$\endgroup\$
    – manatwork
    Commented May 2, 2017 at 13:15
  • \$\begingroup\$ Maybe xrandr|grep *|cut -d' ' -f1? (using the matching line from your paste @TIO) \$\endgroup\$ Commented May 2, 2017 at 13:29
  • \$\begingroup\$ Ah, you mean to pick the resolution from the list by the “*” mark? Thought to that possibility, but I am not sure whether would work with multiple displays connected. As I remember, that would list each connected display's current resolution. \$\endgroup\$
    – manatwork
    Commented May 2, 2017 at 13:36
  • \$\begingroup\$ Ah yes it would, not sure what the OP wants in such a scenario though! \$\endgroup\$ Commented May 2, 2017 at 13:37
5
\$\begingroup\$

Python 2, 73 bytes

from ctypes import*
u=windll.user32.GetSystemMetrics;
print u(0),'x',u(1)
\$\endgroup\$
3
  • \$\begingroup\$ print u(0),'x',u(1) is smaller and his example (link) allows it \$\endgroup\$ Commented May 2, 2017 at 14:20
  • 1
    \$\begingroup\$ To clarify, If it's equivalent to the output from What is my screen resolution, It's valid. in that website, there is space between each part \$\endgroup\$ Commented May 2, 2017 at 14:22
  • \$\begingroup\$ @FelipeNardiBatista Updated, thanks. \$\endgroup\$
    – Neil
    Commented May 2, 2017 at 14:24
5
\$\begingroup\$

Octave, 41 bytes

Thanks to @Arjun and @StephenS for corrections.

fprintf('%ix%i',get(0,'ScreenSize')(3:4))

0 is a handle to the root graphics object. Its property 'ScreenSize' contains the coordinates of the screen in pixels. The third and fourth entries give the desired information.

\$\endgroup\$
0
5
\$\begingroup\$

APL (Dyalog), 23 bytes

' '⎕R'x'⍕⌽⊃⎕WG'DevCaps'

⎕WG'DevCaps'Window Get Device Capabilities

 pick the first property (height, width)

 reverse

 format as text

' '⎕R'x'Replace spaces with "x"s

\$\endgroup\$
1
  • \$\begingroup\$ "substitute with an "x" at position 5 (the space)" this would cause problems on a small screen, e.g. 640x480 (which VMs use) \$\endgroup\$
    – Baldrickk
    Commented May 2, 2017 at 13:55
5
\$\begingroup\$

ZX Spectrum Basic, 10 bytes

just for completeness:

PRINT "256x192"

outputs 256x192. The Spectrum has a fixed hardwired screen resolution.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ ...and uses a single byte for keywords like PRINT. \$\endgroup\$
    – Jens
    Commented Oct 18, 2019 at 8:11
4
\$\begingroup\$

Japt, 24 bytes

Ox`ØP(s×Çn)±d+"x"+ight

Test it online!

The compressed string represents with(screen)width+"x"+height. Ox evaluates this as JavaScript, and the result is implicitly printed.

\$\endgroup\$
4
\$\begingroup\$

C (SDL2 library) 113 88 84

(-4 chars due to @AppleShell 's help)

Yes. it compiles.

m[3];main(){SDL_Init(32);SDL_GetDesktopDisplayMode(0,m);printf("%dx%d",m[1],m[2]);}

Run with : gcc snippet.c -lSDL2 && ./a.out

\$\endgroup\$
3
  • 3
    \$\begingroup\$ I think you can shorten this by making m global and omitting int: m[3];main(){... \$\endgroup\$
    – Appleshell
    Commented May 2, 2017 at 15:39
  • \$\begingroup\$ accessing by m+1 should be shorter than m[1] right? or isn't that possible in C but only in C++? surely printf has some dereference token \$\endgroup\$
    – Gizmo
    Commented May 3, 2017 at 9:34
  • \$\begingroup\$ @gizmo unfortunately AFAIK there is no printf specifier that does such thing .. \$\endgroup\$
    – dieter
    Commented May 3, 2017 at 11:26
4
\$\begingroup\$

xrandr + awk, 25 bytes

xrandr|awk /\*/{print\$1}

enter image description here

\$\endgroup\$
7
  • 1
    \$\begingroup\$ This doesn't work. grep * expands the asterisk to all files in the directory. \$\endgroup\$
    – Jens
    Commented May 3, 2017 at 8:07
  • \$\begingroup\$ @Jens Corrected. Thanks for pointing out \$\endgroup\$
    – Pandya
    Commented May 3, 2017 at 8:56
  • \$\begingroup\$ Thanks; another hint: the proper spelling for grep|cut is awk. \$\endgroup\$
    – Jens
    Commented May 3, 2017 at 9:11
  • \$\begingroup\$ It still doesn't work. It outputs *0. My xrandr output is *0 3360 x 1050 ( 889mm x 278mm ) *0. \$\endgroup\$
    – Jens
    Commented May 3, 2017 at 9:15
  • \$\begingroup\$ @Jens then you need -f2 Btw, Can you check xrandr|awk '/\*/{print $2}'? \$\endgroup\$
    – Pandya
    Commented May 3, 2017 at 9:29
4
\$\begingroup\$

Python 2, 61 49 bytes

Thanks @Jonathan-allan, @felipe-nardi-batista

from Tkinter import*
print'%sx%s'%Tk().maxsize()

For single display setups, this matches the output from the site. This gives entire resolution for multiple displays.

\$\endgroup\$
3
  • \$\begingroup\$ print'x'.... saves a byte \$\endgroup\$ Commented May 3, 2017 at 10:52
  • \$\begingroup\$ v=Tk().maxsize(), print'%sx%s'%v saves 9 bytes. \$\endgroup\$ Commented May 3, 2017 at 13:04
  • \$\begingroup\$ oops, and then print'%sx%s'%Tk().maxsize() saves another 4 >_< \$\endgroup\$ Commented May 3, 2017 at 13:14
3
\$\begingroup\$

bash + xdpyinfo 42 31 bytes

xdpyinfo|grep dim|cut -d' ' -f7

From man page:

xdpyinfo - is  a utility for displaying information about an X server.

@Floris @manatwork Thanks for saving a few bytes!

\$\endgroup\$
3
  • \$\begingroup\$ Crossed out 4 is still 4 :( \$\endgroup\$
    – user63187
    Commented May 2, 2017 at 15:22
  • \$\begingroup\$ There is no need for spaces around the pipes; I think is safe to search for “dim” only; you can write -d\ instead of -d' '. Then when it comes to both grep for a line and cut a part of that line, usually is shorter with a single awk call: xdpyinfo|awk '/dim/&&$0=$2'. \$\endgroup\$
    – manatwork
    Commented May 2, 2017 at 15:32
  • \$\begingroup\$ I suspect you can grep something shorter than dimensions but I don't have xdpyinfo on my system... \$\endgroup\$
    – Floris
    Commented May 2, 2017 at 16:27
2
\$\begingroup\$

Processing, 51 bytes

void setup(){fullScreen();print(width+"x"+height);}

This outputs in this format: width height. Also, the program creates a window that is the size of the screen you are using (because every Processing program creates a window by default) and this program just outputs the height and the width of this window/sketch.

\$\endgroup\$
2
  • \$\begingroup\$ Oh, the format is WIDTHxHEIGHT. \$\endgroup\$ Commented May 2, 2017 at 15:27
  • \$\begingroup\$ @SIGSEGV Just noticed it \$\endgroup\$
    – user41805
    Commented May 2, 2017 at 15:27
2
\$\begingroup\$

xdpyinfo + awk, 28 bytes

$ xdpyinfo|awk /dim/{print\$2}
3360x1050

Tested on Cygwin with dual heads.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ xdpyinfo|awk /dim/{print\$2} takes 28 bytes not 24 \$\endgroup\$
    – Pandya
    Commented May 3, 2017 at 9:55
  • \$\begingroup\$ @Pandya I need new glasses :-) \$\endgroup\$
    – Jens
    Commented May 3, 2017 at 11:18
2
\$\begingroup\$

Racket, 73 bytes

#!racket/gui
(let-values([(x y)(get-display-size #t)])(printf"~ax~a"x y))

Just discovered the (discouraged) shorthand for #lang. Saves a few bytes! Documentation for get-display-size.

\$\endgroup\$
1
\$\begingroup\$

Tcl/Tk, 40

puts [winfo screenw .]x[winfo screenh .]
\$\endgroup\$
1
\$\begingroup\$

Lithp, 116 bytes

((import html-toolkit)
(htmlOnLoad #::((var S(index(getWindow)screen))
(print(+(index S width)"x"(index S height))))))

(Line breaks added for readability)

Try it online!

Finally, my html-toolkit module gets some use! Only works in the Try it Online link, will not work from command line.

A few bytes could be saved if 1024 x 768 could be valid output. We just use (+ .. "x" .. ) to avoid print's implicit spacing.

\$\endgroup\$
2
  • \$\begingroup\$ Hmm. I tried it online, but it says 2048x1080 for a true 4K screen that's actually 4096x2160. Any idea why? Firefox 52.0 on FreeBSD 11. \$\endgroup\$
    – Jens
    Commented May 3, 2017 at 17:25
  • \$\begingroup\$ No idea. I'm merely grabbing window.screen and getting the width and height attributes from it. I imagine if you opened up the Firefox console and typed in window.screen you'll see the apparently incorrect 2048x1080. \$\endgroup\$
    – Andrakis
    Commented May 4, 2017 at 0:28
1
\$\begingroup\$

Lua (löve framework),116 bytes

f,g=love.window.setFullscreen,love.graphics function love.draw()f(1)w,h=g.getDimensions()f(0>1)g.print(w.."x"..h)end

The programm changes first to fullscreen then it gets the width and height and prints it then :)

\$\endgroup\$
1
\$\begingroup\$

xrandr and sh, 23 bytes

$ set `xrandr`;echo $6x$8
3360x1050

Tested on a CentOS 5 box with display redirected to a Cygwin machine with two monitors. Here the full xrandr output is

$ xrandr
 SZ:    Pixels          Physical       Refresh
*0   3360 x 1050   ( 889mm x 278mm )  *0
Current rotation - normal
Current reflection - none
Rotations possible - normal
Reflections possible - none
\$\endgroup\$
1
\$\begingroup\$

Ruby + xrandr, 37 bytes

puts `xrandr`.split[7..9].join[0..-2]

Alternate solution (52 bytes):

puts `xrandr`.match(/t (\d+) (x) (\d+),/)[1..3].join
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.