| 1 | /* |
|---|
| 2 | * neercs console-based window manager |
|---|
| 3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
|---|
| 4 | * 2008 Jean-Yves Lamoureux <jylam@lnxscene.org> |
|---|
| 5 | * All Rights Reserved |
|---|
| 6 | * |
|---|
| 7 | * $Id$ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software. It comes without any warranty, to |
|---|
| 10 | * the extent permitted by applicable law. You can redistribute it |
|---|
| 11 | * and/or modify it under the terms of the Do What The Fuck You Want |
|---|
| 12 | * To Public License, Version 2, as published by Sam Hocevar. See |
|---|
| 13 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #include <stdint.h> |
|---|
| 17 | #include <caca.h> |
|---|
| 18 | |
|---|
| 19 | enum wm_types |
|---|
| 20 | { |
|---|
| 21 | WM_FULL, |
|---|
| 22 | WM_CARD, |
|---|
| 23 | WM_HSPLIT, |
|---|
| 24 | WM_VSPLIT, |
|---|
| 25 | |
|---|
| 26 | WM_MAX, |
|---|
| 27 | }; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | struct screen |
|---|
| 31 | { |
|---|
| 32 | /* Graphics stuff */ |
|---|
| 33 | int init; |
|---|
| 34 | cucul_canvas_t *cv; |
|---|
| 35 | uint32_t clearattr; |
|---|
| 36 | uint8_t fg, bg; /* ANSI-context fg/bg */ |
|---|
| 37 | uint8_t dfg, dbg; /* Default fg/bg */ |
|---|
| 38 | uint8_t bold, blink, italics, negative, concealed, underline; |
|---|
| 39 | uint8_t faint, strike, proportional; /* unsupported */ |
|---|
| 40 | |
|---|
| 41 | /* Other stuff */ |
|---|
| 42 | int visible; |
|---|
| 43 | int fd; |
|---|
| 44 | unsigned char *buf; |
|---|
| 45 | char *title; |
|---|
| 46 | long int total; |
|---|
| 47 | int bell; |
|---|
| 48 | unsigned int scroll, s1, s2; |
|---|
| 49 | int pid; |
|---|
| 50 | |
|---|
| 51 | int kill_time; |
|---|
| 52 | |
|---|
| 53 | int x, y; |
|---|
| 54 | int w, h; |
|---|
| 55 | |
|---|
| 56 | int orig_x, orig_y; |
|---|
| 57 | int orig_w, orig_h; |
|---|
| 58 | |
|---|
| 59 | }; |
|---|
| 60 | |
|---|
| 61 | struct screen_list |
|---|
| 62 | { |
|---|
| 63 | int wm_type; |
|---|
| 64 | int in_bell; |
|---|
| 65 | int dont_update_coords; |
|---|
| 66 | /* Add-ons*/ |
|---|
| 67 | int mini; |
|---|
| 68 | int status; |
|---|
| 69 | int help; |
|---|
| 70 | |
|---|
| 71 | int pty, prevpty; |
|---|
| 72 | int count; |
|---|
| 73 | int width, height; |
|---|
| 74 | struct screen **screen; |
|---|
| 75 | }; |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | struct recurrent |
|---|
| 79 | { |
|---|
| 80 | int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t); |
|---|
| 81 | void *user; |
|---|
| 82 | long long unsigned int start_time; |
|---|
| 83 | int kill_me; |
|---|
| 84 | }; |
|---|
| 85 | |
|---|
| 86 | struct recurrent_list |
|---|
| 87 | { |
|---|
| 88 | int count; |
|---|
| 89 | struct recurrent **recurrent; |
|---|
| 90 | }; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | void version(void); |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid); |
|---|
| 98 | #ifdef USE_GRAB |
|---|
| 99 | int create_pty_grab(pid_t pid, unsigned int w, unsigned int h); |
|---|
| 100 | int grab_process(pid_t pid, char *ptyname, int ptyfd); |
|---|
| 101 | #endif |
|---|
| 102 | |
|---|
| 103 | long int import_term(struct screen_list *screen_list, struct screen *sc, void const *data, unsigned int size); |
|---|
| 104 | int set_tty_size(int fd, unsigned int w, unsigned int h); |
|---|
| 105 | int update_terms(struct screen_list* screen_list); |
|---|
| 106 | void refresh_screens(cucul_canvas_t *cv, |
|---|
| 107 | caca_display_t *dp, |
|---|
| 108 | struct screen_list *screen_list); |
|---|
| 109 | int update_screens_contents(struct screen_list* screen_list); |
|---|
| 110 | long long get_ms(void); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | /* Screens management */ |
|---|
| 114 | struct screen* create_screen(int w, int h, char *command); |
|---|
| 115 | #ifdef USE_GRAB |
|---|
| 116 | struct screen* create_screen_grab(int w, int h, int pid); |
|---|
| 117 | #endif |
|---|
| 118 | int destroy_screen(struct screen *s); |
|---|
| 119 | int add_screen(struct screen_list *list, struct screen *s); |
|---|
| 120 | int remove_screen(struct screen_list *list, int n, int please_kill); |
|---|
| 121 | void resize_screen(struct screen *s, int z, int h); |
|---|
| 122 | |
|---|
| 123 | /* Window managers */ |
|---|
| 124 | void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 125 | void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 126 | void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 127 | void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 128 | void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 129 | |
|---|
| 130 | /* Effects and addons */ |
|---|
| 131 | void draw_thumbnails(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 132 | void draw_status(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 133 | void draw_help(cucul_canvas_t *cv, struct screen_list *screen_list); |
|---|
| 134 | int close_screen_recurrent(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t); |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | /* Recurrents */ |
|---|
| 138 | int add_recurrent(struct recurrent_list *list, |
|---|
| 139 | int (*function)(struct screen_list*, struct recurrent* rec, void *user, long long unsigned int t), |
|---|
| 140 | void *user); |
|---|
| 141 | int remove_recurrent(struct recurrent_list *list, int n); |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | #if 0 |
|---|
| 145 | # define debug(f, z...) fprintf(stderr, f "\n", z) |
|---|
| 146 | #else |
|---|
| 147 | # define debug(f, z...) do {} while(0) |
|---|
| 148 | #endif |
|---|
| 149 | |
|---|