From 46b93928dbca3cb89fe5d6ea4e3dbff234fa8e2a Mon Sep 17 00:00:00 2001 From: kucaahbe Date: Wed, 27 May 2020 23:48:36 +0300 Subject: [PATCH] switch panels --- Makefile | 3 +- curses-panel.vapi | 8 +++++ panels-switch.vala | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 panels-switch.vala diff --git a/Makefile b/Makefile index 9b2ff94..5db2411 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ demos = just-text \ window-with-text\ two-windows \ doupdate \ - panels + panels \ + panels-switch demos_files = $(patsubst %, %.exe, $(demos)) .PHONY: all diff --git a/curses-panel.vapi b/curses-panel.vapi index 6c7d1d2..8ca612a 100644 --- a/curses-panel.vapi +++ b/curses-panel.vapi @@ -4,6 +4,14 @@ namespace Curses { public class Panel { [CCode (cname = "new_panel")] public Panel(Window win); + public void * userptr { + [CCode (cname = "panel_userptr")] get; + [CCode (cname = "set_panel_userptr")] set; + } + [CCode (cname = "top_panel")] + public int top(); + [CCode (cname = "bottom_panel")] + public int botton(); public static void update_panels(); } diff --git a/panels-switch.vala b/panels-switch.vala new file mode 100644 index 0000000..ea465c8 --- /dev/null +++ b/panels-switch.vala @@ -0,0 +1,85 @@ +using Curses; +using Posix; + +public class Demo { + public MainLoop loop; + private IOChannel io_channel; + internal IOSource io; + + public Demo() { + loop = new MainLoop(); + + io_channel = new IOChannel.unix_new(Posix.STDIN_FILENO); + io = new IOSource(io_channel, IOCondition.IN); + io.attach(loop.get_context()); + } + + public void start() { + initscr(); + noecho(); + } + + public void stop() { + endwin(); + } + + private Window window1; + private Window window2; + + private Panel panel1; + private Panel panel2; + public void activate() { + this.window1 = new Window(5, 20, 1, 1); + panel1 = new Panel(window1); + this.window1.box(0, 0); + this.window1.mvprintw(1, 1, "I am in window 1"); + //this.window1.noutrefresh(); + + this.window2 = new Window(5, 20, 2, 19); + panel2 = new Panel(window2); + this.window2.box(0, 0); + this.window2.mvprintw(1, 1, "I am in window 2"); + //this.window2.noutrefresh(); + + panel1.userptr = panel2; + panel2.userptr = panel1; + + unowned Panel top_panel = panel2; + + io.set_callback(() => { + var c = getch(); + + if (c == Key.F0) { + loop.quit(); + } else { + top_panel = (Panel) top_panel.userptr; + top_panel.top(); + Panel.update_panels(); + doupdate(); + } + + return Source.CONTINUE; + }); + } + + public void run() { + loop.run(); + } + + public void redraw() { + Panel.update_panels(); + doupdate(); + } + + static int main(string[] args) { + var app = new Demo(); + + app.start(); + app.activate(); + app.redraw(); + app.run(); + app.stop(); + + return EXIT_SUCCESS; + } +}