Xlib: DisplayWidth / DisplayHeight

2023-08-29 Thread Zbigniew
Hello,

I believe there's a need to change the functionality of the
DisplayWidth and DisplayHeight functions.

  It has nowadays become quite common to use the so-called virtual
screens — i.e. providing a larger operating field than visible on the
screen. The problem is that when using a virtual screen, both
functions mentioned return its size and not size of the physical
screen, which seldom makes sense in programming practice (for example,
see:
 https://stackoverflow.com/questions/28774830/retrieve-physical-screen-size
 
https://unix.stackexchange.com/questions/573121/get-current-screen-dimensions-via-xlib-using-c
).

  If I understand the intentions of the creators of these functions,
which were created long ago when virtual screens were not used, they
should return the size of the physical screen, so their current
behavior should be assessed as flawed. Therefore, their operation
should be corrected so that they always return the size of the
physical screen — regardless of whether a virtual screen is used or
not — and their current functionality should simply be copied intact
into two new functions, which could be called here VirtualDisplayWidth
/ VirtualDisplayHeight.

  Such a modification would close this issue that is still open for
years — as you can see from the example links provided, it causes a
lot of problems for programmers.

What do you think about this?
-- 
regards,
Zbigniew


Re: Xlib: DisplayWidth / DisplayHeight

2023-08-30 Thread Zbigniew
> Are you making reference to DisplayWidth and DisplayHeight, or
> DisplayWidthMM and DisplayHeightMM?

Talking about DisplayWidth and DisplayHeight functions.

>  And please explain which X extension supplies your ``virtual screen'' 
> functionality

It's done like this:
xrandr --output DVI-0 --mode 1920x1200 --panning 2520x1575

> rather monitors or outputs, wherein the server extension that implements them
> should be exploited to ascertain their dimensions.

No, there are two functions, that should return the proper values
regardless of how the virtual screen was created, which extension has
been used etc. The programmer shouldn't be bothered with such kind of
investigation.
And I'm not talking about size of virtual screen ˛— you may want to
read again my initial post — but exactly about „physical screen”
dimensions. These are the values that should be returned by
DisplayWidth and DisplayHeight functions.

So I would expect (in my particular case) to get 1920 and 1200 values,
and NOT dimensions of virtual screen, I mean 2520 and 1575
-- 
regards,
Zbigniew


Re: Xlib: DisplayWidth / DisplayHeight

2023-08-30 Thread Zbigniew
>>> Are you making reference to DisplayWidth and DisplayHeight, or
>>> DisplayWidthMM and DisplayHeightMM?
>>
>> Talking about DisplayWidth and DisplayHeight functions.
>>
>>>  And please explain which X extension supplies your ``virtual
>>> screen'' functionality
>>
>> It's done like this:
>> xrandr --output DVI-0 --mode 1920x1200 --panning 2520x1575
>>
>>> rather monitors or outputs, wherein the server extension that
>>> implements them
>>> should be exploited to ascertain their dimensions.
>>
>> No, there are two functions, that should return the proper values
>> regardless of how the virtual screen was created, which extension has
>> been used etc. The programmer shouldn't be bothered with such kind of
>> investigation.
>> And I'm not talking about size of virtual screen ˛— you may want to
>> read again my initial post — but exactly about „physical screen”
>> dimensions. These are the values that should be returned by
>> DisplayWidth and DisplayHeight functions.
>>
>> So I would expect (in my particular case) to get 1920 and 1200 values,
>> and NOT dimensions of virtual screen, I mean 2520 and 1575
>
> The behavior prescribed for these macros is to return the width and
> height of the screen, and doesn't provide for the existence of concepts
> such as panning or Xinerama.

You may want to read again my initial post: yes, the functions
described should „return the width and height of the screen”, as you
wrote — regardless if panning was, or it wasn't used.

You don't seem to understand this, I'm afraid?

>  Furthermore, any change to their existing
> semantics would cause countless programs reliant on its present behavior
> to malfunction.

„Existing semantics” is flawed. You may want to read my initial post again.

„Existing semantics” makes these functions unusable for reading width
and height of the screen, when virtual screen (AKA „panning”, if you
prefer) is in use, therefore NO PROGRAM can „malfunction”, because no
program had any chance to read the width and height of the screen
using these (still flawed) functions, when panning is used. These
functions are unusable in such situation. Period.

> Use the XRandR extension to ascertain the dimensions of individual
> outputs: an X "screen" designates a single root window, not a physical
> output device, and its dimensions therefore do not reflect that of any
> outputs which may be connected.  As one of the cornerstones of the X
> protocol, it cannot be subject to change.

