Skip to content

Instantly share code, notes, and snippets.

@aperezdc
Created October 21, 2012 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aperezdc/3926717 to your computer and use it in GitHub Desktop.
Save aperezdc/3926717 to your computer and use it in GitHub Desktop.
Launch separate Emacs process for Notmuch UI with own appname+icon, works with GNOME Shell
#! /bin/bash
#
# Copyright (C) 2012 Adrian Perez <aperez@igalia.com>
# Distributed under terms of the MIT license.
#
# Install as:
# ~/.local/bin/notmuch-launch
# Dependencies:
# wmctrl (http://tomas.styblo.name/wmctrl)
# xsetclasshint program
# Emacs with X-Window systems support
# Notmuch Emacs UI that works with "emacs -f notmuch"
#
PATH="${PATH}:${HOME}/.local/bin"
export PATH
emacs --name Notmuch --no-splash -f notmuch &
tries=10
windowid=''
while [[ -z ${windowid} && ${tries} -gt 0 ]] ; do
sleep 0.75
while read -a wmline ; do
if [[ ${wmline[2]} = Notmuch.Emacs ]] ; then
windowid=${wmline[0]}
fi
done < <( wmctrl -l -x )
(( tries-- ))
done
if [[ -n ${windowid} ]] ; then
xsetclasshint ${windowid} Notmuch Notmuch
fi
[Desktop Entry]
Name=Notmuch
GenericName=Mail reader and indexer
Comment=Edit text
Exec=/home/user/.local/bin/notmuch-launch
Icon=evolution
Type=Application
Terminal=false
Categories=Internet;Email;
StartupWMClass=Notmuch
#
# Usage:
#
# Create the ~/.local.share/applications/ directory if needed
# Copy to ~/.local/share/applications/notmuch.desktop
# Edit the "Exec=" line to point to the location of notmuch-launch
#
/*
* xsetclasshint.c
* Copyright (C) 2012 Adrian Perez <aperez@igalia.com>
* Distributed under terms of the MIT license.
*
* Build with:
* cc -o xsetclasshint xsetclasshint.c `pkg-config x11 --libs`
*
* Install compiled program to:
* ~/.local/bin/xsetclasshint
*/
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <errno.h>
int
main (int argc, char **argv)
{
XClassHint hint = { NULL, NULL };
Display *disp = NULL;
Window w = 0x0;
if (argc != 4)
{
fprintf (stderr,
"Usage: %s window-id window-name window-class\n",
argv[0]);
exit (EXIT_FAILURE);
}
if ((w = (Window) strtoul (argv[1], NULL, 0)) == ULONG_MAX &&
errno == ERANGE)
{
fprintf (stderr, "%s: window-id '%s' invalid\n", argv[0], argv[1]);
exit (EXIT_FAILURE);
}
if ((disp = XOpenDisplay (NULL)) == NULL)
{
fprintf (stderr, "%s: Could not open X display\n", argv[0]);
exit (EXIT_FAILURE);
}
hint.res_name = argv[2];
hint.res_class = argv[3];
XSetClassHint (disp, w, &hint);
XCloseDisplay (disp);
return EXIT_SUCCESS;;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment