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