„To ascertain the dimensions” there are two functions provided, that
should return proper width and height of the screen: DisplayWidth and
DisplayHeight. They should return proper values whether there is
panning in use — or it isn't — and even if virtual screen is used,
they still should return proper values regardless of method used for
panning. The programmer shouldn't be bothered with this („maybe the
user of my program will use Randr?”, „maybe he'll use X extension?”,
„maybe Y extension?” etc.).

Is the above clear enough for you?
-- 
regards,
Zbigniew


Re: Xlib: DisplayWidth / DisplayHeight

2023-08-30 Thread Zbigniew
> What you want is to find out the width and height of physical screen you
> have.

Indeed. That's what DisplayWidth and DisplayHeight functions have been
created for.

> To do that you need to use the subsystem that manages them - which
> is xrandr. And don't forget to specify which of 5 screen you have running
> you actually mean.

No, dear Volodya,

   „The  DisplayHeight  macro returns the height of the specified screen in
   pixels.

   The DisplayWidth macro returns the width of the screen in pixels.”

This is what I want, and this is what — as „man” page states — I
should get, regardless of presence of any „subsystems”. I want nothing
more than is described there.

Are you serious when stating, that during creation of a program I
should play guessing game „what kind of 'subsystem' the user may
employ”?
-- 
best :)
Z.


Re: Xlib: DisplayWidth / DisplayHeight

2023-08-31 Thread Zbigniew
>>   „The  DisplayHeight  macro returns the height of the specified
>> screen in
>>   pixels.
>>
>>   The DisplayWidth macro returns the width of the screen in pixels.”
>>
>> This is what I want, and this is what — as „man” page states — I
>
> And this what you get. Now when I say "Screen" I mean large rectangular
> matrix of pixels I can paint on. Which is pretty much what any application
> cares about - you don't need to paint outside of screen.

Dear, if we should mean by „screen” just any „large rectangular matrix
of pixels we can paint on” — then the whole discussion has no sense
whatsoever, and I should IYO be pleased, that the two functions return
to me, well, anything at all. Just in such case — you forgot(?) to add
— the use of the functions, that return „just something”, has no
purpose.

> What do you mean by "Screen" and why ?

You already know, what I mean — since you've already guessed it: the
physical screen I have. Why? Because that's the area where the window
of my program will appear.
What makes you think, that the creators of these functions, when
designing them years ago, meant anything different at that time, than
„resolution of physical screen handled by its Xserver”?
-- 
regards,
Zbigniew


Re: Xlib: DisplayWidth / DisplayHeight

2023-08-31 Thread Zbigniew
> Perhaps you should share your use case on why you need to know the screen
> size when there are far better mechanisms to handle this?

Because the use of the mentioned functions/macros is simple and
straightforward. But they are flawed, unfortunately.

So what mechanism do you propose to use for that?

> 3. Xserver handled panning is actually incredibly rare (that is what you
> have
> been describing). The panning you probably see 99.9% of the time is
> actually
> implemented by window managers as virtual desktops. This is not even
> implemented by Xlib or the Xserver but by a different process and here you
> have
> a whole different world to deal with and it's much more vague than thing
> than in
> X's "core". So I think your while understanding of virtual screens is flawed
> to begin with.

Is it rare, or it isn't — I believe you'll agree that I should've got
the proper dimensions of physical screen using these macros.

> 4. As has been mentioned - your understanding of screens is also flawed.
> You
> say these above macros should return the real screen width and height...
> what screen is that?

Dear Carsten,
have a look, please, at the man page:

   int DisplayHeight(Display *display, int screen_number);
   int DisplayWidth(Display *display, int screen_number);

„What screen is that”? The one described by the parameters.
('display' is a pointer to a 'Display' structure returned by a
previous call to XOpenDisplay() )

> 5. In fact the whole use of these macros is pretty much broken.

At least one person here notices and understands this. Yes, that's why
I suggested a fix.

> I can go on... I understand on the surface what you say - but you can't
> always
> get what you want and to me it seems your understanding of X is very
> superficial and thus you don't know the right way to do things

That's what APIs are for — to allow to make use out of *something* not
spending next two years to become acquainted with every possible
internals' aspect.

OK, you know what I'm about to. You stated, that the fix is impossible.

Then could you, please, suggest a „replacement functions” for these
two, that I could use to get the dimensions of physical screen —
whether is panning used, or not, is Xrandr used for that panning, or
anything else, is it Linux, or any of xBSD's etc.? In all these cases
t'll be still Xorg server, anyway.

That's all I need for today — and that's what DisplayWidth /
DisplayHeight promised to return
-- 
regards,
Zbigniew


Re: Xlib: DisplayWidth / DisplayHeight

2023-09-05 Thread Zbigniew
> You keep avoiding the question. WHICH SCREEN?
> [..]
>
> so will you answer the question - what screen do you mean? as i mentioned
> before. i think you have a far too basic view of screen and i'm trying to
> paint just a few of the possible scenarios to have you think about this.
> this discussion is going nowhere otherwise.

