A Week of Trial [June Events 2021] - Community & Forums Related Discussions

Users browsing this thread: 2 Guest(s)
movq
Long time nixers
Yesterday was my first day and it was already pretty interesting. Found out that GPM isn't just a daemon that runs in the background and lets you copy and paste text. It's also a mouse server that you can write clients for. elinks uses it, for example, and that actually makes for a pretty good browsing experience: You can point and click to follow links, and you can even use the mouse wheel to scroll. Of course, elinks' menus are also clickable. That thing feels like a good old DOS program.

Also, nixers.net appears to work best in elinks. I just wish elinks could also show images like w3m can.

It's pretty easy to write a simple GPM client. Just for fun, I wrote a little frontend for asciibrot, which turns it into an interactive ASCII mandelbrot explorer:

Code:
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <gpm.h>

void
handle(Gpm_Event *evt)
{
    static double zoom = 1;
    static double cx = 0;
    static double cy = 0;
    char cmd[512] = "";

    if (evt->type & GPM_MOVE)
    {
        if (evt->wdy > 0)
            zoom /= 1.05;
        else if (evt->wdy < 0)
            zoom *= 1.05;

        cx += 0.05 * evt->dx * zoom;
        cy += 0.05 * evt->dy * zoom * (-1);
    }

    puts("\e[H");

    /* "-T" requires the current Git main branch. */
    snprintf(cmd, sizeof cmd, "asciibrot -z %lf -p %lf:%lf -T", zoom, cx, cy);
    system(cmd);
}

int
main()
{
    Gpm_Connect conn;
    Gpm_Event evt;
    fd_set fds;

    conn.eventMask = ~0;
    conn.defaultMask = ~GPM_HARD;  /* ? */
    conn.minMod = 0;
    conn.maxMod = ~0;  /* these two mods mean "get everything" */

    /* gpm_fd is a funny global variable from GPM. */
    if (Gpm_Open(&conn, 0) == -1)
    {
        fprintf(stderr, "Could not connect to gpm\n");
        return 1;
    }
    else if (gpm_fd == -2)
    {
        fprintf(stderr, "GPM says we're running under X11\n");
        return 1;
    }

    printf("Connected with gpm_fd %d\n", gpm_fd);

    for (;;)
    {
        FD_ZERO(&fds);
        FD_SET(gpm_fd, &fds);
        if (select(gpm_fd + 1, &fds, 0, 0, 0) < 0 && errno == EINTR)
            continue;

        if (FD_ISSET(gpm_fd, &fds))
        {
            if (Gpm_GetEvent(&evt) > 0)
                handle(&evt);
            else
                fprintf(stderr, "Oops in Gpm_GetEvent\n");
        }
    }

    return 0;
}

(It's not optimal, it should also adjust the number of iterations depending on the zoom level.)

Sad thing is, GPM clients don't work when run under tmux. They can connect to the daemon (which listens on a UNIX socket), but they don't know their "true" TTY, so they just get errors instead of mouse events.

GPM's documentation is available as GNU info pages. I never liked those, because navigation is so unusual. Yesterday, I finally learned about the "l" key in GNU info: When you follow a link to a section, you can press "l" to jump back to where you were. This was the missing piece of the puzzle for me. GNU info is much more enjoyable now and I think I'll spend a little more time investigating it.

For what it's worth, my current setup uses three TTYs:
  • tty3: This runs a tmux session with ncmpcpp and pulsemixer in it.
  • tty4: I do most of the stuff here, no tmux.
  • tty5: Connects via SSH to one of my servers and attaches to another tmux session there, which runs WeeChat for IRC and Matrix.


Messages In This Thread
A Week of Trial [June Events 2021] - by venam - 01-06-2021, 12:07 PM
RE: A Week of Trial [June Events 2021] - by jkl - 01-06-2021, 02:36 PM
RE: A Week of Trial [June Events 2021] - by venam - 01-06-2021, 02:41 PM
RE: A Week of Trial [June Events 2021] - by pfr - 03-06-2021, 10:07 PM
RE: A Week of Trial [June Events 2021] - by movq - 20-06-2021, 10:17 AM
RE: A Week of Trial [June Events 2021] - by pfr - 22-06-2021, 09:41 PM
RE: A Week of Trial [June Events 2021] - by venam - 24-06-2021, 02:23 AM
RE: A Week of Trial [June Events 2021] - by pfr - 24-06-2021, 03:33 AM
RE: A Week of Trial [June Events 2021] - by venam - 24-06-2021, 03:39 AM
RE: A Week of Trial [June Events 2021] - by movq - 24-06-2021, 11:37 AM
RE: A Week of Trial [June Events 2021] - by jkl - 24-06-2021, 07:32 PM
RE: A Week of Trial [June Events 2021] - by pfr - 25-06-2021, 01:14 AM
RE: A Week of Trial [June Events 2021] - by movq - 26-06-2021, 01:59 AM
RE: A Week of Trial [June Events 2021] - by venam - 26-06-2021, 03:02 AM
RE: A Week of Trial [June Events 2021] - by movq - 27-06-2021, 01:01 PM
RE: A Week of Trial [June Events 2021] - by movq - 30-06-2021, 11:06 AM
RE: A Week of Trial [June Events 2021] - by venam - 30-06-2021, 01:27 PM
RE: A Week of Trial [June Events 2021] - by pfr - 01-07-2021, 09:40 PM
RE: A Week of Trial [June Events 2021] - by prx* - 02-07-2021, 05:31 AM