config.def.c (13042B)
1 /* See LICENSE file for license details. */ 2 #include <stdint.h> 3 #include <stdlib.h> 4 #include <wchar.h> 5 #include <X11/Xlib.h> 6 #include <X11/cursorfont.h> 7 #include <X11/keysym.h> 8 9 #include "util.h" 10 #include "config.h" 11 #include "st.h" 12 #include "win.h" 13 14 static void clipcopy(uint, Arg); 15 static void clippaste(uint, Arg); 16 static void selpaste(uint, Arg); 17 static void zoomrel(uint, Arg); 18 static void zoomrst(uint, Arg); 19 static void numlock(uint, Arg); 20 static void sendstr(uint, Arg); 21 static void sendcsi(uint, Arg); 22 static void printscreen(uint, Arg); 23 static void selprint(uint, Arg); 24 static void sendbreak(uint, Arg); 25 static void togprinter(uint, Arg); 26 27 /* See: http://freedesktop.org/software/fontconfig/fontconfig-user.html */ 28 char *font = "monospace:pixelsize=32:antialias=true:autohint=true"; 29 int borderpx = 2; 30 /* Kerning / character bounding-box multipliers */ 31 float cwscale = 1.0; 32 float chscale = 1.0; 33 34 /* What program is execed by st depends of these precedence rules: 35 * 1: program passed with -e 36 * 2: scroll and/or utmp 37 * 3: SHELL environment variable 38 * 4: user shell in /etc/passwd 39 * 5: shell in config.c */ 40 char *shell = "/bin/sh"; 41 char *utmp = 0; 42 /* scroll program: to enable use a string like "scroll" */ 43 char *scroll = 0; 44 char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; 45 46 /* identification sequence returned in DA and DECID */ 47 char *vtiden = "\033[?6c"; 48 49 wchar_t *worddelimiters = L" "; /* E.g., L" `'\"()[]{}" */ 50 51 /* selection timeouts (in milliseconds) */ 52 uint doubleclicktimeout = 300; 53 uint tripleclicktimeout = 600; 54 55 int allowaltscreen = 1; 56 57 /* allow certain non-interactive (insecure) window operations, such as 58 setting the clipboard text */ 59 int allowwindowops = 0; 60 61 /* draw latency range in ms - from new content/keypress/etc until drawing. 62 * within this range, st draws when content stops arriving (idle). mostly it's 63 * near minlatency, but it waits longer for slow updates to avoid partial draw. 64 * low minlatency will tear/flicker more, as it can "detect" idle too early. */ 65 double minlatency = 8; 66 double maxlatency = 33; 67 68 /* blinking timeout (set to 0 to disable blinking) for the terminal blinking 69 * attribute. */ 70 uint blinktimeout = 800; 71 72 /* thickness of underline and bar cursors */ 73 uint cursorthickness = 2; 74 75 /* bell volume. It must be a value between -100 and 100. 76 * Use 0 to disable it. */ 77 int bellvolume = 0; 78 79 char *termname = "st-256color"; 80 81 /* spaces per tab 82 * When you are changing this value, don't forget to adapt the »it« value in 83 * the st.info and appropriately install the st.info in the environment where 84 * you use this st version. 85 * Secondly make sure your kernel is not expanding tabs. When running 86 * `stty -a`, »tab0« should appear. You can tell the terminal to not expand 87 * tabs by running `stty tabs`. */ 88 uint tabspaces = 4; 89 90 /* Terminal colors (16 first used in escape sequence) */ 91 const char *colorname[] = { 92 /* 8 normal colors */ 93 "black", 94 "red3", 95 "green3", 96 "yellow3", 97 "blue2", 98 "magenta3", 99 "cyan3", 100 "gray90", 101 102 /* 8 bright colors */ 103 "gray50", 104 "red", 105 "green", 106 "yellow", 107 "#5c5cff", 108 "magenta", 109 "cyan", 110 "white", 111 112 [255] = 0, 113 114 /* more colors can be added after 255 to use with defaultXX */ 115 "#f8f8f2", 116 "#1c1c1c", 117 "#cccccc", 118 "#555555", 119 0, 120 }; 121 122 /* Default colors (colorname index) 123 * foreground, background, cursor, reverse cursor */ 124 uint defaultfg = 256; 125 uint defaultbg = 257; 126 uint defaultcs = 258; 127 uint defaultrcs = 259; 128 129 /* Default shape of cursor 130 * 2: Block ("█") 131 * 4: Underline ("_") 132 * 6: Bar ("|") 133 * 7: Snowman ("☃") */ 134 uint cursorshape = 2; 135 136 uint cols = 80; 137 uint rows = 24; 138 139 /* Default colour and shape of the mouse cursor */ 140 uint mouseshape = XC_xterm; 141 uint mousefg = 7; 142 uint mousebg = 0; 143 144 /* Color used to display font attributes when fontconfig selected a font which 145 * doesn't match the ones requested. */ 146 uint defaultattr = 11; 147 148 #define R RELS 149 #define S SHFT 150 #define C CTRL 151 #define A ALT 152 #define TERMMOD (CTRL|SHFT) 153 #define SENDSTR(s_) sendstr, .arg = ARG_STR((s_)) 154 #define SENDCSI(n,m,c) sendcsi, .arg = ARG_CSI((n),(m),(c)) 155 #define SENDTILDE(n) SENDCSI((n),0,'~') 156 #define SENDUNICODE(cp) SENDCSI((cp),S,'u') 157 #define ARG_DUMMY {.i = 0} 158 159 /* Beware that overloading Button1 will disable the selection. */ 160 Btn btns[] = { 161 { Button2, R, 0, selpaste, ARG_DUMMY }, 162 { Button4, S, KEXCL(S)|R, SENDSTR("\033[5;2~") }, 163 { Button4, 0, R, SENDSTR("\031") }, 164 { Button5, S, KEXCL(S)|R, SENDSTR("\033[6;2~") }, 165 { Button5, 0, R, SENDSTR("\005") }, 166 { 0 }, 167 }; 168 169 /* TODO: add RELS to clr */ 170 Key keys[] = { 171 /* Shortcuts (must be first to get precedence) */ 172 { XK_Home, TERMMOD, KEXCL(TERMMOD)|R, zoomrst, ARG_DUMMY }, 173 { XK_Prior, TERMMOD, KEXCL(TERMMOD)|R, zoomrel, {.d = +1} }, 174 { XK_Next, TERMMOD, KEXCL(TERMMOD)|R, zoomrel, {.d = -1} }, 175 { XK_Print, C, KEXCL(C)|R, togprinter, ARG_DUMMY }, 176 { XK_Print, S, KEXCL(S)|R, printscreen, ARG_DUMMY }, 177 { XK_Print, 0, R, selprint, ARG_DUMMY }, 178 { XK_Insert, S, KEXCL(S)|R, selpaste, ARG_DUMMY }, 179 { XK_Break, 0, R, sendbreak, ARG_DUMMY }, 180 { XK_Num_Lock, TERMMOD, KEXCL(TERMMOD)|R, numlock, ARG_DUMMY }, 181 { XK_C, TERMMOD, KEXCL(TERMMOD)|R, clipcopy, ARG_DUMMY }, 182 { XK_V, TERMMOD, KEXCL(TERMMOD)|R, clippaste, ARG_DUMMY }, 183 { XK_Y, TERMMOD, KEXCL(TERMMOD)|R, selpaste, ARG_DUMMY }, 184 185 /* ASCII special cases (handlesym handles most cases already) */ 186 { XK_space, S, R, SENDCSI(' ',0,'u') }, 187 { XK_space, C, KEXCL(C)|R, SENDSTR("\0") }, 188 { XK_space, C|A, KEXCL(C|A)|R, SENDSTR("\033\0") }, 189 { XK_O, A, R, SENDUNICODE('O') }, /* ESC O is SS3 */ 190 { XK_i, C, R, SENDUNICODE('i') }, /* 'i'-0x60 is tab */ 191 { XK_m, C, R, SENDUNICODE('m') }, /* 'm'-0x60 is CR */ 192 { XK_bracketleft, A, R, SENDUNICODE('[') }, /* ESC [ is CSI */ 193 194 /* Misc */ 195 { XK_BackSpace, 0, KMOD|R, SENDSTR("\177") }, 196 { XK_BackSpace, A, KEXCL(A)|R, SENDSTR("\033\177") }, 197 { XK_BackSpace, 0, R, SENDCSI(127,0,'u') }, 198 { XK_Tab, 0, KMOD|R, SENDSTR("\t") }, 199 { XK_Tab, A, KEXCL(A)|R, SENDSTR("\033\t") }, 200 { XK_Tab, S, R, SENDCSI(1,S,'Z') }, 201 { XK_Tab, 0, R, SENDCSI('\t',0,'u') }, 202 { XK_Return, 0, KMOD|R, SENDSTR("\r") }, 203 { XK_Return, A, KEXCL(A)|R, SENDSTR("\033\r") }, 204 { XK_Return, 0, R, SENDCSI('\r',0,'u') }, 205 { XK_Escape, 0, KMOD|R, SENDSTR("\033") }, 206 { XK_Escape, A, KEXCL(A)|R, SENDSTR("\033\033") }, 207 { XK_Escape, 0, R, SENDCSI(27,0,'u') }, 208 { XK_Delete, 0, R, SENDTILDE(3) }, 209 { XK_Home, CURS, KMOD|R, SENDSTR("\033OH") }, 210 { XK_Home, 0, R, SENDCSI(1,0,'H') }, 211 { XK_Left, CURS, KMOD|R, SENDSTR("\033OD") }, 212 { XK_Left, 0, R, SENDCSI(1,0,'D') }, 213 { XK_Up, CURS, KMOD|R, SENDSTR("\033OA") }, 214 { XK_Up, 0, R, SENDCSI(1,0,'A') }, 215 { XK_Right, CURS, KMOD|R, SENDSTR("\033OC") }, 216 { XK_Right, 0, R, SENDCSI(1,0,'C') }, 217 { XK_Down, CURS, KMOD|R, SENDSTR("\033OB") }, 218 { XK_Down, 0, R, SENDCSI(1,0,'B') }, 219 { XK_Prior, 0, R, SENDTILDE(5) }, 220 { XK_Next, 0, R, SENDTILDE(6) }, 221 { XK_End, CURS, KMOD|R, SENDSTR("\033OF") }, 222 { XK_End, 0, R, SENDCSI(1,0,'F') }, 223 { XK_Begin, 0, R, SENDCSI(1,0,'E') }, 224 { XK_Select, 0, R, SENDTILDE(4) }, 225 { XK_Insert, 0, R, SENDTILDE(2) }, 226 { XK_Find, 0, R, SENDTILDE(1) }, 227 228 /* Keypad */ 229 { XK_KP_Enter, KPAD, NMLK|KMOD|R, SENDSTR("\033OM") }, 230 { XK_KP_Enter, 0, KMOD|R, SENDSTR("\r") }, 231 { XK_KP_Enter, A, KEXCL(A)|R, SENDSTR("\033\r") }, 232 { XK_KP_Enter, 0, R, SENDCSI('\r',0,'u') }, 233 { XK_KP_F1, 0, KMOD|R, SENDSTR("\033OP") }, 234 { XK_KP_F1, 0, R, SENDCSI(1,0,'P') }, 235 { XK_KP_F2, 0, KMOD|R, SENDSTR("\033OQ") }, 236 { XK_KP_F2, 0, R, SENDCSI(1,0,'Q') }, 237 { XK_KP_F3, 0, KMOD|R, SENDSTR("\033OR") }, 238 { XK_KP_F3, 0, R, SENDCSI(1,0,'R') }, 239 { XK_KP_F4, 0, KMOD|R, SENDSTR("\033OS") }, 240 { XK_KP_F4, 0, R, SENDCSI(1,0,'S') }, 241 { XK_KP_Home, CURS, KMOD|R, SENDSTR("\033OH") }, 242 { XK_KP_Home, 0, R, SENDCSI(1,0,'H') }, 243 { XK_KP_Left, CURS, KMOD|R, SENDSTR("\033OD") }, 244 { XK_KP_Left, 0, R, SENDCSI(1,0,'D') }, 245 { XK_KP_Up, CURS, KMOD|R, SENDSTR("\033OA") }, 246 { XK_KP_Up, 0, R, SENDCSI(1,0,'A') }, 247 { XK_KP_Right, CURS, KMOD|R, SENDSTR("\033OC") }, 248 { XK_KP_Right, 0, R, SENDCSI(1,0,'C') }, 249 { XK_KP_Down, CURS, KMOD|R, SENDSTR("\033OB") }, 250 { XK_KP_Down, 0, R, SENDCSI(1,0,'B') }, 251 { XK_KP_Prior, 0, R, SENDTILDE(5) }, 252 { XK_KP_Next, 0, R, SENDTILDE(6) }, 253 { XK_KP_End, CURS, KMOD|R, SENDSTR("\033OF") }, 254 { XK_KP_End, 0, R, SENDCSI(1,0,'F') }, 255 { XK_KP_Begin, 0, R, SENDCSI(1,0,'E') }, 256 { XK_KP_Insert, 0, R, SENDTILDE(2) }, 257 { XK_KP_Delete, 0, R, SENDTILDE(3) }, 258 { XK_KP_Equal, KPAD, NMLK|KMOD|R, SENDSTR("\033OX") }, 259 { XK_KP_Multiply, KPAD, NMLK|KMOD|R, SENDSTR("\033Oj") }, 260 { XK_KP_Add, KPAD, NMLK|KMOD|R, SENDSTR("\033Ok") }, 261 { XK_KP_Separator, KPAD, NMLK|KMOD|R, SENDSTR("\033Ol") }, 262 { XK_KP_Subtract, KPAD, NMLK|KMOD|R, SENDSTR("\033Om") }, 263 { XK_KP_Decimal, KPAD, NMLK|KMOD|R, SENDSTR("\033On") }, 264 { XK_KP_Divide, KPAD, NMLK|KMOD|R, SENDSTR("\033Oo") }, 265 { XK_KP_0, KPAD, NMLK|KMOD|R, SENDSTR("\033Op") }, 266 { XK_KP_1, KPAD, NMLK|KMOD|R, SENDSTR("\033Oq") }, 267 { XK_KP_2, KPAD, NMLK|KMOD|R, SENDSTR("\033Or") }, 268 { XK_KP_3, KPAD, NMLK|KMOD|R, SENDSTR("\033Os") }, 269 { XK_KP_4, KPAD, NMLK|KMOD|R, SENDSTR("\033Ot") }, 270 { XK_KP_5, KPAD, NMLK|KMOD|R, SENDSTR("\033Ou") }, 271 { XK_KP_6, KPAD, NMLK|KMOD|R, SENDSTR("\033Ov") }, 272 { XK_KP_7, KPAD, NMLK|KMOD|R, SENDSTR("\033Ow") }, 273 { XK_KP_8, KPAD, NMLK|KMOD|R, SENDSTR("\033Ox") }, 274 { XK_KP_9, KPAD, NMLK|KMOD|R, SENDSTR("\033Oy") }, 275 276 /* Function */ 277 { XK_F1, 0, R, SENDTILDE(11) }, 278 { XK_F2, 0, R, SENDTILDE(12) }, 279 { XK_F3, 0, R, SENDTILDE(13) }, 280 { XK_F4, 0, R, SENDTILDE(14) }, 281 { XK_F5, 0, R, SENDTILDE(15) }, 282 { XK_F6, 0, R, SENDTILDE(17) }, 283 { XK_F7, 0, R, SENDTILDE(18) }, 284 { XK_F8, 0, R, SENDTILDE(19) }, 285 { XK_F9, 0, R, SENDTILDE(20) }, 286 { XK_F10, 0, R, SENDTILDE(21) }, 287 { XK_F11, 0, R, SENDTILDE(23) }, 288 { XK_F12, 0, R, SENDTILDE(24) }, 289 { XK_F13, 0, R, SENDTILDE(25) }, 290 { XK_F14, 0, R, SENDTILDE(26) }, 291 { XK_F15, 0, R, SENDTILDE(28) }, 292 { XK_F16, 0, R, SENDTILDE(29) }, 293 { XK_F17, 0, R, SENDTILDE(31) }, 294 { XK_F18, 0, R, SENDTILDE(32) }, 295 { XK_F19, 0, R, SENDTILDE(33) }, 296 { XK_F20, 0, R, SENDTILDE(34) }, 297 /* libtermkey only recognizes up to F20. */ 298 299 { 0 }, 300 }; 301 302 SelType seltypes[] = { 303 { SEL_RECTANGULAR, A, KEXCL(A) }, 304 /* If no match is found, regular selection is used. */ 305 { 0 }, 306 }; 307 308 uint 309 confstate(uint xstate, int rels) 310 { 311 uint winmode; 312 313 winmode = xgetmode(); 314 return (winmode&MODE_APPCURSOR ? CURS : 0) 315 | (winmode&MODE_APPKEYPAD ? KPAD : 0) 316 | (winmode&MODE_NUMLOCK ? NMLK : 0) 317 | (rels ? RELS : 0) 318 | (xstate << MODOFFS); 319 } 320 321 void 322 clipcopy(uint state, Arg arg) 323 { xclipcopy(); } 324 325 void 326 clippaste(uint state, Arg arg) 327 { xclippaste(); } 328 329 void 330 selpaste(uint state, Arg arg) 331 { xselpaste(); } 332 333 void 334 zoomrel(uint state, Arg arg) 335 { xzoomrel(arg.d); } 336 337 void 338 zoomrst(uint state, Arg arg) 339 { xzoomrst(); } 340 341 void 342 numlock(uint state, Arg arg) 343 { xtogmode(MODE_NUMLOCK); } 344 345 void 346 sendstr(uint state, Arg arg) 347 { ttywrite(arg.str.s, arg.str.l, 1); } 348 349 void 350 sendcsi(uint state, Arg arg) 351 { 352 char buf[64]; 353 size_t len; 354 355 len = csienc(buf, sizeof buf, state, arg.csi.n, arg.csi.m, arg.csi.c); 356 ttywrite(buf, len, 1); 357 } 358 359 void 360 printscreen(uint state, Arg arg) 361 { tdump(); } 362 363 void 364 selprint(uint state, Arg arg) 365 { tdumpsel(); } 366 367 void 368 sendbreak(uint state, Arg arg) 369 { tsendbreak(); } 370 371 void 372 togprinter(uint state, Arg arg) 373 { ttogprinter(); }