Skip to content

Instantly share code, notes, and snippets.

@mid-kid
Last active January 1, 2024 23:00
Show Gist options
  • Select an option

  • Save mid-kid/c4eae19b20d251d2b55008e42998180f to your computer and use it in GitHub Desktop.

Select an option

Save mid-kid/c4eae19b20d251d2b55008e42998180f to your computer and use it in GitHub Desktop.

Revisions

  1. mid-kid revised this gist Jan 1, 2024. No changes.
  2. mid-kid created this gist Jan 1, 2024.
    20 changes: 20 additions & 0 deletions checktray.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #include <stdlib.h>
    #include <stdio.h>
    #include <X11/Xlib.h>

    // Simple program to check for the presence of an Xembed tray
    // Exits with status 0 if the tray exists

    int main()
    {
    Display *d = XOpenDisplay(NULL);
    if (!d) { fprintf(stderr, "XOpenDisplay failed\n"); return EXIT_FAILURE; }

    Atom a = XInternAtom(d, "_NET_SYSTEM_TRAY_S0", False);
    if (a == None) { fprintf(stderr, "XInternAtom failed\n"); return EXIT_FAILURE; }

    Window w = XGetSelectionOwner(d, a);
    if (w == None) { fprintf(stderr, "XGetSelectionOwner failed\n"); return EXIT_FAILURE; }

    return EXIT_SUCCESS;
    }