Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-06

Obtaining screen geometry

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Brad Campbell

G'day all,

My application remembers where it was previously by doing a simple save of the current geometry. Top/Left/Width/Height. This appears to have worked well for a while now, but one of the users has just reported he ordinarily uses a dual head setup with my little app on the right hand screen.

Recently after he had unplugged the right hand screen, the app proceeded to put itself there anyway (off the edge of the accessible desktop). Is there an easy way to detect the current screen width, so if I sense my geometry is going to be off the edge I can provide a sane default instead?

This app runs on Win32, GTK2 & Carbon, so I assume the problem will manifest itself on all three, but in this instance it's running on a Mac.

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Alexander Grau
to Brad Campbell
Show quoted text 19 lines
G'day all, My application remembers where it was previously by doing a simple save of the current geometry. Top/Left/Width/Height. This appears to have worked well for a while now, but one of the users has just reported he ordinarily uses a dual head setup with my little app on the right hand screen. Recently after he had unplugged the right hand screen, the app proceeded to put itself there anyway (off the edge of the accessible desktop). Is there an easy way to detect the current screen width, so if I sense my geometry is going to be off the edge I can provide a sane default instead? This app runs on Win32, GTK2 & Carbon, so I assume the problem will manifest itself on all three, but in this instance it's running on a Mac. Regards, Brad

Hello Brad,

Below is how we center our main form when it is created (FormCreate) - you can see from it, how we can ask for the screen width/height - hopefully this will work with dual screen setups too!

Regards,
Alexander

  // always keep space around the window for dock panels (OSX/Win7 etc.)
  // this is the desired size (considering the space around the window)
  w:=round(screen.width - 150);
  h:=round(screen.height - 150);
  // this calculates the best size keeping aspect
  CalcResizeKeepAspect(1024, 768, w, h);
  height:=max(600, h);
  width:=max(800, w);

Reply by email

Graeme Geldenhuys
to Alexander Grau
Alexander Grau wrote 5 lines
?// always keep space around the window for dock panels (OSX/Win7 etc.) ?// this is the desired size (considering the space around the window) ?w:=round(screen.width - 150); ?h:=round(screen.height - 150);

In stead of using a "magic number" of 150, it would be better to query the underlying OS directly. Obviously this is not portable, but we have done this under Windows. Querying the width or height of the taskbar, and subtract that from the screens size.

But then you can have a multi-monitor system too, so now Screen size and Desktop size differs too... ;-)

?// this calculates the best size keeping aspect ?CalcResizeKeepAspect(1024, 768, w, h); ?height:=max(600, h); ?width:=max(800, w);

And don't for get the Golden Ratio for window sizes: 1.618 http://en.wikipedia.org/wiki/Golden_ratio

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Brad Campbell
to Alexander Grau: Below is how we center our main form when it is created (FormCreate) - you can see from…
Alexander Grau wrote
Below is how we center our main form when it is created (FormCreate) - you can see from it, how we can ask for the screen width/height - hopefully this will work with dual screen setups too!

Thanks for that Alexander, I'll give it a whirl when I get a second head hooked up and let you know. Many thanks :)

Regards,
Brad

Dolphins are so intelligent that within a few weeks they can train Americans to stand at the edge of the pool and throw them fish.

Reply by email

Paul Ishenin
to Brad Campbell: My application remembers where it was previously by doing a simple save of the current…
Brad Campbell wrote 5 lines
Recently after he had unplugged the right hand screen, the app proceeded to put itself there anyway (off the edge of the accessible desktop). Is there an easy way to detect the current screen width, so if I sense my geometry is going to be off the edge I can provide a sane default instead?

Use Screen.Monitors[] to get the geomentry of every monitor in the system. You can use the WorkArea property to exclude system menu, dockbar and taskbar of various window managers.

Best regards,
Paul Ishenin.

Reply by email