Cosmetics...
This commit is contained in:
parent
1bf8ddf418
commit
c6797e16b9
2 changed files with 17 additions and 15 deletions
2
Makefile
2
Makefile
|
|
@ -1,5 +1,5 @@
|
|||
all:
|
||||
gcc -o texec texec.c -lX11 -lpng
|
||||
gcc -Wall -o texec texec.c -lX11 -lpng
|
||||
|
||||
clean:
|
||||
rm -rf texec
|
||||
|
|
|
|||
30
texec.c
30
texec.c
|
|
@ -1,30 +1,29 @@
|
|||
/*
|
||||
* texec.c - Minimal X11 tray applet with mandatory PNG icon (32x32)
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* .c - Minimal X11 tray applet with mandatory PNG icon (32x32)
|
||||
*
|
||||
* Compile:
|
||||
* gcc -o gexec_xembed gexec_xembed.c -lX11 -lXrender -lpng
|
||||
* gcc -o texec.c -lX11 -lpng
|
||||
*
|
||||
* Usage:
|
||||
* ./gexec_xembed "<command>" <icon.png>
|
||||
* ./texec "<command>" <icon.png>
|
||||
*
|
||||
* Left-click: execute command
|
||||
* Right-click: quit applet
|
||||
*/
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
//#include <X11/extensions/Xrender.h>
|
||||
#include <png.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#define WIDTH 24
|
||||
#define HEIGHT 24
|
||||
|
|
@ -32,14 +31,14 @@
|
|||
static Display *dpy;
|
||||
static int screen;
|
||||
static Window icon_win;
|
||||
static char *g_command;
|
||||
static char *x_command;
|
||||
|
||||
void execute_command() {
|
||||
if (!g_command) return;
|
||||
if (!x_command) return;
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
setsid();
|
||||
execl("/bin/sh", "sh", "-c", g_command, (char *)NULL);
|
||||
execl("/bin/sh", "sh", "-c", x_command, (char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
}
|
||||
|
|
@ -112,7 +111,7 @@ int main(int argc, char *argv[]) {
|
|||
fprintf(stderr,"Usage: %s <command> <icon.png>\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
g_command = argv[1];
|
||||
x_command = argv[1];
|
||||
char *icon_path = argv[2];
|
||||
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
|
|
@ -158,8 +157,11 @@ int main(int argc, char *argv[]) {
|
|||
if (xev.xany.window == icon_win) {
|
||||
if (xev.type == Expose) draw_icon(icon_win, icon_path);
|
||||
else if (xev.type == ButtonPress) {
|
||||
if (xev.xbutton.button == 1) execute_command(); // left-click
|
||||
else if (xev.xbutton.button == 3) break; // right-click: quit
|
||||
if (xev.xbutton.button == 1) {
|
||||
execute_command(); // left-click
|
||||
} else if (xev.xbutton.button == 3) {
|
||||
break; // right-click: quit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue