comparison console/libgnt/gntmain.c @ 14477:ca36763497d9

[gaim-migrate @ 17195] Build libgnt with ncurses if ncursesw is not found. I uninstalled ncursesw and it's still working for me .. of course, with no wide-character support. Improve the mouse support a bit. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 09 Sep 2006 02:19:16 +0000
parents 0ed8b285a44b
children 5ac8f22e7b08
comparison
equal deleted inserted replaced
14476:218a36c1c9e2 14477:ca36763497d9
1 #define _XOPEN_SOURCE 1 #define _GNU_SOURCE
2 #define _XOPEN_SOURCE_EXTENDED
3 2
4 #include "config.h" 3 #include "config.h"
5 4
6 #include <gmodule.h> 5 #include <gmodule.h>
7 6
9 #include "gntbox.h" 8 #include "gntbox.h"
10 #include "gntcolors.h" 9 #include "gntcolors.h"
11 #include "gntkeys.h" 10 #include "gntkeys.h"
12 #include "gntstyle.h" 11 #include "gntstyle.h"
13 #include "gnttree.h" 12 #include "gnttree.h"
13 #include "gntutils.h"
14 #include "gntwm.h" 14 #include "gntwm.h"
15 15
16 #include <panel.h> 16 #include <panel.h>
17 17
18 #include <stdio.h> 18 #include <stdio.h>
24 #include <ctype.h> 24 #include <ctype.h>
25 #include <errno.h> 25 #include <errno.h>
26 26
27 #include <sys/types.h> 27 #include <sys/types.h>
28 #include <sys/wait.h> 28 #include <sys/wait.h>
29
30 #include <wchar.h>
31 29
32 /** 30 /**
33 * Notes: Interesting functions to look at: 31 * Notes: Interesting functions to look at:
34 * scr_dump, scr_init, scr_restore: for workspaces 32 * scr_dump, scr_init, scr_restore: for workspaces
35 * 33 *
251 } 249 }
252 wbkgdset(taskbar, '\0' | COLOR_PAIR(color)); 250 wbkgdset(taskbar, '\0' | COLOR_PAIR(color));
253 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width); 251 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width);
254 title = GNT_BOX(w)->title; 252 title = GNT_BOX(w)->title;
255 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>"); 253 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>");
254 if (i)
255 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL));
256 256
257 update_window_in_list(w); 257 update_window_in_list(w);
258 } 258 }
259 259
260 wrefresh(taskbar); 260 wrefresh(taskbar);
421 for (y = 0; y < getmaxy(stdscr); y++) 421 for (y = 0; y < getmaxy(stdscr); y++)
422 { 422 {
423 for (x = 0; x < getmaxx(stdscr); x++) 423 for (x = 0; x < getmaxx(stdscr); x++)
424 { 424 {
425 char ch; 425 char ch;
426 now = mvwinch(newscr, y, x); 426 now = mvwinch(curscr, y, x);
427 ch = now & A_CHARTEXT; 427 ch = now & A_CHARTEXT;
428 now ^= ch; 428 now ^= ch;
429 429
430 #define CHECK(attr, start, end) \ 430 #define CHECK(attr, start, end) \
431 do \ 431 do \
559 } button = MOUSE_NONE; 559 } button = MOUSE_NONE;
560 static GntWidget *remember = NULL; 560 static GntWidget *remember = NULL;
561 static int offset = 0; 561 static int offset = 0;
562 GntMouseEvent event; 562 GntMouseEvent event;
563 GntWidget *widget = NULL; 563 GntWidget *widget = NULL;
564 GList *iter; 564 PANEL *p = NULL;
565 565
566 if (!ordered || buffer[0] != 27) 566 if (!ordered || buffer[0] != 27)
567 return FALSE; 567 return FALSE;
568 568
569 buffer++; 569 buffer++;
575 if (x < 0) x += 256; 575 if (x < 0) x += 256;
576 if (y < 0) y += 256; 576 if (y < 0) y += 256;
577 x -= 33; 577 x -= 33;
578 y -= 33; 578 y -= 33;
579 579
580 for (iter = ordered; iter; iter = iter->next) { 580 /* It might be a better idea to use panel_below. That would allow mouse-clicks
581 GntWidget *wid = iter->data; 581 * to be operated on transient windows, which would be cool.*/
582 while ((p = panel_below(p)) != NULL) {
583 const GntNode *node = panel_userptr(p);
584 GntWidget *wid;
585 if (!node)
586 continue;
587 wid = node->me;
582 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) { 588 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) {
583 if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) { 589 if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) {
584 widget = wid; 590 widget = wid;
585 break; 591 break;
586 } 592 }
587 } 593 }
588 } 594 }
595
589 if (strncmp(buffer, "[M ", 3) == 0) { 596 if (strncmp(buffer, "[M ", 3) == 0) {
590 /* left button down */ 597 /* left button down */
591 /* Bring the window you clicked on to front */ 598 /* Bring the window you clicked on to front */
592 /* If you click on the topbar, then you can drag to move the window */ 599 /* If you click on the topbar, then you can drag to move the window */
593 event = GNT_LEFT_MOUSE_DOWN; 600 event = GNT_LEFT_MOUSE_DOWN;
610 return FALSE; 617 return FALSE;
611 618
612 if (wm.mouse_clicked && wm.mouse_clicked(event, x, y, widget)) 619 if (wm.mouse_clicked && wm.mouse_clicked(event, x, y, widget))
613 return TRUE; 620 return TRUE;
614 621
615 if (event == GNT_LEFT_MOUSE_DOWN && widget) { 622 if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != _list.window &&
623 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) {
616 if (widget != ordered->data) { 624 if (widget != ordered->data) {
617 GntWidget *w = ordered->data; 625 GntWidget *w = ordered->data;
618 ordered = g_list_bring_to_front(ordered, widget); 626 ordered = g_list_bring_to_front(ordered, widget);
619 wm.give_focus(ordered->data); 627 wm.give_focus(ordered->data);
620 gnt_widget_set_focus(w, FALSE); 628 gnt_widget_set_focus(w, FALSE);
642 button = MOUSE_NONE; 650 button = MOUSE_NONE;
643 remember = NULL; 651 remember = NULL;
644 offset = 0; 652 offset = 0;
645 } 653 }
646 654
647 gnt_widget_clicked(ordered->data, event, x, y); 655 gnt_widget_clicked(widget, event, x, y);
648 return FALSE; /* XXX: this should be TRUE */ 656 return TRUE; /* XXX: this should be TRUE */
649 } 657 }
658
659 #ifndef NO_WIDECHAR
660 static int
661 widestringwidth(wchar_t *wide)
662 {
663 int len, ret;
664 char *string;
665
666 len = wcstombs(NULL, wide, 0) + 1;
667 string = g_new0(char, len);
668 wcstombs(string, wide, len);
669 ret = gnt_util_onscreen_width(string, NULL);
670 g_free(string);
671 return ret;
672 }
673 #endif
650 674
651 /* Returns the onscreen width of the character at the position */ 675 /* Returns the onscreen width of the character at the position */
652 static int 676 static int
653 reverse_char(WINDOW *d, int y, int x, gboolean set) 677 reverse_char(WINDOW *d, int y, int x, gboolean set)
654 { 678 {
655 /* This is supposed to simply in_wch the cchar_t, set the attribute, 679 #define DECIDE(ch) (set ? ((ch) | WA_REVERSE) : ((ch) & ~WA_REVERSE))
656 * and add_wch. But that doesn't currently work, possibly because of 680
657 * a bug in ncurses. This is an ugly hack to work around that. */ 681 #ifdef NO_WIDECHAR
682 chtype ch;
683 ch = mvwinch(d, y, x);
684 mvwaddch(d, y, x, DECIDE(ch));
685 return 1;
686 #else
658 cchar_t ch; 687 cchar_t ch;
659 int wc = 1, j; 688 int wc = 1;
660
661 #define DECIDE(ch) (set ? ((ch) | WA_REVERSE) : ((ch) & ~WA_REVERSE))
662
663 if (mvwin_wch(d, y, x, &ch) == OK) { 689 if (mvwin_wch(d, y, x, &ch) == OK) {
664 wc = wcswidth(ch.chars, CCHARW_MAX); 690 wc = widestringwidth(ch.chars);
665 for (j = 0; j < wc; j++)
666 mvwdelch(d, y, x);
667 ch.attr = DECIDE(ch.attr); 691 ch.attr = DECIDE(ch.attr);
668 mvwins_wch(d, y, x, &ch); 692 ch.attr &= WA_ATTRIBUTES; /* XXX: This is a workaround for a bug */
669 } 693 mvwadd_wch(d, y, x, &ch);
694 }
695
670 return wc; 696 return wc;
697 #endif
671 } 698 }
672 699
673 static void 700 static void
674 window_reverse(GntWidget *win, gboolean set) 701 window_reverse(GntWidget *win, gboolean set)
675 { 702 {
1176 { 1203 {
1177 if (wm.new_window && node->me != _list.window) 1204 if (wm.new_window && node->me != _list.window)
1178 node->panel = wm.new_window(node->me); 1205 node->panel = wm.new_window(node->me);
1179 else 1206 else
1180 node->panel = new_panel(node->me->window); 1207 node->panel = new_panel(node->me->window);
1208 set_panel_userptr(node->panel, node);
1181 if (!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT)) 1209 if (!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT))
1182 { 1210 {
1183 bottom_panel(node->panel); /* New windows should not grab focus */ 1211 bottom_panel(node->panel); /* New windows should not grab focus */
1184 gnt_widget_set_urgent(node->me); 1212 gnt_widget_set_urgent(node->me);
1185 } 1213 }