| 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: effects.c 2360 2008-06-11 16:23:46Z jylam $ |
|---|
| 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 <stdio.h> |
|---|
| 17 | #include <stdlib.h> |
|---|
| 18 | #include <string.h> |
|---|
| 19 | #include <cucul.h> |
|---|
| 20 | #include <caca.h> |
|---|
| 21 | #include <config.h> |
|---|
| 22 | #include <time.h> |
|---|
| 23 | |
|---|
| 24 | #include "neercs.h" |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | void draw_thumbnails(cucul_canvas_t *cv, struct screen_list *screen_list, int pty) |
|---|
| 28 | { |
|---|
| 29 | char const * const *fonts; |
|---|
| 30 | cucul_dither_t *d; |
|---|
| 31 | cucul_font_t *f; |
|---|
| 32 | uint8_t *buf; |
|---|
| 33 | int i; |
|---|
| 34 | int miniw, minih; |
|---|
| 35 | |
|---|
| 36 | if(screen_list->count) |
|---|
| 37 | { |
|---|
| 38 | fonts = cucul_get_font_list(); |
|---|
| 39 | f = cucul_load_font(fonts[0], 0); |
|---|
| 40 | |
|---|
| 41 | miniw = cucul_get_canvas_width(screen_list->screen[0]->cv) |
|---|
| 42 | * cucul_get_font_width(f); |
|---|
| 43 | minih = cucul_get_canvas_height(screen_list->screen[0]->cv) |
|---|
| 44 | * cucul_get_font_height(f); |
|---|
| 45 | buf = malloc(4 * miniw * minih); |
|---|
| 46 | |
|---|
| 47 | #if defined(HAVE_ENDIAN_H) |
|---|
| 48 | if(__BYTE_ORDER == __BIG_ENDIAN) |
|---|
| 49 | #else |
|---|
| 50 | /* This is compile-time optimised with at least -O1 or -Os */ |
|---|
| 51 | uint32_t const tmp = 0x12345678; |
|---|
| 52 | if(*(uint8_t const *)&tmp == 0x12) |
|---|
| 53 | #endif |
|---|
| 54 | d = cucul_create_dither(32, miniw, minih, 4 * miniw, |
|---|
| 55 | 0xff0000, 0xff00, 0xff, 0x0); |
|---|
| 56 | else |
|---|
| 57 | d = cucul_create_dither(32, miniw, minih, 4 * miniw, |
|---|
| 58 | 0xff00, 0xff0000, 0xff000000, 0x0); |
|---|
| 59 | |
|---|
| 60 | for(i = 0; i < screen_list->count; i++) |
|---|
| 61 | { |
|---|
| 62 | cucul_render_canvas(screen_list->screen[i]->cv, f, buf, |
|---|
| 63 | miniw, minih, miniw * 4); |
|---|
| 64 | cucul_dither_bitmap(cv, 20 * i, |
|---|
| 65 | cucul_get_canvas_height(cv) - 6, 19, 6, d, buf); |
|---|
| 66 | cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE); |
|---|
| 67 | |
|---|
| 68 | if(pty == i) |
|---|
| 69 | cucul_draw_cp437_box(cv,20 * i, |
|---|
| 70 | cucul_get_canvas_height(cv) - 6, 19, 6); |
|---|
| 71 | cucul_printf(cv, 20 * i, |
|---|
| 72 | cucul_get_canvas_height(cv) - 6, "(%i)", i+1); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | cucul_free_dither(d); |
|---|
| 76 | cucul_free_font(f); |
|---|
| 77 | |
|---|
| 78 | free(buf); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | /* FIXME, make this stuff more configurable */ |
|---|
| 84 | void draw_status(cucul_canvas_t *cv, struct screen_list *screen_list, int pty) |
|---|
| 85 | { |
|---|
| 86 | int x = 0, y = cucul_get_canvas_height(cv) - 1; |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE); |
|---|
| 90 | cucul_fill_box(cv, |
|---|
| 91 | x, y, |
|---|
| 92 | cucul_get_canvas_width(cv), 1, '#'); |
|---|
| 93 | |
|---|
| 94 | /* Hour */ |
|---|
| 95 | { |
|---|
| 96 | time_t now = time ((time_t *) 0); |
|---|
| 97 | struct tm *t = localtime(&now); |
|---|
| 98 | char hour[256]; |
|---|
| 99 | sprintf(hour, "%02d:%02d", t->tm_hour, t->tm_min); |
|---|
| 100 | |
|---|
| 101 | cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
|---|
| 102 | cucul_printf(cv, x, y, |
|---|
| 103 | "["); |
|---|
| 104 | |
|---|
| 105 | cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); |
|---|
| 106 | cucul_printf(cv, x+1, y, |
|---|
| 107 | hour); |
|---|
| 108 | cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
|---|
| 109 | cucul_printf(cv, x + strlen(hour) + 1, y, |
|---|
| 110 | "]"); |
|---|
| 111 | x += 7; |
|---|
| 112 | |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | /* Window */ |
|---|
| 116 | { |
|---|
| 117 | char text[256]; |
|---|
| 118 | sprintf(text, "%d/%d", pty+1, screen_list->count); |
|---|
| 119 | x++; |
|---|
| 120 | cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
|---|
| 121 | cucul_printf(cv, x, y, "Window:"); |
|---|
| 122 | cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); |
|---|
| 123 | cucul_printf(cv, x+8, y, text); |
|---|
| 124 | x+= 8+strlen(text); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /* Window Manager */ |
|---|
| 128 | { |
|---|
| 129 | char text[256]; |
|---|
| 130 | |
|---|
| 131 | switch(screen_list->wm_type) |
|---|
| 132 | { |
|---|
| 133 | case WM_CARD: |
|---|
| 134 | strcpy(text, "card"); |
|---|
| 135 | break; |
|---|
| 136 | case WM_HSPLIT: |
|---|
| 137 | strcpy(text, "hsplit"); |
|---|
| 138 | break; |
|---|
| 139 | case WM_VSPLIT: |
|---|
| 140 | strcpy(text, "vsplit"); |
|---|
| 141 | break; |
|---|
| 142 | case WM_FULL: |
|---|
| 143 | default: |
|---|
| 144 | strcpy(text, "full"); |
|---|
| 145 | break; |
|---|
| 146 | |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | x++; |
|---|
| 150 | cucul_set_color_ansi(cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); |
|---|
| 151 | cucul_printf(cv, x, y, "WM:"); |
|---|
| 152 | cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); |
|---|
| 153 | cucul_printf(cv, x+4, y, text); |
|---|
| 154 | x+= 4+strlen(text); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | /* Help (must be the last one )*/ |
|---|
| 158 | { |
|---|
| 159 | char text[256]; |
|---|
| 160 | sprintf(text, "Help: ctrl-a-h"); |
|---|
| 161 | x = cucul_get_canvas_width(cv) - strlen(text); |
|---|
| 162 | |
|---|
| 163 | cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); |
|---|
| 164 | cucul_printf(cv, x, y, text); |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | void draw_help(cucul_canvas_t *cv, struct screen_list *screen_list, int pty) |
|---|
| 172 | { |
|---|
| 173 | int w = 65, h = 20; |
|---|
| 174 | int x = (cucul_get_canvas_width(cv) - w) / 2; |
|---|
| 175 | int y = (cucul_get_canvas_height(cv) - h) / 2; |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE); |
|---|
| 179 | cucul_fill_box(cv, |
|---|
| 180 | x, y, |
|---|
| 181 | w, h, '#'); |
|---|
| 182 | cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); |
|---|
| 183 | cucul_draw_cp437_box(cv, |
|---|
| 184 | x, y, |
|---|
| 185 | w, h); |
|---|
| 186 | |
|---|
| 187 | x+=2; |
|---|
| 188 | y++; |
|---|
| 189 | cucul_printf(cv, |
|---|
| 190 | (cucul_get_canvas_width(cv) - strlen(PACKAGE_STRING)) / 2, |
|---|
| 191 | y-1, |
|---|
| 192 | PACKAGE_STRING); |
|---|
| 193 | cucul_printf(cv, x, y++, "Copyright (c) 2006-2008 "); |
|---|
| 194 | cucul_printf(cv, x, y++, " Sam Hocevar <sam@zoy.org>"); |
|---|
| 195 | cucul_printf(cv, x, y++, " Jean-Yves Lamoureux <jylam@lnxscene.org>"); |
|---|
| 196 | cucul_printf(cv, x, y++, ""); |
|---|
| 197 | cucul_printf(cv, x, y++, ""); |
|---|
| 198 | cucul_printf(cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); |
|---|
| 199 | |
|---|
| 200 | cucul_printf(cv, x, y++, "n:\t Next window"); |
|---|
| 201 | cucul_printf(cv, x, y++, "p:\t Previous window"); |
|---|
| 202 | cucul_printf(cv, x, y++, "w:\t Switch window manager"); |
|---|
| 203 | cucul_printf(cv, x, y++, "c:\t Create new window"); |
|---|
| 204 | cucul_printf(cv, x, y++, "m:\t Thumbnails"); |
|---|
| 205 | cucul_printf(cv, x, y++, "k:\t Close window and kill associated process"); |
|---|
| 206 | cucul_printf(cv, x, y++, "h:\t This help"); |
|---|
| 207 | cucul_printf(cv, x, y++, ""); |
|---|
| 208 | cucul_printf(cv, x, y++, ""); |
|---|
| 209 | cucul_printf(cv, x, y++, ""); |
|---|
| 210 | cucul_printf(cv, x, y++, "See http://libcaca.zoy.org/wiki/neercs for more informations"); |
|---|
| 211 | } |
|---|