My conky config here:
Code: Select all
own_window yes
own_window_class Conky
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
Code: Select all
own_window yes
own_window_class Conky
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
Code: Select all
own_window yes
own_window_class conky
own_window_type dock
Code: Select all
own_window yes
own_window_type normal
own_window_title myconky
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
Code: Select all
sh -c 'wmctrl -k on; wmctrl -a myconky;'
Code: Select all
conky; sleep 3; conkier
Code: Select all
/*
compile with
gcc -o conkier conkier.c -L/usr/X11R6/lib -lX11 -I/usr/X11R6/include
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h> /* for sleep() */
#include<X11/keysym.h>
#include<X11/Xlib.h>
#include<X11/Xutil.h>
#include<X11/Xatom.h>
Window cw;
void help() {
fprintf(stdout, "usage: conkier [options]\r\n");
fprintf(stdout, "options:\r\n");
fprintf(stdout, "-h,--help Show this help.\r\n");
}
// ERROR HANDLER, GENERIC
static int ErrorHandler (Display *display, XErrorEvent *error)
{
fprintf(stderr, "Error handler triggered.\r\n");
return(0);
}
// ENUMARATE THROUGH WINDOWS AND DISPLAY THEIR TITLES
enumwin(Display *dpy, Window rootwin, char *sstr)
{
static int level = 0;
Window parent;
Window *children;
unsigned int noOfChildren;
int status;
int i;
XTextProperty wmName;
char **list;
status = XGetWMName (dpy, rootwin, &wmName);
if ((status) && (wmName.value) && (wmName.nitems))
{
status = XmbTextPropertyToTextList (dpy, &wmName, &list, &i);
if(strcmp(*list,sstr)==0)
{
// fprintf(stdout, "Found Conky window.\n");
// fprintf (stdout, "On level %i with id %02X. \r\n", level, (unsigned int)rootwin);
cw=rootwin;
free(list);
XFree((char*) children);
return;
}
}
level++;
status = XQueryTree (dpy, rootwin, &rootwin, &parent, &children, &noOfChildren);
for (i=0; i < noOfChildren; i++)
{
enumwin(dpy, children[i],sstr);
}
XFree((char*) children);
}
int main(int argc, char *argv[])
{
Display *dpy;
int screen;
Window rootwin=-1;
int status;
const char *name = "HOSTNAME";
char *hostname;
int i, len;
char *conkytitle;
char **list;
Atom net_showing_desktop_atom, net_active_window_atom, net_current_desktop_atom, net_wm_desktop_atom;
Atom actual_type;
int done=0;
int actual_format, current_nsd,previous_nsd;
unsigned long nitems, after;
unsigned char *data = NULL;
int current_screen, previous_screen;
for(i=0; i<argc; i++) {
if(strcmp(argv[i],"--help")==0||strcmp(argv[i],"-h")==0) {
help();
exit(EXIT_SUCCESS);
}
}
if(argv[1]) {
conkytitle=argv[1];
fprintf(stdout, "Conky title given: '%s'.\r\n", conkytitle);
} else {
hostname=(char *) malloc(100*sizeof(char));
if(hostname==NULL)
{
fprintf(stderr, "Failed to allocate memory for hostname retrieval.\r\nStop.\r\n");
exit(EXIT_FAILURE);;
}
status=gethostname(hostname,100);
conkytitle=(char *) malloc((10+strlen(hostname))*sizeof(char));
if(conkytitle==NULL)
{
fprintf(stderr, "Failed to allocate memory to guess conky window title.\r\nStop.\r\n");
exit(EXIT_FAILURE);
}
strncpy(conkytitle,"Conky (",7);
strncat(conkytitle,hostname,strlen(hostname));
strncat(conkytitle,")",1);
free(hostname);
fprintf(stdout, "Presumed conky title: '%s'.\r\n", conkytitle);
}
dpy=XOpenDisplay(NULL);
if(dpy==NULL)
{
fprintf(stderr,"Failed to open display. Stop.\r\n");
exit(EXIT_FAILURE);
}
XSetErrorHandler(ErrorHandler);
screen=DefaultScreen(dpy);
rootwin=RootWindow(dpy, screen);
if(rootwin==-1)
{
fprintf(stderr,"Failed to obtain root window. Stop.\r\n");
exit(EXIT_FAILURE);
}
// LOOP THROUGH ALL WINDOWS
cw=-1;
enumwin(dpy, rootwin, conkytitle);
if(cw!=-1)
{
fprintf(stdout, "Conky window id %02X. \r\n", (unsigned int) cw);
} else
{
fprintf(stderr, "No conky window with title '%s' found. Stop.\r\n", conkytitle);
exit(EXIT_FAILURE);
}
net_showing_desktop_atom = XInternAtom(dpy, "_NET_SHOWING_DESKTOP", False);
net_active_window_atom = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
net_current_desktop_atom = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False);
net_wm_desktop_atom = XInternAtom(dpy, "_NET_WM_DESKTOP", False);
current_nsd=-1;
current_screen=DefaultScreen(dpy);
/* Initialize Xevent struct */
XEvent xev = {
.xclient = {
.type=ClientMessage,
.send_event=True,
.display=dpy,
.window=cw,
.message_type=net_active_window_atom,
.format=32,
.data.l[0]=!current_nsd /* ThatÂ’s what we want the new state to be */
}
};
/* Obtain the current state of _NET_SHOWING_DESKTOP on the default root window */
while(!done)
{
//1st check if conky has been minimised together with all other windows
status = XGetWindowProperty(dpy, rootwin, net_showing_desktop_atom, 0, 1, False, XA_CARDINAL, &actual_type, &actual_format, &nitems, &after, &data);
if(status!=Success) {
fprintf(stderr, "Received error %d.\n", status);
}
/* The current state should be in data[0] */
if(data) {
previous_nsd=current_nsd;
current_nsd=data[0];
XFree(data);
data=NULL;
}
if(!nitems) {
fprintf(stderr, "Unexpected result.\r\n");
fprintf(stderr, "Assuming unshown desktop.\r\n");
current_nsd=-1;
}
if(current_nsd==1 && cw!=-1) {
xev.xclient.message_type=net_active_window_atom;
xev.xclient.data.l[0]=!current_nsd;
XSendEvent(dpy, rootwin, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
}
// Now check if desktop has been changed
status = XGetWindowProperty(dpy, rootwin, net_current_desktop_atom, 0, 1, False, XA_CARDINAL, &actual_type, &actual_format, &nitems, &after, &data);
if(status!=Success) {
fprintf(stderr, "Received error %d.\n", status);
}
/* The current state should be in data[0] */
if(data) {
previous_screen=current_screen;
current_screen=data[0];
XFree(data);
data=NULL;
}
if(!nitems) {
fprintf(stderr, "Unexpected result.\r\n");
fprintf(stderr, "Assuming unshown desktop.\r\n");
current_screen=-1;
}
if(previous_screen!=current_screen && current_screen!=-1){
// fprintf(stderr,"Desktop changed.\n");
xev.xclient.message_type=net_wm_desktop_atom;
xev.xclient.data.l[0]=current_screen;
XSendEvent(dpy, rootwin, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
}
usleep(100000);
}
XCloseDisplay(dpy);
free(conkytitle);
exit(EXIT_SUCCESS);
}