Changeset 2495 for neercs/trunk/src/effects.c
- Timestamp:
- Jun 28, 2008, 1:22:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/effects.c
r2474 r2495 23 23 #include <sys/wait.h> 24 24 #include <sys/types.h> 25 #include <security/pam_appl.h>26 #include <security/pam_misc.h>27 #include <pwd.h>28 25 29 26 #include "neercs.h" 30 27 31 static int convpam(int num_msg, const struct pam_message **msg, 32 struct pam_response **resp, void *appdata_ptr); 33 34 void draw_thumbnails(cucul_canvas_t *cv, struct screen_list *screen_list) 35 { 36 char const * const *fonts; 37 cucul_dither_t *d; 38 cucul_font_t *f; 39 uint8_t *buf; 40 int i; 41 int miniw, minih; 42 43 if(screen_list->count) 44 { 45 fonts = cucul_get_font_list(); 46 f = cucul_load_font(fonts[0], 0); 47 48 miniw = cucul_get_canvas_width(screen_list->screen[0]->cv) 49 * cucul_get_font_width(f); 50 minih = cucul_get_canvas_height(screen_list->screen[0]->cv) 51 * cucul_get_font_height(f); 52 buf = malloc(4 * miniw * minih); 28 void draw_thumbnails(struct screen_list *screen_list) 29 { 30 char const * const *fonts; 31 cucul_dither_t *d; 32 cucul_font_t *f; 33 uint8_t *buf; 34 int i; 35 int miniw, minih; 36 37 if(screen_list->count) 38 { 39 fonts = cucul_get_font_list(); 40 f = cucul_load_font(fonts[0], 0); 41 42 miniw = cucul_get_canvas_width(screen_list->screen[0]->cv) 43 * cucul_get_font_width(f); 44 minih = cucul_get_canvas_height(screen_list->screen[0]->cv) 45 * cucul_get_font_height(f); 46 buf = malloc(4 * miniw * minih); 53 47 54 48 #if defined(HAVE_ENDIAN_H) 55 49 if(__BYTE_ORDER == __BIG_ENDIAN) 56 50 #else 57 58 59 51 /* This is compile-time optimised with at least -O1 or -Os */ 52 uint32_t const tmp = 0x12345678; 53 if(*(uint8_t const *)&tmp == 0x12) 60 54 #endif 61 62 63 64 65 66 67 68 69 70 71 cucul_dither_bitmap(cv, 20 * i,72 cucul_get_canvas_height(cv) - 6, 19, 6, d, buf);73 cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);74 75 76 cucul_draw_cp437_box(cv,20 * i,77 cucul_get_canvas_height(cv) - 6, 19, 6);78 cucul_printf(cv, 20 * i,79 cucul_get_canvas_height(cv) - 6, "(%i)", i+1);80 81 82 83 84 85 86 55 d = cucul_create_dither(32, miniw, minih, 4 * miniw, 56 0xff0000, 0xff00, 0xff, 0x0); 57 else 58 d = cucul_create_dither(32, miniw, minih, 4 * miniw, 59 0xff00, 0xff0000, 0xff000000, 0x0); 60 61 for(i = 0; i < screen_list->count; i++) 62 { 63 cucul_render_canvas(screen_list->screen[i]->cv, f, buf, 64 miniw, minih, miniw * 4); 65 cucul_dither_bitmap(screen_list->cv, 20 * i, 66 cucul_get_canvas_height(screen_list->cv) - 6, 19, 6, d, buf); 67 cucul_set_color_ansi(screen_list->cv, CUCUL_WHITE, CUCUL_BLUE); 68 69 if(screen_list->pty == i) 70 cucul_draw_cp437_box(screen_list->cv,20 * i, 71 cucul_get_canvas_height(screen_list->cv) - 6, 19, 6); 72 cucul_printf(screen_list->cv, 20 * i, 73 cucul_get_canvas_height(screen_list->cv) - 6, "(%i)", i+1); 74 } 75 76 cucul_free_dither(d); 77 cucul_free_font(f); 78 79 free(buf); 80 } 87 81 88 82 } 89 83 90 84 /* FIXME, make this stuff more configurable */ 91 void draw_status( cucul_canvas_t *cv,struct screen_list *screen_list)92 { 93 int x = 0, y = cucul_get_canvas_height( cv) - 1;94 95 96 cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE);97 cucul_fill_box(cv,98 99 cucul_get_canvas_width(cv), 1, '#');85 void draw_status(struct screen_list *screen_list) 86 { 87 int x = 0, y = cucul_get_canvas_height(screen_list->cv) - 1; 88 89 90 cucul_set_color_ansi(screen_list->cv, CUCUL_BLUE, CUCUL_BLUE); 91 cucul_fill_box(screen_list->cv, 92 x, y, 93 cucul_get_canvas_width(screen_list->cv), 1, '#'); 100 94 101 95 /* Hour */ … … 106 100 sprintf(hour, "%02d:%02d", t->tm_hour, t->tm_min); 107 101 108 cucul_set_color_ansi( cv, CUCUL_LIGHTBLUE, CUCUL_BLUE);109 cucul_printf( cv, x, y,102 cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 103 cucul_printf(screen_list->cv, x, y, 110 104 "["); 111 105 112 cucul_set_color_ansi( cv, CUCUL_DEFAULT, CUCUL_BLUE);113 cucul_printf( cv, x+1, y,106 cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 107 cucul_printf(screen_list->cv, x+1, y, 114 108 hour); 115 cucul_set_color_ansi( cv, CUCUL_LIGHTBLUE, CUCUL_BLUE);116 cucul_printf( cv, x + strlen(hour) + 1, y,109 cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 110 cucul_printf(screen_list->cv, x + strlen(hour) + 1, y, 117 111 "]"); 118 112 x += 7; … … 125 119 sprintf(text, "%d/%d", screen_list->pty+1, screen_list->count); 126 120 x++; 127 cucul_set_color_ansi( cv, CUCUL_LIGHTBLUE, CUCUL_BLUE);128 cucul_printf( cv, x, y, "Window:");129 cucul_set_color_ansi( cv, CUCUL_DEFAULT, CUCUL_BLUE);130 cucul_printf( cv, x+8, y, text);121 cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 122 cucul_printf(screen_list->cv, x, y, "Window:"); 123 cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 124 cucul_printf(screen_list->cv, x+8, y, text); 131 125 x+= 8+strlen(text); 132 126 } … … 155 149 156 150 x++; 157 cucul_set_color_ansi( cv, CUCUL_LIGHTBLUE, CUCUL_BLUE);158 cucul_printf( cv, x, y, "WM:");159 cucul_set_color_ansi( cv, CUCUL_DEFAULT, CUCUL_BLUE);160 cucul_printf( cv, x+4, y, text);151 cucul_set_color_ansi(screen_list->cv, CUCUL_LIGHTBLUE, CUCUL_BLUE); 152 cucul_printf(screen_list->cv, x, y, "WM:"); 153 cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 154 cucul_printf(screen_list->cv, x+4, y, text); 161 155 x+= 4+strlen(text); 162 156 } … … 166 160 char text[256]; 167 161 sprintf(text, "Help: ctrl-a-h"); 168 x = cucul_get_canvas_width( cv) - strlen(text);169 170 cucul_set_color_ansi( cv, CUCUL_DEFAULT, CUCUL_BLUE);171 cucul_printf( cv, x, y, text);172 } 173 174 175 } 176 177 178 void draw_help( cucul_canvas_t *cv,struct screen_list *screen_list)162 x = cucul_get_canvas_width(screen_list->cv) - strlen(text); 163 164 cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 165 cucul_printf(screen_list->cv, x, y, text); 166 } 167 168 169 } 170 171 172 void draw_help(struct screen_list *screen_list) 179 173 { 180 174 int w = 65, h = 20; 181 int x = (cucul_get_canvas_width( cv) - w) / 2;182 int y = (cucul_get_canvas_height( cv) - h) / 2;183 184 185 cucul_set_color_ansi( cv, CUCUL_BLUE, CUCUL_BLUE);186 cucul_fill_box( cv,175 int x = (cucul_get_canvas_width(screen_list->cv) - w) / 2; 176 int y = (cucul_get_canvas_height(screen_list->cv) - h) / 2; 177 178 179 cucul_set_color_ansi(screen_list->cv, CUCUL_BLUE, CUCUL_BLUE); 180 cucul_fill_box(screen_list->cv, 187 181 x, y, 188 182 w, h, '#'); 189 cucul_set_color_ansi( cv, CUCUL_DEFAULT, CUCUL_BLUE);190 cucul_draw_cp437_box( cv,183 cucul_set_color_ansi(screen_list->cv, CUCUL_DEFAULT, CUCUL_BLUE); 184 cucul_draw_cp437_box(screen_list->cv, 191 185 x, y, 192 186 w, h); … … 194 188 x+=2; 195 189 y++; 196 cucul_printf( cv,197 (cucul_get_canvas_width( cv) - strlen(PACKAGE_STRING)) / 2,190 cucul_printf(screen_list->cv, 191 (cucul_get_canvas_width(screen_list->cv) - strlen(PACKAGE_STRING)) / 2, 198 192 y-1, 199 193 PACKAGE_STRING); 200 cucul_printf(cv, x, y++, "Copyright (c) 2006-2008 "); 201 cucul_printf(cv, x, y++, " Sam Hocevar <sam@zoy.org>"); 202 cucul_printf(cv, x, y++, " Jean-Yves Lamoureux <jylam@lnxscene.org>"); 203 cucul_printf(cv, x, y++, " Pascal Terjan <pterjan@linuxfr.org>"); 204 cucul_printf(cv, x, y++, ""); 205 cucul_printf(cv, x, y++, ""); 206 cucul_printf(cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); 207 cucul_printf(cv, x, y++, "n:\t Next window"); 208 cucul_printf(cv, x, y++, "p:\t Previous window"); 209 cucul_printf(cv, x, y++, "w:\t Switch window manager"); 210 cucul_printf(cv, x, y++, "c:\t Create new window"); 211 cucul_printf(cv, x, y++, "m:\t Thumbnails"); 212 cucul_printf(cv, x, y++, "d:\t Detach"); 213 cucul_printf(cv, x, y++, "k:\t Close window and kill associated process"); 214 cucul_printf(cv, x, y++, "h:\t This help"); 215 cucul_printf(cv, x, y++, ""); 216 cucul_printf(cv, x, y++, ""); 217 cucul_printf(cv, x, y++, "See http://libcaca.zoy.org/wiki/neercs for more informations"); 218 } 219 220 221 void draw_lock(cucul_canvas_t *cv, struct screen_list *screen_list) 222 { 223 unsigned int i; 224 char buffer[1024]; 225 gethostname(buffer, sizeof(buffer)-1); 226 227 int w = 65, h = 20; 228 int x = (cucul_get_canvas_width(cv) - w) / 2; 229 int y = (cucul_get_canvas_height(cv) - h) / 2; 230 231 232 cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE); 233 cucul_fill_box(cv, 234 x, y, 235 w, h, '#'); 236 cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 237 cucul_draw_cp437_box(cv, 238 x, y, 239 w, h); 240 241 x+=2; 242 y++; 243 cucul_printf(cv, 244 (cucul_get_canvas_width(cv) - strlen(PACKAGE_STRING " locked")) / 2, 245 y-1, 246 PACKAGE_STRING " locked"); 247 248 cucul_printf(cv, x, y++, "Please type in your password for %s@%s :", getenv("USER"), buffer); 249 y+=2; 250 251 x = (cucul_get_canvas_width(cv)/2) - ((strlen(screen_list->lockpass) / 2) + strlen("Password : ")); 252 cucul_printf(cv, x, y, "Password : "); 253 x+=strlen("Password : "); 254 for(i=0; i<strlen(screen_list->lockpass); i++) 255 { 256 cucul_put_str(cv, x, y, "*"); 257 x++; 258 } 259 260 261 if(strlen(screen_list->lockmsg)) 262 { 263 x = ((cucul_get_canvas_width(cv) - w) / 2) + (strlen(screen_list->lockmsg)); 264 y+=2; 265 cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLUE); 266 cucul_printf(cv, x, y, "Error : %s", screen_list->lockmsg); 267 } 268 } 269 270 271 272 /* FIXME, handle this without assuming this is a password auth */ 273 static int convpam(int num_msg, const struct pam_message **msg, 274 struct pam_response **resp, void *appdata_ptr) 275 { 276 277 struct pam_response *aresp; 278 int i; 279 aresp = calloc(num_msg, sizeof(*aresp)); 280 281 for (i = 0; i < num_msg; ++i) 282 { 283 switch(msg[i]->msg_style) 284 { 285 case PAM_PROMPT_ECHO_ON: 286 case PAM_PROMPT_ECHO_OFF: 287 aresp[i].resp = strdup(appdata_ptr); 288 aresp[i].resp_retcode = 0; 289 break; 290 case PAM_ERROR_MSG: 291 break; 292 default : 293 printf("Unknow message type from PAM\n"); 294 break; 295 } 296 } 297 298 *resp = aresp; 299 return (PAM_SUCCESS); 300 } 301 302 303 int validate_lock(struct screen_list *screen_list, char *user, char *pass) 304 { 305 int ret; 306 pam_handle_t *pamh=NULL; 307 char buffer[100]; 308 const char *service="neercs"; 309 struct pam_conv conv = { 310 convpam, 311 pass, 312 }; 313 314 ret = pam_start(service, user, &conv, &pamh); 315 if(ret!=PAM_SUCCESS) 316 return 0; 317 pam_set_item(pamh, PAM_RUSER, user); 318 319 ret = gethostname(buffer, sizeof(buffer)-1); 320 if (ret) 321 { 322 perror("failed to look up hostname"); 323 ret = pam_end(pamh, PAM_ABORT); 324 sprintf(screen_list->lockmsg, "Can't get hostname"); 325 pam_end(pamh, PAM_SUCCESS); 326 return 0; 327 } 328 329 ret = pam_set_item(pamh, PAM_RHOST, buffer); 330 if(ret!=PAM_SUCCESS) 331 { 332 sprintf(screen_list->lockmsg, "Can't set hostname"); 333 pam_end(pamh, PAM_SUCCESS); 334 return 0; 335 } 336 337 ret = pam_authenticate(pamh, 0); 338 if(ret!=PAM_SUCCESS) 339 { 340 sprintf(screen_list->lockmsg, "Can't authenticate"); 341 pam_end(pamh, PAM_SUCCESS); 342 return 0; 343 } 344 345 ret = pam_end(pamh, PAM_SUCCESS); 346 return 1; 347 } 194 cucul_printf(screen_list->cv, x, y++, "Copyright (c) 2006-2008 "); 195 cucul_printf(screen_list->cv, x, y++, " Sam Hocevar <sam@zoy.org>"); 196 cucul_printf(screen_list->cv, x, y++, " Jean-Yves Lamoureux <jylam@lnxscene.org>"); 197 cucul_printf(screen_list->cv, x, y++, " Pascal Terjan <pterjan@linuxfr.org>"); 198 cucul_printf(screen_list->cv, x, y++, ""); 199 cucul_printf(screen_list->cv, x, y++, ""); 200 cucul_printf(screen_list->cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); 201 cucul_printf(screen_list->cv, x, y++, "n:\t Next window"); 202 cucul_printf(screen_list->cv, x, y++, "p:\t Previous window"); 203 cucul_printf(screen_list->cv, x, y++, "w:\t Switch window manager"); 204 cucul_printf(screen_list->cv, x, y++, "c:\t Create new window"); 205 cucul_printf(screen_list->cv, x, y++, "m:\t Thumbnails"); 206 cucul_printf(screen_list->cv, x, y++, "d:\t Detach"); 207 cucul_printf(screen_list->cv, x, y++, "k:\t Close window and kill associated process"); 208 cucul_printf(screen_list->cv, x, y++, "h:\t This help"); 209 cucul_printf(screen_list->cv, x, y++, ""); 210 cucul_printf(screen_list->cv, x, y++, ""); 211 cucul_printf(screen_list->cv, x, y++, "See http://libcaca.zoy.org/wiki/neercs for more informations"); 212 } 213 348 214 349 215 … … 391 257 ((s->orig_h/2) - s->h/2); 392 258 } 393 394 259 return 1; 395 260 }
Note: See TracChangeset
for help on using the changeset viewer.