• Re: Can 'graphics' be a file descriptor?

    From Lawrence D'Oliveiro@21:1/5 to wij on Wed Jan 1 08:11:10 2025
    On Wed, 01 Jan 2025 15:48:32 +0800, wij wrote:

    (ByteFlow is actually a file descriptor, it is a base class of regular
    file, fifo file, socket file character file...)

    Relevance being?

    Perfect fit! Any idea that 'graphics' be a file descriptor?

    What is 'graphics'?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bart@21:1/5 to wij on Wed Jan 1 12:07:07 2025
    On 01/01/2025 11:05, wij wrote:
    On Wed, 2025-01-01 at 01:29 -0800, Keith Thompson wrote:
    wij <wyniijj5@gmail.com> writes:
    In recent revision of libwy (a C++ library that wraps Clib functions), I feel
    the so called 'graphics' can be a file descriptor.

    A file *descriptor* is a small integer referring to some file-like
    entity, used with open/close/read/write.  There's no such thing in
    standard C; it's a POSIX concept.

    I don't think you're actually working with file descriptors, though it's
    hard to tell.

      if((r=popen(GrSvr,cpid,frd,fwr))!=Ok) {
        WY_THROW(r);
      }

    popen() is a POSIX function.  It takes two arguments, not four.

    The code you posted is C++.  Why are you posting it to comp.lang.c?

    [...]

    I would like to have opinions about the idea "graphics being a file descriptor".
    The implement is irrevent for the discussion. Some imagination is required.


    You'll need to explain what you mean by `graphics` or `'graphics`. What
    is it now? What is it anyway?

    Are you refering to the 'handles' that graphics libraries sometimes use
    to refer to windows etc? If so what would be the advantages of having
    them being file descriptors? Could those advantages be possible in any
    other way?

    How would it simplify your C++ code?

    Some time ago, I had a scripting language where you could write:

    print #x, "hello"

    With x being either 'con' (the default if omitted), an open file handle,
    a string destination, a printer or plotter handle, or the handle to an
    image, window or control (button etc).

    So this allowed you write text into any of those, via the convenience of 'print' which stringified or serialised many kinds of data, and also
    kept track of the current text position.

    Is this one of the advantages?

    Actually I'm surprised that in Linux, everything isn't already a file
    anyway.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to bart on Wed Jan 1 19:25:57 2025
    On Wed, 1 Jan 2025 12:07:07 +0000, bart wrote:

    Actually I'm surprised that in Linux, everything isn't already a file
    anyway.

    There are three separate ideas you will come across in Linux:
    * Everything is a file
    * Everything is a file descriptor
    * Everything is a filesystem

    Examples of the first one: Unix sockets, named pipes, device files
    Examples of the second one: pidfd, signalfd, timerfd, poll
    Examples of the third one: procfs, sysfs, securityfs, cgroup2

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Keith Thompson on Thu Jan 2 00:50:06 2025
    On Wed, 01 Jan 2025 14:33:34 -0800, Keith Thompson wrote:

    ... a small integer value used in POSIX I/O ...

    A small non-negative integer value.

    Remember, negative integers are smaller than positive ones.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bart@21:1/5 to wij on Thu Jan 2 11:28:32 2025
    On 01/01/2025 13:40, wij wrote:
    On Wed, 2025-01-01 at 12:07 +0000, bart wrote:
    On 01/01/2025 11:05, wij wrote:
    On Wed, 2025-01-01 at 01:29 -0800, Keith Thompson wrote:
    wij <wyniijj5@gmail.com> writes:
    In recent revision of libwy (a C++ library that wraps Clib functions), I feel
    the so called 'graphics' can be a file descriptor.

    A file *descriptor* is a small integer referring to some file-like
    entity, used with open/close/read/write.  There's no such thing in
    standard C; it's a POSIX concept.

    I don't think you're actually working with file descriptors, though it's >>>> hard to tell.

       if((r=popen(GrSvr,cpid,frd,fwr))!=Ok) {
         WY_THROW(r);
       }

    popen() is a POSIX function.  It takes two arguments, not four.

    The code you posted is C++.  Why are you posting it to comp.lang.c?

    [...]

    I would like to have opinions about the idea "graphics being a file descriptor".
    The implement is irrevent for the discussion. Some imagination is required. >>>

    You'll need to explain what you mean by `graphics` or `'graphics`. What
    is it now? What is it anyway?

    Are you refering to the 'handles' that graphics libraries sometimes use
    to refer to windows etc? If so what would be the advantages of having
    them being file descriptors? Could those advantages be possible in any
    other way?

    How would it simplify your C++ code?

    Yes, in MS-Windonw, file descriptor is probably still 'file handle' (as in DOS).
    I am mainly referring to Linux (or systems that relies on file descriptor). The usual graphics library, especially with GUI,... seriously interfere the the 'normal' program. E.g. you are not expected to have a clean source program
    that simply edits a picture file.

    I don't know what that means. But an app that edits text files is going
    to be different from one that edits images.

    As for a clean program, what you posted was in C++, a language not known
    for its clean, simple syntax. You might want to start there.


    Some time ago, I had a scripting language where you could write:

        print #x, "hello"

    With x being either 'con' (the default if omitted), an open file handle,
    a string destination, a printer or plotter handle, or the handle to an
    image, window or control (button etc).

    So this allowed you write text into any of those, via the convenience of
    'print' which stringified or serialised many kinds of data, and also
    kept track of the current text position.

    Is this one of the advantages?

    Yes, looked like what I expect. But file descriptor is a stronger request (or provision) than library codes. It will simply more and would standardize 'graphics' to some extent enough for 'normal programs' (commercial programs alway seek breakthrough, you cannot expect to fully standardize it).

    Are there any problem doing 'graphics' with your print script? I am mainly looking for 'clean'/reusabe source code.

    My 'print #w' was specifically for text. There was a proper API for
    actual graphics content within a window, which was both pixel-based and model-based (using 2D/3D floating point data).

    However, in early days, my dialog boxes were little more than text
    windows rendered in graphics, and GUI elements were created with text
    escape codes via 'print', IIRC. That was nearly 4 decades ago though.

    I don't see a use for real graphics using a text or byte stream except
    when the connection to the display device is some serial link. But even
    then, at the user level I'd expect an API which hides those details:

    w := createwindow(....)
    draw_rectangle(w, x1, y1, x2, y2)

    'w' is a handle; you don't care exactly what it is or how it works.


    ??? to my knowledge, in Linux 'everything' is file descriptor.

    Perhaps I meant that everything can be accessed via a path within the
    file system.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to BGB on Fri Jan 3 00:07:48 2025
    On Thu, 2 Jan 2025 16:08:57 -0600, BGB wrote:

    POSIX sockets also share the same numbering space, and some of the same
    calls (Windows sockets do not, and many functions gain an WSA prefix and changes to capitalization and similar).

    That’s a limitation of Windows. For example, POSIX systems allow select/
    poll on any file descriptor, Windows does not.

    What happens then, does one represent a window as a BMP file or
    something, which one writes to to update the contents?...

    The old X11 protocol used a socket as its primary communication channel.
    To this was soon added a shared-memory extension, for more rapid
    information transfer when both client and server were on the same machine.

    Wayland does something similar.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to BGB on Thu Jan 2 23:35:12 2025
    On Thu, 02 Jan 2025 16:08:57 -0600, BGB wrote:

    On 1/2/2025 3:06 PM, Keith Thompson wrote:
    wij <wyniijj5@gmail.com> writes:
    On Wed, 2025-01-01 at 14:33 -0800, Keith Thompson wrote:
    wij <wyniijj5@gmail.com> writes:
    On Wed, 2025-01-01 at 01:29 -0800, Keith Thompson wrote:
    [...]
    A file *descriptor* is a small integer referring to some file-like >>>>>> entity, used with open/close/read/write.  There's no such thing in >>>>>> standard C; it's a POSIX concept.
    [...]
    I would like to have opinions about the idea "graphics being a file
    descriptor".  The implement is irrevent for the discussion. Some
    imagination is required.

    Why do you insist on referring to "file descriptors"?  That's a specific >>>> term with a specific meaning: a small integer value used in POSIX I/O
    (not in standard C).

    I do not insist anything. I would just like to have an opinion on the idea >>> "graphics being a file descriptor".

    So you insist on talking about "file descriptors".

    Standard C doesn't have file descriptors. Consider discussing this in
    comp.unix.programmer.


    It is also kinda moot...

    If it were "integer handle" or even "integer value in the same numbering space as file handles", I would be like "yeah, sure, whatever".

    POSIX sockets also share the same numbering space, and some of the same
    calls (Windows sockets do not, and many functions gain an WSA prefix and changes to capitalization and similar).



    If one wants it so that read/write/lseek/etc do something useful with
    them, this is a different matter.

    What happens then, does one represent a window as a BMP file or
    something, which one writes to to update the contents?... This is likely
    more overhead than is worthwhile.

    I refer you to the X11 specifications and example implementation found at
    x.org

    X is a networked protocol that performs graphics functions. The network communications used by X, on Unix and unix-like systems, accesses a socket (which others have pointed out is, on Unix a "file descriptor"-like object)

    Granted, some dislike /how/ X uses network sockets for communication, and X implementations (for Unixish systems) often provide alternatives such as
    "unix domain sockets" and "shared memory" communications. Still, X has found
    it "useful" to use these "file descriptor"-like objects to implement
    "graphics" facilities.

    [snip]


    Other methods, like sockets or local RPC, still likely make more sense.

    Oh, I'm glad that the techniques and technologies in use for over 30 years
    gain your (apparently grudging) approval.

    :-)


    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)