source: neercs/trunk/src/wm.c @ 2362

Last change on this file since 2362 was 2362, checked in by Jean-Yves Lamoureux, 14 years ago
  • Added window management skeleton (ctrl-a-w)
File size: 3.9 KB
Line 
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: wm.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 <cucul.h>
18#include <caca.h>
19#include <stdlib.h>
20
21#include "neercs.h"
22
23
24void resize_screen(struct screen *s, int w, int h)
25{
26    cucul_canvas_t *old, *new;
27
28    if(w==s->w && h==s->h) return;
29
30    s->w = w;
31    s->h = h;
32
33    /* cucul_set_canvas_boundaries() is bugged as hell,
34     * so let's resize it by hands */
35    old = s->cv;
36    new = cucul_create_canvas(w, h);
37    cucul_blit(new, 0, 0, old, NULL);
38    s->cv = new;
39    cucul_free_canvas(old);
40    set_tty_size(s->fd, w, h);
41}
42
43void update_windows_props(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
44{
45    switch(screen_list->wm_type)
46    {
47    case WM_FULL:
48        update_windows_props_full(cv, screen_list, pty);
49        break;
50    case WM_HSPLIT:
51        update_windows_props_hsplit(cv, screen_list, pty);
52        break;
53    case WM_VSPLIT:
54        update_windows_props_vsplit(cv, screen_list, pty);
55        break;
56    case WM_CARD:
57    default:
58        update_windows_props_cards(cv, screen_list, pty);
59        break;
60    }
61}
62
63void update_windows_props_hsplit(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
64{
65    int i;
66    int w = (screen_list->width / screen_list->count);
67    int h = (screen_list->height) - 2;
68
69
70    for(i = 0; i < screen_list->count; i++)
71    {
72        screen_list->screen[i]->x = (i*w)+1;
73        screen_list->screen[i]->y = 1;
74
75        resize_screen(screen_list->screen[i],
76                      w - 1, h);
77    }
78}
79
80void update_windows_props_vsplit(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
81{
82    int i;
83    int w = screen_list->width - 2;
84    int h = (screen_list->height / screen_list->count);
85
86    for(i = 0; i < screen_list->count; i++)
87    {
88        screen_list->screen[i]->x = 1;
89        screen_list->screen[i]->y = (i*h) + 1;
90
91        resize_screen(screen_list->screen[i],
92                      w, h - 1);
93    }
94}
95
96
97void update_windows_props_full(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
98{
99    int i;
100    int w = screen_list->width - 2;
101    int h = screen_list->height - 2;
102
103
104    for(i = 0; i < screen_list->count; i++)
105    {
106        screen_list->screen[i]->x = 1;
107        screen_list->screen[i]->y = 1;
108
109        resize_screen(screen_list->screen[i],
110                      w, h);
111    }
112}
113
114
115void update_windows_props_cards(cucul_canvas_t *cv, struct screen_list *screen_list, int pty)
116{
117#if 0
118    int i;
119    int xtab, ytab;
120
121    xtab = cucul_get_canvas_width(cv) screen_list->count
122
123
124    cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_DEFAULT);
125    cucul_clear_canvas(cv);
126    cucul_set_color_ansi(cv, CUCUL_LIGHTRED, CUCUL_BLACK);
127
128    for(i = 0; i < screen_list->count; i++)
129    {
130        int n = screen_list->count;
131        if(screen_list->screen[i]->fd < 0)
132            continue;
133        int j = (pty + n - 1 - i) % n;
134        cucul_blit(cv, (n - 1 - j) * XTAB + 1,
135                   j * YTAB + 1, screen_list->screen[j]->cv, NULL);
136        cucul_draw_cp437_box(cv, (n - 1 - j) * XTAB, j * YTAB,
137                             screen_list->screen[j]->w+1,
138                             screen_list->screen[j]->h+1);
139        /* Set cursor to the correct position */
140        if(i == n - 1)
141            cucul_gotoxy(cv, (n - 1 - j) * XTAB + 1
142                         + cucul_get_cursor_x(screen_list->screen[j]->cv),
143                         j * YTAB + 1
144                         + cucul_get_cursor_y(screen_list->screen[j]->cv));
145    }
146
147#endif
148}
149
Note: See TracBrowser for help on using the repository browser.