Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Don’t toss your Windows 10 PC! Try switching to KDE Plasma instead

    Windows 10 gets an extra year of free security updates (with a catch)

    Philps Hue smart lights are already pricey. They’re about to get pricier

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Apple sued by shareholders for allegedly overstating AI progress

      June 22, 2025

      How far will AI go to defend its own survival?

      June 2, 2025

      The internet thinks this video from Gaza is AI. Here’s how we proved it isn’t.

      May 30, 2025

      Nvidia CEO hails Trump’s plan to rescind some export curbs on AI chips to China

      May 22, 2025

      AI poses a bigger threat to women’s work, than men’s, report says

      May 21, 2025
    • Business

      Google links massive cloud outage to API management issue

      June 13, 2025

      The EU challenges Google and Cloudflare with its very own DNS resolver that can filter dangerous traffic

      June 11, 2025

      These two Ivanti bugs are allowing hackers to target cloud instances

      May 21, 2025

      How cloud and AI transform and improve customer experiences

      May 10, 2025

      Cookie-Bite attack PoC uses Chrome extension to steal session tokens

      April 22, 2025
    • Crypto

      How Plume Drove a 100% Jump in RWA Holders to Overtake Ethereum

      June 24, 2025

      $400 Million SHIB Supply Zone Might Prevent Shiba Inu From Ending Downtrend

      June 24, 2025

      Turkey Overhauls Crypto Regulations to Stop Money Laundering

      June 24, 2025

      What Crypto Whales Are Buying After Israel-Iran Ceasefire Announcement

      June 24, 2025

      Midnight Network Tokenomics Introduces Radically Accessible and Fair Token Distribution Model 

      June 24, 2025
    • Technology

      Don’t toss your Windows 10 PC! Try switching to KDE Plasma instead

      June 25, 2025

      Windows 10 gets an extra year of free security updates (with a catch)

      June 25, 2025

      Philps Hue smart lights are already pricey. They’re about to get pricier

      June 25, 2025

      Amazon’s Fire TV Stick 4K drops to its best price of the year

      June 25, 2025

      The state of DTC marketing in 2025: How brands and agencies are leveraging data and automation to fuel ROI

      June 25, 2025
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Shop Now
    Tech AI Verse
    You are at:Home»Technology»Forbidden secrets of ancient X11 scaling technology revealed
    Technology

    Forbidden secrets of ancient X11 scaling technology revealed

    TechAiVerseBy TechAiVerseJune 24, 2025No Comments5 Mins Read0 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Forbidden secrets of ancient X11 scaling technology revealed

    People keep telling me that X11 doesn’t support DPI scaling, or fractional scaling, or multiple monitors, or something. There’s nothing you can do to make it work. I find this surprising. Why doesn’t it work? I figure the best way to find out is try the impossible and see how far we get.

    I’m just going to draw a two inch circle on the screen. This screen, that screen, any screen, the circle should always be two inches. Perhaps not the most exciting task, but I figure it’s isomorphic to any other scaling challenge. Just imagine it’s the letter o or a button we wish to draw at a certain size.

    I have gathered around me a few screens of different sizes and resolutions. My laptop screen, and then a bit to the right a desktop monitor, and then somewhere over that way a nice big TV. Specifically:

    $ xrandr | grep  connected
    eDP connected primary 2880x1800+0+0 (normal left inverted right x axis y axis) 302mm x 189mm
    DisplayPort-0 connected 2560x1440+2880+0 (normal left inverted right x axis y axis) 590mm x 334mm
    DisplayPort-1 connected 3840x2160+5440+0 (normal left inverted right x axis y axis) 1600mm x 900mm

    I think I just spoiled the ending, but here we go anyway.

    I’m going to draw the circle with OpenGL, using a simple shader and OBT. There’s a bunch of not very exciting code to create a window and a GLX context, but eventually we’re going to be looking at the shader. This may not be the best way to draw a circle, but it’s my way. For reference, the full code is in circle.c.

    void main()
    {
        float thick = radius / 10;
        if (abs(center.y - gl_FragCoord.y) < thick/2) 
            thick = 2;
        float pi = 3.14159;
        float d = distance(gl_FragCoord.xy, center);
        float angle = atan(gl_FragCoord.y - center.y, gl_FragCoord.x - center.x);
        angle /= 2 * pi;
        angle += 0.5;
        angle += 0.25;
        if (angle > 1.0) angle -= 1.0;
        float amt = (thick - abs(d - radius)) / thick;
        if (d < radius + thick && d > radius - thick) 
            fragment = vec4(rgb(angle)*amt, 1.0);
        else 
            discard;
    }

    I got a little carried away and made a pretty color wheel instead of a flat circle.

    The key variable is radius which tells us how many pixels from the center the circle should be. But where does the shader get this from?

        glUniform1f(0, radius);

    Okay, but seriously. We listen for configure events. This is the X server telling us our window has been moved or resized. Something has changed, so we should figure out where we are and adjust accordingly.

            case ConfigureNotify:
                {
                    XConfigureEvent *xev = (void *)&ev;
                    int x = xev->x;
                    for (int i = 0; i < 16; i++) {
                        if (x >= screen_x[i] && x - screen_x[i] < screen_w[i]) {
                            float r = screen_w[i] / screen_mm[i] * 25.4;
                            if (r != radius) {
                                radius = r;
                            }
                            break;
                        }
                    }
                    width = xev->width;
                    height = xev->height;
                }

    Getting closer. The numbers we need come from the X server.

        XRRScreenResources *res = XRRGetScreenResourcesCurrent(disp, root);
        float screen_mm[16] = { 0 };
        float screen_w[16] = { 0 };
        float screen_x[16] = { 0 };
        int j = 0;
        for (int i = 0; i < res->noutput; i++) {
            XRROutputInfo *info = XRRGetOutputInfo(disp, res, res->outputs[i]);
            screen_mm[j++] = info->mm_width;
        }
        j = 0;
        for (int i = 0; i < res->ncrtc; i++) {
            XRRCrtcInfo *info = XRRGetCrtcInfo(disp, res, res->crtcs[i]);
            screen_w[j] = info->width;
            screen_x[j++] = info->x;
        }

    It’s somewhat annoying that physical width and virtual width are in different structures, and we have to put the puzzle back together, but there it is.

    Some more code to handle expose events, the draw loop, etc., and that’s it. A beautiful circle sized just right. Drag it over onto the next monitor, and it changes size. Or rather, it maintains its size. Send it over to the next monitor, and same as before.

    Time for the visual proof. A nice pretty circle on my laptop. Another circle on my monitor. And despite the 4K resolution, a somewhat pixely circle on my TV. Turns out the hardest part of this adventure was trying to hold an uncooperative tape measure in place with one hand while trying to get a decent, or not, photo with the other.

    We were so close to perfection. Somebody at the factory screwed up, and my TV is actually 66.5” wide, not the claimed 63 inches. So if we learn anything today, it’s that you shouldn’t use a consumer LG TV for accurately measuring the scale of structural engineering diagrams, at least not without further calibration.

    The good news is we’ve done the impossible. Even better, I didn’t mention that I wasn’t actually running this program on my laptop. It was running on my router in another room, but everything worked as if by MIT-MAGIC-COOKIE-1. Alas, we are still no closer to understanding why people say this is impossible.

    Anyway, I think the point is we should probably ignore the people who can’t do something when they tell us we can’t do it either. I woke up this morning not knowing precisely how to draw a scaled circle, having never done so before, but armed with a vague sense that surely it must be possible, because come on of course it is, I got it working. And now look at me, driven insane by the relentless stare of three unblinking eyes.

    With my new knowledge, I also wrote an onscreen ruler using the shape extension. Somewhat tautological for measuring the two inch circle, but in the event anyone asks, I can now tell them my terminal line height is 1/8”, and yes, I measured.

    Posted 24 Jun 2025 17:59 by tedu Updated: 24 Jun 2025 17:59

    Tagged: programming x11

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleBridging Cinematic Principles and Generative AI for Automated Film Generation
    Next Article Roland just released a weird little riff on an acoustic handpan
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Don’t toss your Windows 10 PC! Try switching to KDE Plasma instead

    June 25, 2025

    Windows 10 gets an extra year of free security updates (with a catch)

    June 25, 2025

    Philps Hue smart lights are already pricey. They’re about to get pricier

    June 25, 2025
    Leave A Reply Cancel Reply

    Top Posts

    New Akira ransomware decryptor cracks encryptions keys using GPUs

    March 16, 202525 Views

    OpenAI details ChatGPT-o3, o4-mini, o4-mini-high usage limits

    April 19, 202521 Views

    Rsync replaced with openrsync on macOS Sequoia

    April 7, 202515 Views

    Arizona moves to ban AI use in reviewing medical claims

    March 12, 202511 Views
    Don't Miss
    Technology June 25, 2025

    Don’t toss your Windows 10 PC! Try switching to KDE Plasma instead

    Don’t toss your Windows 10 PC! Try switching to KDE Plasma instead Image: KDE Come…

    Windows 10 gets an extra year of free security updates (with a catch)

    Philps Hue smart lights are already pricey. They’re about to get pricier

    Amazon’s Fire TV Stick 4K drops to its best price of the year

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Don’t toss your Windows 10 PC! Try switching to KDE Plasma instead

    June 25, 20250 Views

    Windows 10 gets an extra year of free security updates (with a catch)

    June 25, 20250 Views

    Philps Hue smart lights are already pricey. They’re about to get pricier

    June 25, 20250 Views
    Most Popular

    Ethereum must hold $2,000 support or risk dropping to $1,850 – Here’s why

    March 12, 20250 Views

    Xiaomi 15 Ultra Officially Launched in China, Malaysia launch to follow after global event

    March 12, 20250 Views

    Apple thinks people won’t use MagSafe on iPhone 16e

    March 12, 20250 Views
    © 2025 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.