Here is the corresponding part of my config.h:

/* Internal keyboard shortcuts. */
#define MODKEY Mod1Mask
#define TERMMOD (ControlMask|ShiftMask)

static Shortcut shortcuts[] = {
    /* mask                 keysym          function        argument */
    { XK_ANY_MOD,           XK_Break,       sendbreak,      {.i =  0} },
    { ControlMask,          XK_Print,       toggleprinter,  {.i =  0} },
    { ShiftMask,            XK_Print,       printscreen,    {.i =  0} },
    { XK_ANY_MOD,           XK_Print,       printsel,       {.i =  0} },
    { TERMMOD,              XK_Prior,       zoom,           {.f = +1} },
    { TERMMOD,              XK_Next,        zoom,           {.f = -1} },
    { TERMMOD,              XK_Home,        zoomreset,      {.f =  0} },
    { TERMMOD,              XK_C,           clipcopy,       {.i =  0} },
    { TERMMOD,              XK_V,           clippaste,      {.i =  0} },
    { TERMMOD,              XK_Y,           selpaste,       {.i =  0} },
    { TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },

Now, what is the purpose of the column argument?


The address of the argument in the fourth column is passed to the function listed in the third column. For example, note how the zoom() function is listed twice under different arguments for different shortcuts.

The Shortcut data type that makes up the shortcuts[] array in your question is defined in x.c as a struct of four members:

typedef struct {
    uint mod;
    KeySym keysym;
    void (*func)(const Arg *);
    const Arg arg;
} Shortcut;

The last member of Shortcut, Arg, is defined in st.h as a union of four:

typedef union {
    int i;
    uint ui;
    float f;
    const void *v;
} Arg;

An example of func from a Shortcut getting called with the address of the union member from the struct happens in keypress() from x.c, where bp points to a Shortcut:

if (ksym == bp->keysym && match(bp->mod, e->state)) {

A concrete example of leveraging this setup can be seen in zoom() where the float in the Arg union is used. From the configuration in your question, arg->f in this function can be +1 or -1 to grow or shrink the font size:

zoom(const Arg *arg)
    Arg larg;

    larg.f = usedfontsize + arg->f;
| improve this answer | |
  • 1
    Yes, after asking the question I went to look into the source code and it's pretty simple. Thanks. – klaus Nov 4 '18 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.