diff options
author | B. Watson <urchlay@slackware.uk> | 2024-01-10 12:54:54 -0500 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-01-10 12:54:54 -0500 |
commit | 088c769de46c4c1540c96c8b48bf17e3b093e0f6 (patch) | |
tree | 65f8cf49806c419b9d9fa2ce958680e7bc303977 | |
parent | 695ba0c4fae1e4e2d1629d45fcb9540276deee65 (diff) | |
download | hcalc-088c769de46c4c1540c96c8b48bf17e3b093e0f6.tar.gz |
Switch window sizes without re-executing (leaks a bit though).
-rw-r--r-- | hcalc.h | 1 | ||||
-rw-r--r-- | images.c | 5 | ||||
-rw-r--r-- | input.c | 44 |
3 files changed, 17 insertions, 33 deletions
@@ -53,6 +53,7 @@ void button(int b, int x, int y); void complete_paste(unsigned char *s, int n); void send_current_display(void); void setup_x(void); +void free_pixmaps(void); void load_pixmaps(void); void process_input(); void load_config(void); @@ -38,6 +38,11 @@ Pixmap chars; char charmap[] = " 0123456789ABCDEF-x,.ro+"; int char_to_x[256]; +void free_pixmaps(void) { + if(face) XFreePixmap(display, face); + if(chars) XFreePixmap(display, chars); +} + void load_pixmaps(void) { int i, c; @@ -430,49 +430,27 @@ void key(char c) { exit(0); case 'z': - { - /* dirty hack method of changing window size: - re-execute ourselves with appropriate argument. - TODO: see if this leaks memory, fds, etc */ - extern char *self; - char *args[4]; - - args[0] = self; - - switch (winsize) { - case 0: - args[1] = "-medium"; - break; - case 1: - args[1] = "-large"; - break; - case 2: - args[1] = "-small"; - break; - } - - args[2] = NULL; - - /* note that atexit() functions do NOT get called on execv() */ - save_config(); - - XCloseDisplay(display); - - execv(self, args); - } + winsize++; + if(winsize == 3) winsize = 0; + free_pixmaps(); + XCloseDisplay(display); + setup_x(); + load_pixmaps(); + show_value(); + break; } } static char *bmap[] = { - "PPPP\033", /* mouse copy and paste, CLR */ - "DHOB\010", /* DEC, HEX, OCT, BIN, DEL */ + "PPPP\033", /* mouse copy and paste, CLR */ + "DHOB\010", /* DEC, HEX, OCT, BIN, DEL */ "[]}<>", /* STO, RCL, SUM, <<, >> */ "Sdef/", /* SHF, D E F / */ "~abc*", /* INV, */ "|789-", /* OR, */ "&456+", /* AND, */ "^123=", /* XOR, */ - "u0._=" /* CE, 0, . , +/-, = */ + "u0._=" /* CE, 0, . , +/-, = */ }; void copy(void) { |