I've got a feeling you are trying to dilute this exchange by
artificially introducing conceptual confusion. Just as Pilate asked:
„but what exactly is truth?” — you keep asking: „which actually
screen?”.

As I already answered: the one described by the parameters. ('display'
is a pointer to a 'Display' structure returned by a previous call to
XOpenDisplay() ). The parameters to functions we're talking about are
described as follows:

   int DisplayHeight(Display *display, int screen_number);
   int DisplayWidth(Display *display, int screen_number);

It's clearly defined there.

Say, we've got a simple program:

#include 
#include 
int main(int argc,char **argv) {
Display *display = XOpenDisplay(NULL);
int screen_number = DefaultScreen(display);
int height = DisplayHeight(display, screen_number);
int width = DisplayWidth(display, screen_number);
XCloseDisplay(display);

printf("Height: %d\n", height);
printf("Width: %d\n",  width);

return 0;
}

What more you need to find out „which display”?
-- 
regards,
Zbigniew


Re: Xlib: DisplayWidth / DisplayHeight

2023-09-08 Thread Zbigniew
> Which screen? What is your use case? What are you trying to achieve?

I already wrote that in my post — that was my reply to yours — from
31. August, I quote:

„Could you, please, suggest a „replacement functions” for these two
[macros we're talking about], that I could use to get the dimensions
of physical screen — whether is panning used, or not, is Xrandr used
for that panning or anything else, is it Linux, or any of xBSD's etc.?
In all these cases t'll be still Xorg server, anyway.

That's all I need for today — and that's what DisplayWidth /
DisplayHeight promised to return”

But if you still prefer to pretend you actually don't know, what I
meant, and to ask rhetorical questions like „but what is a screen,
actually?” (Volodya knows precisely, what a „screen” is; it's about
any area of pixels) — then all I've got to say is: „never mind”
-- 
best,
Z.


Re: Xlib: DisplayWidth / DisplayHeight

2023-09-08 Thread Zbigniew
> To help you see our point of view, imagine someone complaining to you that
> even though the computer science course talked about trees and leaves
> there were no actual trees anywhere in sight, and how exactly does that
> help with CO2 emissions ?
>
> Display and Screen structures are abstractions that in some cases
> correspond to physical devices and in some cases (many more cases
> nowadays) do not. They are named "Display" and "Screen" but what they
> actually are is determined by how the code actually works.

The code I pasted had 14 lines (including two empty ones). So how it
„actually works”, according to you?

To help you see my point of view, here's a follow-up question: and how
do you think, reading my posts — and a code snippet, you've cut out so
conveniently — what kind of „Display and Screen structure” I had in
mind? A physical device, or the one from „some case”?
-- 
regards,
Zbigniew


Re: Xlib: DisplayWidth / DisplayHeight

2023-09-12 Thread Zbigniew
> If you are doing this for open source project, you should change your code
> to:
>
>  [..]

The code you've pasted doesn't work properly; it returns the size of
virtual screen — so you added 3x as much lines to get, in effect, the
same (incorrect) result as the few lines I pasted.

> Oh, and no I don't actually know what you mean, because it depends on what
> application you are writing.

Whatever it could be — an useful tool, or a silly game, open-source,
or commercial — it needs to find out the exact physical screen's
dimensions (in pixels), to learn how big is the working area.

> If you do teleconferencing, you might want to capture either the entire
> screen, or some window.
>
> If you want to record a movie of a game playing fullscreen, than you
> probably need the position and dimensions of the game window, because
> games often change video mode while keeping original virtual screen
> intact.
>
> If you want to make a better Xvnc, you probably need the code above and
> you might not need xrandr.
>
> If you are doing something else - who knows what you mean ?

So now you see (I hope that you see): „if… if… if… if… else…” etc. A
whole lot of checks and decisions that could be avoided, _IF_ the two
macros were working properly
-- 
best,
Teenager


Re: Xlib: DisplayWidth / DisplayHeight

2023-09-18 Thread Zbigniew
> Oh, I see. I suggest you try writing some concrete code - learning this
in abstract can be tricky.
> Don't be afraid to rewrite it from scratch a few times. There is existing
source code from X examples
> and tools, as well as other libraries, such as gtk and Qt.

Dear Volodya,

dpn't you worry about me, I'm not that afraid — and have a tip from me in
return: don't be afraid to polish your programming skills by „rewriting
from scratch” — or by learning from some tutorials (google for them) —
maybe one day the program you'll send to someone as „remedy” will work as
intended (provided you won't forget again even such basic things, like
„includes”), and (who knows?) maybe one day you will be able even to play
an authority on these matters.

Until then — consider taking more modest stance, avoid „patronizing”,
especially when you're unable even to create a properly working few-liner
-- 
best :)
Z.