- removed 0 CR characters - removed 0 trailing whitespaces - replaced 0 tabs with spaces - fixed 542 svn:eol-style propertiesmaster
@@ -1,64 +1 @@ | |||||
// | |||||
// Neercs | |||||
// | |||||
// Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <time.h> | |||||
#include <caca.h> | |||||
#include "core.h" | |||||
using namespace std; | |||||
using namespace lol; | |||||
#include "neercs.h" | |||||
#include "video/render.h" | |||||
extern "C" | |||||
{ | |||||
#include "old/neercs.h" | |||||
} | |||||
Neercs::Neercs(int argc, char **argv) | |||||
: m_term(new Term(ivec2(45, 16))), | |||||
m_render(new Render(m_term->GetCaca())), | |||||
m_ready(false) | |||||
{ | |||||
Ticker::Ref(m_term); | |||||
Ticker::Ref(m_render); | |||||
} | |||||
void Neercs::TickGame(float seconds) | |||||
{ | |||||
WorldEntity::TickGame(seconds); | |||||
} | |||||
void Neercs::TickDraw(float seconds) | |||||
{ | |||||
WorldEntity::TickDraw(seconds); | |||||
} | |||||
Neercs::~Neercs() | |||||
{ | |||||
Ticker::Unref(m_term); | |||||
Ticker::Unref(m_render); | |||||
} | |||||
int main(int argc, char **argv) | |||||
{ | |||||
System::Init(argc, argv); | |||||
Application app("Neercs", ivec2(800, 600), 60.0f); | |||||
new Neercs(argc, argv); | |||||
app.ShowPointer(false); | |||||
app.Run(); | |||||
return EXIT_SUCCESS; | |||||
} | |||||
// // Neercs // // Copyright: (c) 2012-2013 Sam Hocevar <sam@hocevar.net> // #if defined HAVE_CONFIG_H # include "config.h" #endif #include <time.h> #include <caca.h> #include "core.h" using namespace std; using namespace lol; #include "neercs.h" #include "video/render.h" extern "C" { #include "old/neercs.h" } Neercs::Neercs(int argc, char **argv) : m_term(new Term(ivec2(45, 16))), m_render(new Render(m_term->GetCaca())), m_ready(false) { Ticker::Ref(m_term); Ticker::Ref(m_render); } void Neercs::TickGame(float seconds) { WorldEntity::TickGame(seconds); } void Neercs::TickDraw(float seconds) { WorldEntity::TickDraw(seconds); } Neercs::~Neercs() { Ticker::Unref(m_term); Ticker::Unref(m_render); } int main(int argc, char **argv) { System::Init(argc, argv); Application app("Neercs", ivec2(800, 600), 60.0f); new Neercs(argc, argv); app.ShowPointer(false); app.Run(); return EXIT_SUCCESS; } |
@@ -1,40 +1 @@ | |||||
// | |||||
// Neercs | |||||
// | |||||
// Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
#if !defined __NEERCS_H__ | |||||
#define __NEERCS_H__ | |||||
#include <caca.h> | |||||
#include "video/render.h" | |||||
#include "term/term.h" | |||||
extern "C" | |||||
{ | |||||
#include "old/neercs.h" | |||||
} | |||||
class Neercs : public WorldEntity | |||||
{ | |||||
public: | |||||
Neercs(int argc, char **argv); | |||||
virtual ~Neercs(); | |||||
char const *GetName() { return "<neercs>"; } | |||||
protected: | |||||
virtual void TickGame(float seconds); | |||||
virtual void TickDraw(float seconds); | |||||
private: | |||||
Term *m_term; | |||||
Render *m_render; | |||||
bool m_ready; | |||||
}; | |||||
#endif // __NEERCS_H__ | |||||
// // Neercs // // Copyright: (c) 2012 Sam Hocevar <sam@hocevar.net> // #if !defined __NEERCS_H__ #define __NEERCS_H__ #include <caca.h> #include "video/render.h" #include "term/term.h" extern "C" { #include "old/neercs.h" } class Neercs : public WorldEntity { public: Neercs(int argc, char **argv); virtual ~Neercs(); char const *GetName() { return "<neercs>"; } protected: virtual void TickGame(float seconds); virtual void TickDraw(float seconds); private: Term *m_term; Render *m_render; bool m_ready; }; #endif // __NEERCS_H__ |
@@ -1,66 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* 2008-2010 Pascal Terjan <pterjan@linuxfr.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <caca.h> | |||||
#include <errno.h> | |||||
#include <string.h> | |||||
#include <sys/stat.h> | |||||
#include "neercs.h" | |||||
void dump_to_file(struct screen_list *screen_list) | |||||
{ | |||||
char filename[14] = "hardcopy.0"; | |||||
int n = 0; | |||||
struct stat bufstat; | |||||
void * export; | |||||
size_t len, wrote; | |||||
FILE * out; | |||||
/* FIXME maybe use glob and get next one directly */ | |||||
while (n<9999 && !stat(filename, &bufstat)) | |||||
{ | |||||
n++; | |||||
sprintf(&filename[9], "%d", n); | |||||
} | |||||
if (n>=9999) | |||||
{ | |||||
debug("Too many hardcopy files in current directory\n"); | |||||
return; | |||||
} | |||||
export = caca_export_canvas_to_memory(screen_list->cv, "ansi", &len); | |||||
if (!export) | |||||
{ | |||||
debug("Failed to export to ansi\n"); | |||||
return; | |||||
} | |||||
out = fopen(filename, "w"); | |||||
if (!out) | |||||
{ | |||||
debug("Failed to open output file %s: %s\n", filename, strerror(errno)); | |||||
return; | |||||
} | |||||
wrote = fwrite(export, len, 1, out); | |||||
if (!wrote) | |||||
{ | |||||
debug("Failed to write to output file: %s\n", strerror(errno)); | |||||
return; | |||||
} | |||||
free(export); | |||||
} | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2008-2010 Pascal Terjan <pterjan@linuxfr.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #include <caca.h> #include <errno.h> #include <string.h> #include <sys/stat.h> #include "neercs.h" void dump_to_file(struct screen_list *screen_list) { char filename[14] = "hardcopy.0"; int n = 0; struct stat bufstat; void * export; size_t len, wrote; FILE * out; /* FIXME maybe use glob and get next one directly */ while (n<9999 && !stat(filename, &bufstat)) { n++; sprintf(&filename[9], "%d", n); } if (n>=9999) { debug("Too many hardcopy files in current directory\n"); return; } export = caca_export_canvas_to_memory(screen_list->cv, "ansi", &len); if (!export) { debug("Failed to export to ansi\n"); return; } out = fopen(filename, "w"); if (!out) { debug("Failed to open output file %s: %s\n", filename, strerror(errno)); return; } wrote = fwrite(export, len, 1, out); if (!wrote) { debug("Failed to write to output file: %s\n", strerror(errno)); return; } free(export); } |
@@ -1,82 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#if !defined _WIN32 | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <time.h> | |||||
#include <sys/wait.h> | |||||
#include <sys/types.h> | |||||
#include <caca.h> | |||||
#include "neercs.h" | |||||
int help_handle_key(struct screen_list *screen_list, unsigned int c) | |||||
{ | |||||
if (c == CACA_KEY_ESCAPE || c == '?') | |||||
{ | |||||
screen_list->modals.help = 0; | |||||
screen_list->changed = 1; | |||||
return 1; | |||||
} | |||||
else | |||||
{ | |||||
return 0; | |||||
} | |||||
} | |||||
void draw_help(struct screen_list *screen_list) | |||||
{ | |||||
int w = 65, h = 20; | |||||
int x = (caca_get_canvas_width(screen_list->cv) - w) / 2; | |||||
int y = (caca_get_canvas_height(screen_list->cv) - h) / 2; | |||||
caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE); | |||||
caca_fill_box(screen_list->cv, x, y, w, h, '#'); | |||||
caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_BLUE); | |||||
caca_draw_cp437_box(screen_list->cv, x, y, w, h); | |||||
x += 2; | |||||
y++; | |||||
caca_printf(screen_list->cv, | |||||
(caca_get_canvas_width(screen_list->cv) - | |||||
strlen(PACKAGE_STRING)) / 2, y - 1, PACKAGE_STRING); | |||||
caca_printf(screen_list->cv, x, y++, "Copyright (c) 2006-2010"); | |||||
caca_printf(screen_list->cv, x, y++, " Sam Hocevar <sam@zoy.org>"); | |||||
caca_printf(screen_list->cv, x, y++, " Jean-Yves Lamoureux <jylam@lnxscene.org>"); | |||||
caca_printf(screen_list->cv, x, y++, " Pascal Terjan <pterjan@linuxfr.org>"); | |||||
caca_printf(screen_list->cv, x, y++, ""); | |||||
caca_printf(screen_list->cv, x, y++, ""); | |||||
caca_printf(screen_list->cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); | |||||
caca_printf(screen_list->cv, x, y++, "n: Next window"); | |||||
caca_printf(screen_list->cv, x, y++, "p: Previous window"); | |||||
caca_printf(screen_list->cv, x, y++, "w: Switch window manager"); | |||||
caca_printf(screen_list->cv, x, y++, "c: Create new window"); | |||||
caca_printf(screen_list->cv, x, y++, "m: Thumbnails"); | |||||
caca_printf(screen_list->cv, x, y++, "d: Detach"); | |||||
caca_printf(screen_list->cv, x, y++, "k: Close window and kill associated process"); | |||||
caca_printf(screen_list->cv, x, y++, "h: Dump screen into a file"); | |||||
caca_printf(screen_list->cv, x, y++, "?: This help"); | |||||
caca_printf(screen_list->cv, x, y++, ""); | |||||
caca_printf(screen_list->cv, x, y++, ""); | |||||
caca_printf(screen_list->cv, x, y, "See http://caca.zoy.org/wiki/neercs for more informations"); | |||||
} | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #if !defined _WIN32 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <sys/wait.h> #include <sys/types.h> #include <caca.h> #include "neercs.h" int help_handle_key(struct screen_list *screen_list, unsigned int c) { if (c == CACA_KEY_ESCAPE || c == '?') { screen_list->modals.help = 0; screen_list->changed = 1; return 1; } else { return 0; } } void draw_help(struct screen_list *screen_list) { int w = 65, h = 20; int x = (caca_get_canvas_width(screen_list->cv) - w) / 2; int y = (caca_get_canvas_height(screen_list->cv) - h) / 2; caca_set_color_ansi(screen_list->cv, CACA_BLUE, CACA_BLUE); caca_fill_box(screen_list->cv, x, y, w, h, '#'); caca_set_color_ansi(screen_list->cv, CACA_DEFAULT, CACA_BLUE); caca_draw_cp437_box(screen_list->cv, x, y, w, h); x += 2; y++; caca_printf(screen_list->cv, (caca_get_canvas_width(screen_list->cv) - strlen(PACKAGE_STRING)) / 2, y - 1, PACKAGE_STRING); caca_printf(screen_list->cv, x, y++, "Copyright (c) 2006-2010"); caca_printf(screen_list->cv, x, y++, " Sam Hocevar <sam@zoy.org>"); caca_printf(screen_list->cv, x, y++, " Jean-Yves Lamoureux <jylam@lnxscene.org>"); caca_printf(screen_list->cv, x, y++, " Pascal Terjan <pterjan@linuxfr.org>"); caca_printf(screen_list->cv, x, y++, ""); caca_printf(screen_list->cv, x, y++, ""); caca_printf(screen_list->cv, x, y++, "All shortcuts are in format 'ctrl-a-X' where X is :"); caca_printf(screen_list->cv, x, y++, "n: Next window"); caca_printf(screen_list->cv, x, y++, "p: Previous window"); caca_printf(screen_list->cv, x, y++, "w: Switch window manager"); caca_printf(screen_list->cv, x, y++, "c: Create new window"); caca_printf(screen_list->cv, x, y++, "m: Thumbnails"); caca_printf(screen_list->cv, x, y++, "d: Detach"); caca_printf(screen_list->cv, x, y++, "k: Close window and kill associated process"); caca_printf(screen_list->cv, x, y++, "h: Dump screen into a file"); caca_printf(screen_list->cv, x, y++, "?: This help"); caca_printf(screen_list->cv, x, y++, ""); caca_printf(screen_list->cv, x, y++, ""); caca_printf(screen_list->cv, x, y, "See http://caca.zoy.org/wiki/neercs for more informations"); } #endif |
@@ -1,94 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2011 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* 2008-2010 Pascal Terjan <pterjan@linuxfr.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <stdio.h> /* BUFSIZ */ | |||||
#include <string.h> /* strncmp() */ | |||||
#include <caca.h> | |||||
#include "mini-neercs.h" | |||||
#include "mini-socket.h" | |||||
static caca_display_t *dp; | |||||
static caca_canvas_t *cv; | |||||
static nrx_socket_t *insock, *outsock; | |||||
void client_init(void) | |||||
{ | |||||
int i, usec = 10000; | |||||
cv = caca_create_canvas(0, 0); | |||||
dp = caca_create_display(cv); | |||||
caca_set_display_title(dp, "Press Esc to quit"); | |||||
insock = socket_open("/tmp/neercs.sock.client", 1); | |||||
for (i = 0; i < 10; i++) | |||||
{ | |||||
outsock = socket_open("/tmp/neercs.sock", 0); | |||||
if (outsock) | |||||
break; | |||||
usleep(usec); | |||||
usec += usec; | |||||
} | |||||
socket_puts(outsock, "CONNECT /tmp/neercs.sock.client"); | |||||
} | |||||
int client_step(void) | |||||
{ | |||||
caca_event_t ev; | |||||
int ret; | |||||
/* Handle client sockets */ | |||||
ret = socket_select(insock, 1000); | |||||
if (ret > 0) | |||||
{ | |||||
char buf[BUFSIZ]; | |||||
ssize_t bytes = socket_read(insock, buf, BUFSIZ); | |||||
if (bytes <= 0) | |||||
return 1; | |||||
/* Parse message */ | |||||
if (!strncmp(buf, "OK", strlen("OK"))) | |||||
{ | |||||
fprintf(stderr, "neercs: connection established\n"); | |||||
socket_puts(insock, "TEST insock"); | |||||
} | |||||
} | |||||
/* Handle libcaca events */ | |||||
if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 1000) | |||||
&& caca_get_event_key_ch(&ev) == CACA_KEY_ESCAPE) | |||||
return 0; | |||||
return 1; | |||||
} | |||||
void client_fini(void) | |||||
{ | |||||
socket_puts(outsock, "QUIT /tmp/neercs.sock.client"); | |||||
caca_free_display(dp); | |||||
caca_free_canvas(cv); | |||||
if (insock) | |||||
socket_close(insock); | |||||
if (outsock) | |||||
socket_close(outsock); | |||||
} | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2011 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2008-2010 Pascal Terjan <pterjan@linuxfr.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #include <stdio.h> /* BUFSIZ */ #include <string.h> /* strncmp() */ #include <caca.h> #include "mini-neercs.h" #include "mini-socket.h" static caca_display_t *dp; static caca_canvas_t *cv; static nrx_socket_t *insock, *outsock; void client_init(void) { int i, usec = 10000; cv = caca_create_canvas(0, 0); dp = caca_create_display(cv); caca_set_display_title(dp, "Press Esc to quit"); insock = socket_open("/tmp/neercs.sock.client", 1); for (i = 0; i < 10; i++) { outsock = socket_open("/tmp/neercs.sock", 0); if (outsock) break; usleep(usec); usec += usec; } socket_puts(outsock, "CONNECT /tmp/neercs.sock.client"); } int client_step(void) { caca_event_t ev; int ret; /* Handle client sockets */ ret = socket_select(insock, 1000); if (ret > 0) { char buf[BUFSIZ]; ssize_t bytes = socket_read(insock, buf, BUFSIZ); if (bytes <= 0) return 1; /* Parse message */ if (!strncmp(buf, "OK", strlen("OK"))) { fprintf(stderr, "neercs: connection established\n"); socket_puts(insock, "TEST insock"); } } /* Handle libcaca events */ if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 1000) && caca_get_event_key_ch(&ev) == CACA_KEY_ESCAPE) return 0; return 1; } void client_fini(void) { socket_puts(outsock, "QUIT /tmp/neercs.sock.client"); caca_free_display(dp); caca_free_canvas(cv); if (insock) socket_close(insock); if (outsock) socket_close(outsock); } |
@@ -1,52 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* 2008-2010 Pascal Terjan <pterjan@linuxfr.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <stdlib.h> | |||||
#include <stdio.h> /* perror() */ | |||||
#include <unistd.h> /* fork() */ | |||||
#include "mini-neercs.h" | |||||
int main(void) | |||||
{ | |||||
pid_t pid; | |||||
pid = fork(); | |||||
if (pid < 0) | |||||
{ | |||||
perror("fork"); | |||||
return EXIT_FAILURE; | |||||
} | |||||
if (pid > 0) | |||||
{ | |||||
client_init(); | |||||
while(client_step()) ; | |||||
client_fini(); | |||||
} | |||||
else | |||||
{ | |||||
server_init(); | |||||
while(server_step()) ; | |||||
server_fini(); | |||||
} | |||||
return EXIT_SUCCESS; | |||||
} | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2008-2010 Pascal Terjan <pterjan@linuxfr.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #include <stdlib.h> #include <stdio.h> /* perror() */ #include <unistd.h> /* fork() */ #include "mini-neercs.h" int main(void) { pid_t pid; pid = fork(); if (pid < 0) { perror("fork"); return EXIT_FAILURE; } if (pid > 0) { client_init(); while(client_step()) ; client_fini(); } else { server_init(); while(server_step()) ; server_fini(); } return EXIT_SUCCESS; } |
@@ -1,22 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* 2008-2010 Pascal Terjan <pterjan@linuxfr.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
void client_init(void); | |||||
int client_step(void); | |||||
void client_fini(void); | |||||
void server_init(void); | |||||
int server_step(void); | |||||
void server_fini(void); | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2008-2010 Pascal Terjan <pterjan@linuxfr.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ void client_init(void); int client_step(void); void client_fini(void); void server_init(void); int server_step(void); void server_fini(void); |
@@ -1,80 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2011 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* 2008-2010 Pascal Terjan <pterjan@linuxfr.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <stdio.h> /* BUFSIZ */ | |||||
#include <string.h> /* strncmp() */ | |||||
#include "mini-neercs.h" | |||||
#include "mini-socket.h" | |||||
static nrx_socket_t *insock, *outsock; | |||||
void server_init(void) | |||||
{ | |||||
while (!insock) | |||||
insock = socket_open("/tmp/neercs.sock", 1); | |||||
} | |||||
int server_step(void) | |||||
{ | |||||
char buf[BUFSIZ]; | |||||
ssize_t bytes; | |||||
int ret; | |||||
if (outsock) | |||||
{ | |||||
ret = socket_select(outsock, 1000); | |||||
if (ret <= 0) | |||||
goto nothing; | |||||
bytes = socket_read(outsock, buf, BUFSIZ); | |||||
if (bytes <= 0) | |||||
goto nothing; | |||||
} | |||||
nothing: | |||||
ret = socket_select(insock, 1000); | |||||
if (ret <= 0) | |||||
return 1; | |||||
bytes = socket_read(insock, buf, BUFSIZ); | |||||
if (bytes <= 0) | |||||
return 1; | |||||
/* Parse message */ | |||||
if (!strncmp(buf, "CONNECT ", strlen("CONNECT "))) | |||||
{ | |||||
outsock = socket_open(buf + strlen("CONNECT "), 0); | |||||
socket_puts(outsock, "OK"); | |||||
} | |||||
else if (!strncmp(buf, "QUIT ", strlen("QUIT "))) | |||||
{ | |||||
return 0; | |||||
} | |||||
return 1; | |||||
} | |||||
void server_fini(void) | |||||
{ | |||||
if (insock) | |||||
socket_close(insock); | |||||
if (outsock) | |||||
socket_close(outsock); | |||||
} | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2011 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2008-2010 Pascal Terjan <pterjan@linuxfr.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #include <stdio.h> /* BUFSIZ */ #include <string.h> /* strncmp() */ #include "mini-neercs.h" #include "mini-socket.h" static nrx_socket_t *insock, *outsock; void server_init(void) { while (!insock) insock = socket_open("/tmp/neercs.sock", 1); } int server_step(void) { char buf[BUFSIZ]; ssize_t bytes; int ret; if (outsock) { ret = socket_select(outsock, 1000); if (ret <= 0) goto nothing; bytes = socket_read(outsock, buf, BUFSIZ); if (bytes <= 0) goto nothing; } nothing: ret = socket_select(insock, 1000); if (ret <= 0) return 1; bytes = socket_read(insock, buf, BUFSIZ); if (bytes <= 0) return 1; /* Parse message */ if (!strncmp(buf, "CONNECT ", strlen("CONNECT "))) { outsock = socket_open(buf + strlen("CONNECT "), 0); socket_puts(outsock, "OK"); } else if (!strncmp(buf, "QUIT ", strlen("QUIT "))) { return 0; } return 1; } void server_fini(void) { if (insock) socket_close(insock); if (outsock) socket_close(outsock); } |
@@ -1,24 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* 2008-2010 Pascal Terjan <pterjan@linuxfr.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#include <sys/types.h> | |||||
typedef struct nrx_socket nrx_socket_t; | |||||
nrx_socket_t * socket_open(char const *path, int server); | |||||
int socket_select(nrx_socket_t *sock, int usecs); | |||||
int socket_puts(nrx_socket_t *sock, char const *str); | |||||
ssize_t socket_read(nrx_socket_t *sock, void *buf, size_t count); | |||||
void socket_close(nrx_socket_t *socket); | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * 2008-2010 Pascal Terjan <pterjan@linuxfr.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #include <sys/types.h> typedef struct nrx_socket nrx_socket_t; nrx_socket_t * socket_open(char const *path, int server); int socket_select(nrx_socket_t *sock, int usecs); int socket_puts(nrx_socket_t *sock, char const *str); ssize_t socket_read(nrx_socket_t *sock, void *buf, size_t count); void socket_close(nrx_socket_t *socket); |
@@ -1,127 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
/* | |||||
* mygetopt.c: getopt_long reimplementation | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include "caca_types.h" | |||||
#include "mygetopt.h" | |||||
int myoptind = 1; | |||||
char *myoptarg = NULL; | |||||
/* XXX: this getopt_long implementation should not be trusted for other | |||||
applications without any serious peer reviewing. It “just works” with | |||||
zzuf but may fail miserably in other programs. */ | |||||
int mygetopt(int argc, char *const _argv[], const char *optstring, | |||||
const struct myoption *longopts, int *longindex) | |||||
{ | |||||
char **argv = (char **)(uintptr_t) _argv; | |||||
char *flag; | |||||
int i; | |||||
if (myoptind >= argc) | |||||
return -1; | |||||
flag = argv[myoptind]; | |||||
if (flag[0] == '-' && flag[1] != '-') | |||||
{ | |||||
char const *tmp; | |||||
int ret = flag[1]; | |||||
if (ret == '\0') | |||||
return -1; | |||||
tmp = strchr(optstring, ret); | |||||
if (!tmp || ret == ':') | |||||
return '?'; | |||||
myoptind++; | |||||
if (tmp[1] == ':') | |||||
{ | |||||
if (flag[2] != '\0') | |||||
myoptarg = flag + 2; | |||||
else if (myoptind >= argc) | |||||
{ | |||||
if (tmp[2] != ':') | |||||
{ | |||||
fprintf(stderr, "%s: `%s' needs an argument\n", argv[0], | |||||
flag); | |||||
return -2; | |||||
} | |||||
} | |||||
else | |||||
myoptarg = argv[myoptind++]; | |||||
return ret; | |||||
} | |||||
if (flag[2] != '\0') | |||||
{ | |||||
flag[1] = '-'; | |||||
myoptind--; | |||||
argv[myoptind]++; | |||||
} | |||||
return ret; | |||||
} | |||||
if (flag[0] == '-' && flag[1] == '-') | |||||
{ | |||||
if (flag[2] == '\0') | |||||
return -1; | |||||
for (i = 0; longopts[i].name; i++) | |||||
{ | |||||
size_t l = strlen(longopts[i].name); | |||||
if (strncmp(flag + 2, longopts[i].name, l)) | |||||
continue; | |||||
switch (flag[2 + l]) | |||||
{ | |||||
case '=': | |||||
if (!longopts[i].has_arg) | |||||
goto bad_opt; | |||||
if (longindex) | |||||
*longindex = i; | |||||
myoptind++; | |||||
myoptarg = flag + 2 + l + 1; | |||||
return longopts[i].val; | |||||
case '\0': | |||||
if (longindex) | |||||
*longindex = i; | |||||
myoptind++; | |||||
if (longopts[i].has_arg) | |||||
myoptarg = argv[myoptind++]; | |||||
return longopts[i].val; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
bad_opt: | |||||
fprintf(stderr, "%s: unrecognized option `%s'\n", argv[0], flag); | |||||
return '?'; | |||||
} | |||||
return -1; | |||||
} | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ /* * mygetopt.c: getopt_long reimplementation */ #if defined HAVE_CONFIG_H # include "config.h" #endif #include <stdio.h> #include <string.h> #include "caca_types.h" #include "mygetopt.h" int myoptind = 1; char *myoptarg = NULL; /* XXX: this getopt_long implementation should not be trusted for other applications without any serious peer reviewing. It “just works” with zzuf but may fail miserably in other programs. */ int mygetopt(int argc, char *const _argv[], const char *optstring, const struct myoption *longopts, int *longindex) { char **argv = (char **)(uintptr_t) _argv; char *flag; int i; if (myoptind >= argc) return -1; flag = argv[myoptind]; if (flag[0] == '-' && flag[1] != '-') { char const *tmp; int ret = flag[1]; if (ret == '\0') return -1; tmp = strchr(optstring, ret); if (!tmp || ret == ':') return '?'; myoptind++; if (tmp[1] == ':') { if (flag[2] != '\0') myoptarg = flag + 2; else if (myoptind >= argc) { if (tmp[2] != ':') { fprintf(stderr, "%s: `%s' needs an argument\n", argv[0], flag); return -2; } } else myoptarg = argv[myoptind++]; return ret; } if (flag[2] != '\0') { flag[1] = '-'; myoptind--; argv[myoptind]++; } return ret; } if (flag[0] == '-' && flag[1] == '-') { if (flag[2] == '\0') return -1; for (i = 0; longopts[i].name; i++) { size_t l = strlen(longopts[i].name); if (strncmp(flag + 2, longopts[i].name, l)) continue; switch (flag[2 + l]) { case '=': if (!longopts[i].has_arg) goto bad_opt; if (longindex) *longindex = i; myoptind++; myoptarg = flag + 2 + l + 1; return longopts[i].val; case '\0': if (longindex) *longindex = i; myoptind++; if (longopts[i].has_arg) myoptarg = argv[myoptind++]; return longopts[i].val; default: break; } } bad_opt: fprintf(stderr, "%s: unrecognized option `%s'\n", argv[0], flag); return '?'; } return -1; } |
@@ -1,30 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
/* | |||||
* mygetopt.h: getopt_long reimplementation | |||||
*/ | |||||
struct myoption | |||||
{ | |||||
const char *name; | |||||
int has_arg; | |||||
int *flag; | |||||
int val; | |||||
}; | |||||
extern int myoptind; | |||||
extern char *myoptarg; | |||||
int mygetopt(int, char * const[], const char *, const struct myoption *, int *); | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ /* * mygetopt.h: getopt_long reimplementation */ struct myoption { const char *name; int has_arg; int *flag; int val; }; extern int myoptind; extern char *myoptarg; int mygetopt(int, char * const[], const char *, const struct myoption *, int *); |
@@ -1,37 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2008-2010 Sam Hocevar <sam@hocevar.net> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if !defined _WIN32 | |||||
#include <termios.h> | |||||
struct mytrace; | |||||
struct mytrace* mytrace_attach(long int pid); | |||||
struct mytrace* mytrace_fork(struct mytrace *t); | |||||
int mytrace_detach(struct mytrace *t); | |||||
long mytrace_getpid(struct mytrace *t); | |||||
int mytrace_open(struct mytrace *t, char const *path, int mode); | |||||
int mytrace_write(struct mytrace *t, int fd, char const *data, size_t len); | |||||
int mytrace_close(struct mytrace *t, int fd); | |||||
int mytrace_dup2(struct mytrace *t, int oldfd, int newfd); | |||||
int mytrace_setpgid(struct mytrace *t, long pid, long pgid); | |||||
int mytrace_setsid(struct mytrace *t); | |||||
int mytrace_kill(struct mytrace *t, long pid, int sig); | |||||
int mytrace_exit(struct mytrace *t, int status); | |||||
int mytrace_exec(struct mytrace *t, char const *command); | |||||
int mytrace_tcgets(struct mytrace *t, int fd, struct termios *tos); | |||||
int mytrace_tcsets(struct mytrace *t, int fd, struct termios *tos); | |||||
int mytrace_sctty(struct mytrace *t, int fd); | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2008-2010 Sam Hocevar <sam@hocevar.net> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if !defined _WIN32 #include <termios.h> struct mytrace; struct mytrace* mytrace_attach(long int pid); struct mytrace* mytrace_fork(struct mytrace *t); int mytrace_detach(struct mytrace *t); long mytrace_getpid(struct mytrace *t); int mytrace_open(struct mytrace *t, char const *path, int mode); int mytrace_write(struct mytrace *t, int fd, char const *data, size_t len); int mytrace_close(struct mytrace *t, int fd); int mytrace_dup2(struct mytrace *t, int oldfd, int newfd); int mytrace_setpgid(struct mytrace *t, long pid, long pgid); int mytrace_setsid(struct mytrace *t); int mytrace_kill(struct mytrace *t, long pid, int sig); int mytrace_exit(struct mytrace *t, int status); int mytrace_exec(struct mytrace *t, char const *command); int mytrace_tcgets(struct mytrace *t, int fd, struct termios *tos); int mytrace_tcsets(struct mytrace *t, int fd, struct termios *tos); int mytrace_sctty(struct mytrace *t, int fd); #endif |
@@ -1,199 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#ifdef USE_PYTHON | |||||
#include <Python.h> | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <unistd.h> | |||||
#include <fcntl.h> | |||||
#include <signal.h> | |||||
#include <sys/ioctl.h> | |||||
#include <sys/socket.h> | |||||
#include <sys/time.h> | |||||
#include <time.h> | |||||
#include <sys/wait.h> | |||||
#include <sys/types.h> | |||||
#include <caca.h> | |||||
#include "neercs.h" | |||||
#include "py_module.h" | |||||
static int python_execute(struct screen_list *sl); | |||||
char *getStringFromPyObject(PyObject * p); | |||||
static char *getPythonError(void); | |||||
#if ! defined HAVE_PYTHON26 | |||||
static PyObject *PyUnicode_FromString(char const *str) | |||||
{ | |||||
PyObject *tmp, *ret; | |||||
tmp = PyString_FromString(str); | |||||
if (!tmp) | |||||
return NULL; | |||||
ret = PyString_AsDecodedObject(tmp, "utf-8", "replace"); | |||||
Py_DECREF(tmp); | |||||
return ret; | |||||
} | |||||
#endif | |||||
int python_command_handle_key(struct screen_list *screen_list, unsigned int c) | |||||
{ | |||||
int ret = widget_ibox_handle_key(screen_list->interpreter_props.box, c); | |||||
if (ret == INPUT_BOX_ESC) | |||||
{ | |||||
widget_ibox_destroy(screen_list->interpreter_props.box); | |||||
screen_list->interpreter_props.box = NULL; | |||||
screen_list->modals.python_command = 0; | |||||
} | |||||
else if (ret == INPUT_BOX_RET) | |||||
{ | |||||
python_execute(screen_list); | |||||
} | |||||
screen_list->changed = 1; | |||||
return 1; | |||||
} | |||||
void draw_python_command(struct screen_list *screen_list) | |||||
{ | |||||
if (!screen_list->interpreter_props.box) | |||||
{ | |||||
screen_list->interpreter_props.box = | |||||
widget_ibox_init(screen_list->cv, 65, 6); | |||||
debug("py Init %p\n", screen_list->interpreter_props.box); | |||||
} | |||||
widget_ibox_draw(screen_list->interpreter_props.box); | |||||
} | |||||
/* Actual Python interpreter stuff */ | |||||
int python_init(struct screen_list *sl) | |||||
{ | |||||
initNeercsModule(sl); | |||||
return 0; | |||||
} | |||||
int python_close(struct screen_list *sl) | |||||
{ | |||||
widget_ibox_destroy(sl->interpreter_props.box); | |||||
sl->interpreter_props.box = NULL; | |||||
Py_Finalize(); | |||||
return 0; | |||||
} | |||||
static int python_execute(struct screen_list *sl) | |||||
{ | |||||
char *command = widget_ibox_get_text(sl->interpreter_props.box); | |||||
if (!command || strlen(command) < 1) | |||||
return -1; | |||||
int err = 0; | |||||
debug("py Executing '%s'\n", command); | |||||
PyObject *pModule, *pName; | |||||
/* Module from which to call the function */ | |||||
pName = PyUnicode_FromString("neercs"); | |||||
if (!pName) | |||||
{ | |||||
widget_ibox_set_error(sl->interpreter_props.box, getPythonError()); | |||||
err = 1; | |||||
debug("py Error 1\n"); | |||||
goto end; | |||||
} | |||||
pModule = PyImport_Import(pName); | |||||
Py_DECREF(pName); | |||||
if (pModule != NULL) | |||||
{ | |||||
PyObject *dictionary = PyModule_GetDict(pModule); | |||||
getExportedValues(dictionary); | |||||
PyObject *o = | |||||
PyRun_String(command, Py_single_input, | |||||
dictionary, NULL); | |||||
if (!o) | |||||
{ | |||||
widget_ibox_set_error(sl->interpreter_props.box, getPythonError()); | |||||
err = 1; | |||||
} | |||||
else | |||||
{ | |||||
setExportedValues(dictionary); | |||||
widget_ibox_set_msg(sl->interpreter_props.box, getStringFromPyObject(o)); | |||||
err = 1; | |||||
} | |||||
Py_DECREF(pModule); | |||||
} | |||||
else | |||||
{ | |||||
widget_ibox_set_error(sl->interpreter_props.box, getPythonError()); | |||||
err = 1; | |||||
} | |||||
end: | |||||
if (!err) | |||||
{ | |||||
widget_ibox_destroy(sl->interpreter_props.box); | |||||
sl->interpreter_props.box = NULL; | |||||
sl->modals.python_command = 0; | |||||
} | |||||
sl->changed = 1; | |||||
return 0; | |||||
} | |||||
static char *getPythonError(void) | |||||
{ | |||||
char *err; | |||||
PyObject *type, *value, *traceback; | |||||
PyErr_Fetch(&type, &value, &traceback); | |||||
char *evalue = getStringFromPyObject(value); | |||||
int r = asprintf(&err, "%s", evalue); | |||||
(void)r; | |||||
return err; | |||||
} | |||||
char *getStringFromPyObject(PyObject * p) | |||||
{ | |||||
PyObject *str = PyObject_Repr(p); | |||||
char *tmp; | |||||
#if defined HAVE_PYTHON26 | |||||
tmp = PyBytes_AS_STRING(PyUnicode_AsEncodedString(str, "utf-8", "Error ~")); | |||||
#else | |||||
tmp = PyString_AsString(str); | |||||
#endif | |||||
return strdup(tmp); | |||||
} | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #ifdef USE_PYTHON #include <Python.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <signal.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/time.h> #include <time.h> #include <sys/wait.h> #include <sys/types.h> #include <caca.h> #include "neercs.h" #include "py_module.h" static int python_execute(struct screen_list *sl); char *getStringFromPyObject(PyObject * p); static char *getPythonError(void); #if ! defined HAVE_PYTHON26 static PyObject *PyUnicode_FromString(char const *str) { PyObject *tmp, *ret; tmp = PyString_FromString(str); if (!tmp) return NULL; ret = PyString_AsDecodedObject(tmp, "utf-8", "replace"); Py_DECREF(tmp); return ret; } #endif int python_command_handle_key(struct screen_list *screen_list, unsigned int c) { int ret = widget_ibox_handle_key(screen_list->interpreter_props.box, c); if (ret == INPUT_BOX_ESC) { widget_ibox_destroy(screen_list->interpreter_props.box); screen_list->interpreter_props.box = NULL; screen_list->modals.python_command = 0; } else if (ret == INPUT_BOX_RET) { python_execute(screen_list); } screen_list->changed = 1; return 1; } void draw_python_command(struct screen_list *screen_list) { if (!screen_list->interpreter_props.box) { screen_list->interpreter_props.box = widget_ibox_init(screen_list->cv, 65, 6); debug("py Init %p\n", screen_list->interpreter_props.box); } widget_ibox_draw(screen_list->interpreter_props.box); } /* Actual Python interpreter stuff */ int python_init(struct screen_list *sl) { initNeercsModule(sl); return 0; } int python_close(struct screen_list *sl) { widget_ibox_destroy(sl->interpreter_props.box); sl->interpreter_props.box = NULL; Py_Finalize(); return 0; } static int python_execute(struct screen_list *sl) { char *command = widget_ibox_get_text(sl->interpreter_props.box); if (!command || strlen(command) < 1) return -1; int err = 0; debug("py Executing '%s'\n", command); PyObject *pModule, *pName; /* Module from which to call the function */ pName = PyUnicode_FromString("neercs"); if (!pName) { widget_ibox_set_error(sl->interpreter_props.box, getPythonError()); err = 1; debug("py Error 1\n"); goto end; } pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { PyObject *dictionary = PyModule_GetDict(pModule); getExportedValues(dictionary); PyObject *o = PyRun_String(command, Py_single_input, dictionary, NULL); if (!o) { widget_ibox_set_error(sl->interpreter_props.box, getPythonError()); err = 1; } else { setExportedValues(dictionary); widget_ibox_set_msg(sl->interpreter_props.box, getStringFromPyObject(o)); err = 1; } Py_DECREF(pModule); } else { widget_ibox_set_error(sl->interpreter_props.box, getPythonError()); err = 1; } end: if (!err) { widget_ibox_destroy(sl->interpreter_props.box); sl->interpreter_props.box = NULL; sl->modals.python_command = 0; } sl->changed = 1; return 0; } static char *getPythonError(void) { char *err; PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); char *evalue = getStringFromPyObject(value); int r = asprintf(&err, "%s", evalue); (void)r; return err; } char *getStringFromPyObject(PyObject * p) { PyObject *str = PyObject_Repr(p); char *tmp; #if defined HAVE_PYTHON26 tmp = PyBytes_AS_STRING(PyUnicode_AsEncodedString(str, "utf-8", "Error ~")); #else tmp = PyString_AsString(str); #endif return strdup(tmp); } #endif |
@@ -1,195 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#ifdef USE_PYTHON | |||||
#include <Python.h> | |||||
#include "py_module.h" | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <unistd.h> | |||||
#include <fcntl.h> | |||||
#include <signal.h> | |||||
#include <sys/ioctl.h> | |||||
#include <sys/socket.h> | |||||
#include <sys/time.h> | |||||
#include <time.h> | |||||
#include <sys/wait.h> | |||||
#include <sys/types.h> | |||||
#include <caca.h> | |||||
#include "neercs.h" | |||||
/* FIXME : Find a way to pass a user pointer to PyModuleDef or something */ | |||||
static struct screen_list *screen_list; | |||||
#if defined HAVE_PYTHON3 | |||||
static PyObject *PyInit_neercs(void); | |||||
#else | |||||
static void PyInit_neercs(void); | |||||
#endif | |||||
static void removeTrailingStuff(char *b); | |||||
static void addVariableFromConfig(PyObject * dictionary, | |||||
const char *varname, const char *configname) | |||||
{ | |||||
char *v = get_config(configname)->get(screen_list); | |||||
if (v != NULL) | |||||
{ | |||||
PyObject *value = Py_BuildValue("s", v); | |||||
PyDict_SetItemString(dictionary, varname, value); | |||||
} | |||||
debug("py get '%s' to '%s'\n", varname, | |||||
get_config(configname)->get(screen_list)); | |||||
} | |||||
static void removeTrailingStuff(char *b) | |||||
{ | |||||
if(!b) | |||||
return; | |||||
if(b[0]=='\'') | |||||
{ | |||||
memmove(b, &b[1], strlen(b)-1); | |||||
b[strlen(b)-2] = 0; | |||||
} | |||||
} | |||||
void setExportedValues(PyObject * dictionary) | |||||
{ | |||||
struct config_line *config_option = get_config_option(); | |||||
int i = 0; | |||||
while (strncmp(config_option[i].name, "last", strlen("last"))) | |||||
{ | |||||
/* Get variable */ | |||||
PyObject *res = | |||||
PyDict_GetItemString(dictionary, config_option[i].name); | |||||
/* Got it */ | |||||
if (res) | |||||
{ | |||||
/* Get object representation | |||||
* FIXME : find a way to check object's type */ | |||||
PyObject *str = PyObject_Repr(res); | |||||
/* Make sure it's a string */ | |||||
char *err = | |||||
#if defined HAVE_PYTHON3 | |||||
PyBytes_AS_STRING(PyUnicode_AsEncodedString | |||||
(str, "utf-8", "Error ~")); | |||||
#elif defined HAVE_PYTHON2 | |||||
PyString_AsString(str); | |||||
#endif | |||||
/* FIXME leak leak leak */ | |||||
char *s = strdup(err); | |||||
if (s != NULL) | |||||
{ | |||||
/* Representation can include '' around strings */ | |||||
removeTrailingStuff(s); | |||||
get_config(config_option[i].name)->set(s, screen_list); | |||||
} | |||||
} | |||||
i++; | |||||
} | |||||
} | |||||
void getExportedValues(PyObject * dictionary) | |||||
{ | |||||
struct config_line *config_option = get_config_option(); | |||||
int i = 0; | |||||
while (strncmp(config_option[i].name, "last", strlen("last"))) | |||||
{ | |||||
addVariableFromConfig(dictionary, config_option[i].name, | |||||
config_option[i].name); | |||||
i++; | |||||
} | |||||
} | |||||
static PyObject *neercs_get(PyObject * self, PyObject * args) | |||||
{ | |||||
char *s = NULL; | |||||
debug("Get using list at %p", screen_list); | |||||
if (!PyArg_ParseTuple(args, "s", &s)) | |||||
{ | |||||
PyErr_SetString(PyExc_ValueError, "Can't parse argument"); | |||||
debug("py Can't parse"); | |||||
return NULL; | |||||
} | |||||
debug("py Argument : '%s'", s); | |||||
struct config_line *c = get_config(s); | |||||
if (c) | |||||
return Py_BuildValue("s", c->get(screen_list)); | |||||
PyErr_SetString(PyExc_ValueError, | |||||
"Can't get value for specified variable"); | |||||
return NULL; | |||||
} | |||||
static PyObject *neercs_version(PyObject * self, PyObject * args) | |||||
{ | |||||
return Py_BuildValue("s", PACKAGE_VERSION); | |||||
} | |||||
static PyMethodDef NeercsMethods[] = | |||||
{ | |||||
{ "version", neercs_version, METH_NOARGS, "Return the neercs version." }, | |||||
{ "get", neercs_get, METH_VARARGS, | |||||
"Return the specified variable's value." }, | |||||
{ NULL, NULL, 0, NULL } | |||||
}; | |||||
#if defined HAVE_PYTHON3 | |||||
static PyObject *PyInit_neercs(void) | |||||
{ | |||||
static PyModuleDef NeercsModule = | |||||
{ | |||||
PyModuleDef_HEAD_INIT, "neercs", NULL, -1, NeercsMethods, | |||||
NULL, NULL, NULL, NULL | |||||
}; | |||||
return PyModule_Create(&NeercsModule); | |||||
} | |||||
#elif defined HAVE_PYTHON2 | |||||
static void PyInit_neercs(void) | |||||
{ | |||||
PyMethodDef *m = NeercsMethods; | |||||
PyObject *mod = PyModule_New("neercs"); | |||||
PyModule_AddStringConstant(mod, "__file__", "<synthetic>"); | |||||
for (m = NeercsMethods; m->ml_name; m++) | |||||
PyModule_AddObject(mod, m->ml_name, PyCFunction_New(m, NULL)); | |||||
} | |||||
#endif | |||||
void initNeercsModule(struct screen_list *sl) | |||||
{ | |||||
screen_list = sl; | |||||
PyImport_AppendInittab("neercs", &PyInit_neercs); | |||||
Py_Initialize(); | |||||
} | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #ifdef USE_PYTHON #include <Python.h> #include "py_module.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <signal.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/time.h> #include <time.h> #include <sys/wait.h> #include <sys/types.h> #include <caca.h> #include "neercs.h" /* FIXME : Find a way to pass a user pointer to PyModuleDef or something */ static struct screen_list *screen_list; #if defined HAVE_PYTHON3 static PyObject *PyInit_neercs(void); #else static void PyInit_neercs(void); #endif static void removeTrailingStuff(char *b); static void addVariableFromConfig(PyObject * dictionary, const char *varname, const char *configname) { char *v = get_config(configname)->get(screen_list); if (v != NULL) { PyObject *value = Py_BuildValue("s", v); PyDict_SetItemString(dictionary, varname, value); } debug("py get '%s' to '%s'\n", varname, get_config(configname)->get(screen_list)); } static void removeTrailingStuff(char *b) { if(!b) return; if(b[0]=='\'') { memmove(b, &b[1], strlen(b)-1); b[strlen(b)-2] = 0; } } void setExportedValues(PyObject * dictionary) { struct config_line *config_option = get_config_option(); int i = 0; while (strncmp(config_option[i].name, "last", strlen("last"))) { /* Get variable */ PyObject *res = PyDict_GetItemString(dictionary, config_option[i].name); /* Got it */ if (res) { /* Get object representation * FIXME : find a way to check object's type */ PyObject *str = PyObject_Repr(res); /* Make sure it's a string */ char *err = #if defined HAVE_PYTHON3 PyBytes_AS_STRING(PyUnicode_AsEncodedString (str, "utf-8", "Error ~")); #elif defined HAVE_PYTHON2 PyString_AsString(str); #endif /* FIXME leak leak leak */ char *s = strdup(err); if (s != NULL) { /* Representation can include '' around strings */ removeTrailingStuff(s); get_config(config_option[i].name)->set(s, screen_list); } } i++; } } void getExportedValues(PyObject * dictionary) { struct config_line *config_option = get_config_option(); int i = 0; while (strncmp(config_option[i].name, "last", strlen("last"))) { addVariableFromConfig(dictionary, config_option[i].name, config_option[i].name); i++; } } static PyObject *neercs_get(PyObject * self, PyObject * args) { char *s = NULL; debug("Get using list at %p", screen_list); if (!PyArg_ParseTuple(args, "s", &s)) { PyErr_SetString(PyExc_ValueError, "Can't parse argument"); debug("py Can't parse"); return NULL; } debug("py Argument : '%s'", s); struct config_line *c = get_config(s); if (c) return Py_BuildValue("s", c->get(screen_list)); PyErr_SetString(PyExc_ValueError, "Can't get value for specified variable"); return NULL; } static PyObject *neercs_version(PyObject * self, PyObject * args) { return Py_BuildValue("s", PACKAGE_VERSION); } static PyMethodDef NeercsMethods[] = { { "version", neercs_version, METH_NOARGS, "Return the neercs version." }, { "get", neercs_get, METH_VARARGS, "Return the specified variable's value." }, { NULL, NULL, 0, NULL } }; #if defined HAVE_PYTHON3 static PyObject *PyInit_neercs(void) { static PyModuleDef NeercsModule = { PyModuleDef_HEAD_INIT, "neercs", NULL, -1, NeercsMethods, NULL, NULL, NULL, NULL }; return PyModule_Create(&NeercsModule); } #elif defined HAVE_PYTHON2 static void PyInit_neercs(void) { PyMethodDef *m = NeercsMethods; PyObject *mod = PyModule_New("neercs"); PyModule_AddStringConstant(mod, "__file__", "<synthetic>"); for (m = NeercsMethods; m->ml_name; m++) PyModule_AddObject(mod, m->ml_name, PyCFunction_New(m, NULL)); } #endif void initNeercsModule(struct screen_list *sl) { screen_list = sl; PyImport_AppendInittab("neercs", &PyInit_neercs); Py_Initialize(); } #endif |
@@ -1,23 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#ifdef USE_PYTHON | |||||
#include <Python.h> | |||||
#include "neercs.h" | |||||
void initNeercsModule(struct screen_list *sl); | |||||
void getExportedValues(PyObject * dictionary); | |||||
void setExportedValues(PyObject * dictionary); | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #ifdef USE_PYTHON #include <Python.h> #include "neercs.h" void initNeercsModule(struct screen_list *sl); void getExportedValues(PyObject * dictionary); void setExportedValues(PyObject * dictionary); #endif |
@@ -1,118 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#if !defined _WIN32 | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include <stdlib.h> | |||||
#include <sys/types.h> | |||||
#include <signal.h> | |||||
#include <sys/wait.h> | |||||
#include <errno.h> | |||||
#include <unistd.h> | |||||
#include "neercs.h" | |||||
int handle_recurrents(struct screen_list *screen_list) | |||||
{ | |||||
int refresh = 0, i; | |||||
/* Recurrent functions */ | |||||
for (i = 0; i < screen_list->recurrent_list->count; i++) | |||||
{ | |||||
if (screen_list->recurrent_list->recurrent[i]->function) | |||||
{ | |||||
refresh |= | |||||
screen_list->recurrent_list->recurrent[i]-> | |||||
function(screen_list, | |||||
screen_list->recurrent_list->recurrent[i], | |||||
screen_list->recurrent_list->recurrent[i]->user, | |||||
get_us()); | |||||
} | |||||
} | |||||
/* Delete recurrent functions */ | |||||
for (i = 0; i < screen_list->recurrent_list->count; i++) | |||||
{ | |||||
if (screen_list->recurrent_list->recurrent[i]->kill_me) | |||||
{ | |||||
remove_recurrent(screen_list->recurrent_list, i); | |||||
refresh = 1; | |||||
i = 0; | |||||
} | |||||
} | |||||
return refresh; | |||||
} | |||||
/* Add recurrent function. It will be called at each main loop iteration, | |||||
unless it is removed */ | |||||
int add_recurrent(struct recurrent_list *list, | |||||
int (*func) (struct screen_list *, struct recurrent * rec, | |||||
void *user, long long unsigned int t), | |||||
void *user) | |||||
{ | |||||
if (list == NULL || func == NULL) | |||||
return -1; | |||||
list->recurrent = (struct recurrent **)realloc(list->recurrent, | |||||
sizeof(struct recurrent *) | |||||
* (list->count + 1)); | |||||
if (!list->recurrent) | |||||
fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, | |||||
__LINE__); | |||||
list->recurrent[list->count] = malloc(sizeof(struct recurrent)); | |||||
list->recurrent[list->count]->kill_me = 0; | |||||
list->recurrent[list->count]->function = func; | |||||
list->recurrent[list->count]->user = user; | |||||
list->recurrent[list->count]->start_time = get_us(); | |||||
list->count++; | |||||
return list->count - 1; | |||||
} | |||||
/* Remove recurrent. Do *NOT* call this from a recurrent function. */ | |||||
int remove_recurrent(struct recurrent_list *list, int n) | |||||
{ | |||||
if (n >= list->count) | |||||
return -1; | |||||
memmove(&list->recurrent[n], | |||||
&list->recurrent[n + 1], | |||||
sizeof(struct recurrent *) * (list->count - (n + 1))); | |||||
free(list->recurrent[n]); | |||||
list->recurrent = (struct recurrent **)realloc(list->recurrent, | |||||
sizeof(sizeof | |||||
(struct recurrent *)) | |||||
* (list->count)); | |||||
if (!list->recurrent) | |||||
fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, | |||||
__LINE__); | |||||
list->count--; | |||||
return 0; | |||||
} | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #if !defined _WIN32 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <signal.h> #include <sys/wait.h> #include <errno.h> #include <unistd.h> #include "neercs.h" int handle_recurrents(struct screen_list *screen_list) { int refresh = 0, i; /* Recurrent functions */ for (i = 0; i < screen_list->recurrent_list->count; i++) { if (screen_list->recurrent_list->recurrent[i]->function) { refresh |= screen_list->recurrent_list->recurrent[i]-> function(screen_list, screen_list->recurrent_list->recurrent[i], screen_list->recurrent_list->recurrent[i]->user, get_us()); } } /* Delete recurrent functions */ for (i = 0; i < screen_list->recurrent_list->count; i++) { if (screen_list->recurrent_list->recurrent[i]->kill_me) { remove_recurrent(screen_list->recurrent_list, i); refresh = 1; i = 0; } } return refresh; } /* Add recurrent function. It will be called at each main loop iteration, unless it is removed */ int add_recurrent(struct recurrent_list *list, int (*func) (struct screen_list *, struct recurrent * rec, void *user, long long unsigned int t), void *user) { if (list == NULL || func == NULL) return -1; list->recurrent = (struct recurrent **)realloc(list->recurrent, sizeof(struct recurrent *) * (list->count + 1)); if (!list->recurrent) fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); list->recurrent[list->count] = malloc(sizeof(struct recurrent)); list->recurrent[list->count]->kill_me = 0; list->recurrent[list->count]->function = func; list->recurrent[list->count]->user = user; list->recurrent[list->count]->start_time = get_us(); list->count++; return list->count - 1; } /* Remove recurrent. Do *NOT* call this from a recurrent function. */ int remove_recurrent(struct recurrent_list *list, int n) { if (n >= list->count) return -1; memmove(&list->recurrent[n], &list->recurrent[n + 1], sizeof(struct recurrent *) * (list->count - (n + 1))); free(list->recurrent[n]); list->recurrent = (struct recurrent **)realloc(list->recurrent, sizeof(sizeof (struct recurrent *)) * (list->count)); if (!list->recurrent) fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); list->count--; return 0; } #endif |
@@ -1,193 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#if !defined _WIN32 | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include <stdlib.h> | |||||
#include <sys/types.h> | |||||
#include <signal.h> | |||||
#include <sys/wait.h> | |||||
#include <errno.h> | |||||
#include <unistd.h> | |||||
#include <caca.h> | |||||
#include "neercs.h" | |||||
void screensaver_init(struct screen_list *screen_list) | |||||
{ | |||||
screensaver_flying_toasters_init(screen_list); | |||||
} | |||||
void screensaver_kill(struct screen_list *screen_list) | |||||
{ | |||||
screensaver_flying_toasters_kill(screen_list); | |||||
} | |||||
void draw_screensaver(struct screen_list *screen_list) | |||||
{ | |||||
screensaver_flying_toasters(screen_list); | |||||
} | |||||
/* Flying Toasters */ | |||||
#define COUNT 15 | |||||
#define PRECISION 100 | |||||
char toaster_text[3][99] = { { | |||||
" __._ \n" | |||||
" .-'== _',\n" | |||||
" <|_= .-' |\n" | |||||
" | --| \\'.-_ \n" | |||||
" | | \\ \" _.\n" | |||||
" `-_|.-\\_.-\n"}, | |||||
{ | |||||
" __._ \n" | |||||
" .-'== _',\n" | |||||
" \\|_= .-' |\n" | |||||
" | --| __'-.\n" | |||||
" | | ___.-\n" | |||||
" `-_|.-\n"}, | |||||
{ | |||||
" _- __._\n" | |||||
" /.-'== _',_.-.\n" | |||||
" \\|_= .-'/ _.'\n" | |||||
" | --| / .-\n" | |||||
" | | _.|\n" | |||||
" `-_|.-\n"} | |||||
}; | |||||
char toaster_mask[3][99] = { { | |||||
" __._ \n" | |||||
" .-'== _',\n" | |||||
" <|_=X.-'XX|\n" | |||||
" |X--|XXX\\'.-_ \n" | |||||
" |XXX|X\\XX\"X_.\n" | |||||
" `-_|.-\\_.-\n"}, | |||||
{ | |||||
" __._ \n" | |||||
" .-'== _',\n" | |||||
" \\|_= .-'XX|\n" | |||||
" |X--|XX__'-.\n" | |||||
" |XXX|X___.-\n" | |||||
" `-_|.-\n"}, | |||||
{ | |||||
" _- __._\n" | |||||
" /.-'== _',_.-.\n" | |||||
" \\|_= .-'/XX_.'\n" | |||||
" |X--|X/X.-\n" | |||||
" |XXX|XX_.|\n" | |||||
" `-_|.-\n"} | |||||
}; | |||||
struct flying_toaster | |||||
{ | |||||
int x[COUNT], y[COUNT], s[COUNT]; | |||||
caca_canvas_t **toaster; | |||||
caca_canvas_t **mask; | |||||
}; | |||||
void screensaver_flying_toasters_init(struct screen_list *screen_list) | |||||
{ | |||||
struct flying_toaster *flying_toaster; | |||||
int w = caca_get_canvas_width(screen_list->cv); | |||||
int h = caca_get_canvas_height(screen_list->cv); | |||||
int i; | |||||
flying_toaster = malloc(sizeof(struct flying_toaster)); | |||||
flying_toaster->toaster = | |||||
(caca_canvas_t **) malloc(sizeof(caca_canvas_t *) * 3); | |||||
flying_toaster->mask = | |||||
(caca_canvas_t **) malloc(sizeof(caca_canvas_t *) * 3); | |||||
for (i = 0; i < 3; i++) | |||||
{ | |||||
flying_toaster->toaster[i] = caca_create_canvas(0, 0); | |||||
flying_toaster->mask[i] = caca_create_canvas(0, 0); | |||||
caca_import_canvas_from_memory(flying_toaster->toaster[i], | |||||
toaster_text[i], | |||||
strlen(toaster_text[i]), "utf8"); | |||||
caca_import_canvas_from_memory(flying_toaster->mask[i], | |||||
toaster_mask[i], | |||||
strlen(toaster_mask[i]), "utf8"); | |||||
} | |||||
for (i = 0; i < COUNT; i++) | |||||
{ | |||||
flying_toaster->x[i] = (rand() % w) * PRECISION; | |||||
flying_toaster->y[i] = (rand() % h) * PRECISION; | |||||
flying_toaster->s[i] = (rand() % 3) * PRECISION; | |||||
} | |||||
screen_list->screensaver.data = flying_toaster; | |||||
} | |||||
void screensaver_flying_toasters_kill(struct screen_list *screen_list) | |||||
{ | |||||
struct flying_toaster *flying_toaster = screen_list->screensaver.data; | |||||
caca_free_canvas(flying_toaster->toaster[0]); | |||||
caca_free_canvas(flying_toaster->toaster[1]); | |||||
caca_free_canvas(flying_toaster->toaster[2]); | |||||
free(flying_toaster->toaster); | |||||
free(flying_toaster); | |||||
screen_list->screensaver.data = NULL; | |||||
} | |||||
void screensaver_flying_toasters(struct screen_list *screen_list) | |||||
{ | |||||
struct flying_toaster *d = screen_list->screensaver.data; | |||||
int i, w, h, x, y, s; | |||||
if (!d) | |||||
return; | |||||
w = caca_get_canvas_width(screen_list->cv); | |||||
h = caca_get_canvas_height(screen_list->cv); | |||||
caca_set_color_ansi(screen_list->cv, CACA_WHITE, CACA_BLACK); | |||||
caca_clear_canvas(screen_list->cv); | |||||
for (i = 0; i < COUNT; i++) | |||||
{ | |||||
x = d->x[i] / PRECISION; | |||||
y = d->y[i] / PRECISION; | |||||
s = d->s[i] / PRECISION; | |||||
caca_blit(screen_list->cv, x, y, d->toaster[s], d->mask[s]); | |||||
d->x[i] -= 40; | |||||
d->y[i] += 10; | |||||
if (d->x[i] / PRECISION + caca_get_canvas_width(d->toaster[s]) <= 0) | |||||
d->x[i] = ((rand() % w) / 3 + w) * PRECISION; | |||||
if (d->y[i] / PRECISION >= h) | |||||
d->y[i] = ((rand() % h) / 2 - h) * PRECISION; | |||||
d->s[i] = ((d->s[i] + 24) % (3 * PRECISION)); | |||||
} | |||||
} | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #if !defined _WIN32 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <signal.h> #include <sys/wait.h> #include <errno.h> #include <unistd.h> #include <caca.h> #include "neercs.h" void screensaver_init(struct screen_list *screen_list) { screensaver_flying_toasters_init(screen_list); } void screensaver_kill(struct screen_list *screen_list) { screensaver_flying_toasters_kill(screen_list); } void draw_screensaver(struct screen_list *screen_list) { screensaver_flying_toasters(screen_list); } /* Flying Toasters */ #define COUNT 15 #define PRECISION 100 char toaster_text[3][99] = { { " __._ \n" " .-'== _',\n" " <|_= .-' |\n" " | --| \\'.-_ \n" " | | \\ \" _.\n" " `-_|.-\\_.-\n"}, { " __._ \n" " .-'== _',\n" " \\|_= .-' |\n" " | --| __'-.\n" " | | ___.-\n" " `-_|.-\n"}, { " _- __._\n" " /.-'== _',_.-.\n" " \\|_= .-'/ _.'\n" " | --| / .-\n" " | | _.|\n" " `-_|.-\n"} }; char toaster_mask[3][99] = { { " __._ \n" " .-'== _',\n" " <|_=X.-'XX|\n" " |X--|XXX\\'.-_ \n" " |XXX|X\\XX\"X_.\n" " `-_|.-\\_.-\n"}, { " __._ \n" " .-'== _',\n" " \\|_= .-'XX|\n" " |X--|XX__'-.\n" " |XXX|X___.-\n" " `-_|.-\n"}, { " _- __._\n" " /.-'== _',_.-.\n" " \\|_= .-'/XX_.'\n" " |X--|X/X.-\n" " |XXX|XX_.|\n" " `-_|.-\n"} }; struct flying_toaster { int x[COUNT], y[COUNT], s[COUNT]; caca_canvas_t **toaster; caca_canvas_t **mask; }; void screensaver_flying_toasters_init(struct screen_list *screen_list) { struct flying_toaster *flying_toaster; int w = caca_get_canvas_width(screen_list->cv); int h = caca_get_canvas_height(screen_list->cv); int i; flying_toaster = malloc(sizeof(struct flying_toaster)); flying_toaster->toaster = (caca_canvas_t **) malloc(sizeof(caca_canvas_t *) * 3); flying_toaster->mask = (caca_canvas_t **) malloc(sizeof(caca_canvas_t *) * 3); for (i = 0; i < 3; i++) { flying_toaster->toaster[i] = caca_create_canvas(0, 0); flying_toaster->mask[i] = caca_create_canvas(0, 0); caca_import_canvas_from_memory(flying_toaster->toaster[i], toaster_text[i], strlen(toaster_text[i]), "utf8"); caca_import_canvas_from_memory(flying_toaster->mask[i], toaster_mask[i], strlen(toaster_mask[i]), "utf8"); } for (i = 0; i < COUNT; i++) { flying_toaster->x[i] = (rand() % w) * PRECISION; flying_toaster->y[i] = (rand() % h) * PRECISION; flying_toaster->s[i] = (rand() % 3) * PRECISION; } screen_list->screensaver.data = flying_toaster; } void screensaver_flying_toasters_kill(struct screen_list *screen_list) { struct flying_toaster *flying_toaster = screen_list->screensaver.data; caca_free_canvas(flying_toaster->toaster[0]); caca_free_canvas(flying_toaster->toaster[1]); caca_free_canvas(flying_toaster->toaster[2]); free(flying_toaster->toaster); free(flying_toaster); screen_list->screensaver.data = NULL; } void screensaver_flying_toasters(struct screen_list *screen_list) { struct flying_toaster *d = screen_list->screensaver.data; int i, w, h, x, y, s; if (!d) return; w = caca_get_canvas_width(screen_list->cv); h = caca_get_canvas_height(screen_list->cv); caca_set_color_ansi(screen_list->cv, CACA_WHITE, CACA_BLACK); caca_clear_canvas(screen_list->cv); for (i = 0; i < COUNT; i++) { x = d->x[i] / PRECISION; y = d->y[i] / PRECISION; s = d->s[i] / PRECISION; caca_blit(screen_list->cv, x, y, d->toaster[s], d->mask[s]); d->x[i] -= 40; d->y[i] += 10; if (d->x[i] / PRECISION + caca_get_canvas_width(d->toaster[s]) <= 0) d->x[i] = ((rand() % w) / 3 + w) * PRECISION; if (d->y[i] / PRECISION >= h) d->y[i] = ((rand() % h) / 2 - h) * PRECISION; d->s[i] = ((d->s[i] + 24) % (3 * PRECISION)); } } #endif |
@@ -1,143 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#if !defined _WIN32 | |||||
#define _XOPEN_SOURCE | |||||
#include <stdlib.h> | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include <sys/ioctl.h> | |||||
#include <sys/types.h> | |||||
#include <termios.h> | |||||
#if defined HAVE_PTY_H | |||||
# include <pty.h> /* for openpty and forkpty */ | |||||
#elif defined HAVE_UTIL_H | |||||
# include <util.h> /* for OS X, OpenBSD and NetBSD */ | |||||
#elif defined HAVE_LIBUTIL_H | |||||
# include <libutil.h> /* for FreeBSD */ | |||||
#endif | |||||
#include <unistd.h> | |||||
#include <fcntl.h> | |||||
#include <caca.h> | |||||
#include "neercs.h" | |||||
int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid) | |||||
{ | |||||
char **argv; | |||||
int fd; | |||||
pid_t pid; | |||||
pid = forkpty(&fd, NULL, NULL, NULL); | |||||
if (pid < 0) | |||||
{ | |||||
fprintf(stderr, "forkpty() error\n"); | |||||
return -1; | |||||
} | |||||
else if (pid == 0) | |||||
{ | |||||
set_tty_size(0, w, h); | |||||
putenv("CACA_DRIVER=slang"); | |||||
putenv("TERM=xterm"); | |||||
argv = malloc(2 * sizeof(char *)); | |||||
if (!argv) | |||||
{ | |||||
fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, | |||||
__LINE__); | |||||
return -1; | |||||
} | |||||
argv[0] = cmd; | |||||
argv[1] = NULL; | |||||
execvp(cmd, argv); | |||||
fprintf(stderr, "execvp() error\n"); | |||||
return -1; | |||||
} | |||||
*cpid = pid; | |||||
fcntl(fd, F_SETFL, O_NDELAY); | |||||
return fd; | |||||
} | |||||
int create_pty_grab(long pid, unsigned int w, unsigned int h, int *newpid) | |||||
{ | |||||
int fdm, fds; | |||||
int ret = openpty(&fdm, &fds, NULL, NULL, NULL); | |||||
if (ret < 0) | |||||
{ | |||||
fprintf(stderr, "open() error\n"); | |||||
return -1; | |||||
} | |||||
set_tty_size(0, w, h); | |||||
grab_process(pid, ptsname(fdm), fds, newpid); | |||||
fcntl(fdm, F_SETFL, O_NDELAY); | |||||
return fdm; | |||||
} | |||||
int set_tty_size(int fd, unsigned int w, unsigned int h) | |||||
{ | |||||
struct winsize ws; | |||||
memset(&ws, 0, sizeof(ws)); | |||||
ws.ws_row = h; | |||||
ws.ws_col = w; | |||||
ioctl(fd, TIOCSWINSZ, (char *)&ws); | |||||
return 0; | |||||
} | |||||
int update_terms(struct screen_list *screen_list) | |||||
{ | |||||
int i, refresh = 0; | |||||
for (i = 0; i < screen_list->count; i++) | |||||
{ | |||||
if (screen_list->screen[i]->total && !screen_list->dont_update_coords) | |||||
{ | |||||
unsigned long int bytes; | |||||
bytes = import_term(screen_list, | |||||
screen_list->screen[i], | |||||
screen_list->screen[i]->buf, | |||||
screen_list->screen[i]->total); | |||||
if (bytes > 0) | |||||
{ | |||||
screen_list->screen[i]->total -= bytes; | |||||
memmove(screen_list->screen[i]->buf, | |||||
screen_list->screen[i]->buf + bytes, | |||||
screen_list->screen[i]->total); | |||||
if (screen_list->screen[i]->visible || screen_list->modals.mini) | |||||
refresh = 1; | |||||
} | |||||
} | |||||
} | |||||
return refresh; | |||||
} | |||||
#else | |||||
/* FIXME: unimplemented */ | |||||
int set_tty_size(int fd, unsigned int w, unsigned int h) { return 0; } | |||||
#endif | |||||
/* * neercs console-based window manager * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #if defined HAVE_CONFIG_H # include "config.h" #endif #if !defined _WIN32 #define _XOPEN_SOURCE #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/ioctl.h> #include <sys/types.h> #include <termios.h> #if defined HAVE_PTY_H # include <pty.h> /* for openpty and forkpty */ #elif defined HAVE_UTIL_H # include <util.h> /* for OS X, OpenBSD and NetBSD */ #elif defined HAVE_LIBUTIL_H # include <libutil.h> /* for FreeBSD */ #endif #include <unistd.h> #include <fcntl.h> #include <caca.h> #include "neercs.h" int create_pty(char *cmd, unsigned int w, unsigned int h, int *cpid) { char **argv; int fd; pid_t pid; pid = forkpty(&fd, NULL, NULL, NULL); if (pid < 0) { fprintf(stderr, "forkpty() error\n"); return -1; } else if (pid == 0) { set_tty_size(0, w, h); putenv("CACA_DRIVER=slang"); putenv("TERM=xterm"); argv = malloc(2 * sizeof(char *)); if (!argv) { fprintf(stderr, "Can't allocate memory at %s:%d\n", __FUNCTION__, __LINE__); return -1; } argv[0] = cmd; argv[1] = NULL; execvp(cmd, argv); fprintf(stderr, "execvp() error\n"); return -1; } *cpid = pid; fcntl(fd, F_SETFL, O_NDELAY); return fd; } int create_pty_grab(long pid, unsigned int w, unsigned int h, int *newpid) { int fdm, fds; int ret = openpty(&fdm, &fds, NULL, NULL, NULL); if (ret < 0) { fprintf(stderr, "open() error\n"); return -1; } set_tty_size(0, w, h); grab_process(pid, ptsname(fdm), fds, newpid); fcntl(fdm, F_SETFL, O_NDELAY); return fdm; } int set_tty_size(int fd, unsigned int w, unsigned int h) { struct winsize ws; memset(&ws, 0, sizeof(ws)); ws.ws_row = h; ws.ws_col = w; ioctl(fd, TIOCSWINSZ, (char *)&ws); return 0; } int update_terms(struct screen_list *screen_list) { int i, refresh = 0; for (i = 0; i < screen_list->count; i++) { if (screen_list->screen[i]->total && !screen_list->dont_update_coords) { unsigned long int bytes; bytes = import_term(screen_list, screen_list->screen[i], screen_list->screen[i]->buf, screen_list->screen[i]->total); if (bytes > 0) { screen_list->screen[i]->total -= bytes; memmove(screen_list->screen[i]->buf, screen_list->screen[i]->buf + bytes, screen_list->screen[i]->total); if (screen_list->screen[i]->visible || screen_list->modals.mini) refresh = 1; } } } return refresh; } #else /* FIXME: unimplemented */ int set_tty_size(int fd, unsigned int w, unsigned int h) { return 0; } #endif |
@@ -1,176 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#include "widgets.h" | |||||
static void widget_ibox_add_char(struct input_box *box, unsigned int c); | |||||
static void widget_ibox_del_char(struct input_box *box); | |||||
struct input_box *widget_ibox_init(caca_canvas_t *cv, int w, int h) | |||||
{ | |||||
struct input_box *box = (struct input_box *)malloc(sizeof(struct input_box)); | |||||
if (!box) | |||||
return NULL; | |||||
box->cv = cv; | |||||
box->w = w; | |||||
box->h = h; | |||||
box->command = NULL; | |||||
box->output_err = NULL; | |||||
box->output_res = NULL; | |||||
return box; | |||||
} | |||||
int widget_ibox_draw(struct input_box *box) | |||||
{ | |||||
int x = (caca_get_canvas_width(box->cv) - box->w) / 2; | |||||
int y = (caca_get_canvas_height(box->cv) - box->h) / 2; | |||||
caca_set_color_ansi(box->cv, CACA_BLUE, CACA_BLUE); | |||||
caca_fill_box(box->cv, x, y, box->w, box->h, '#'); | |||||
caca_set_color_ansi(box->cv, CACA_DEFAULT, CACA_BLUE); | |||||
caca_draw_cp437_box(box->cv, x, y, box->w, box->h); | |||||
caca_printf(box->cv, x, y, "Mini-command"); | |||||
caca_printf(box->cv, x + 2, y + 2, | |||||
"[___________________________________________________________]"); | |||||
if (box->command) | |||||
{ | |||||
caca_printf(box->cv, x + 3, y + 2, "%s", box->command); | |||||
caca_gotoxy(box->cv, x + 3 + box->x, y + 2); | |||||
} | |||||
else | |||||
{ | |||||
caca_gotoxy(box->cv, x + 3, y + 2); | |||||
} | |||||
if (box->output_err) | |||||
{ | |||||
caca_set_color_ansi(box->cv, CACA_RED, CACA_BLUE); | |||||
caca_printf(box->cv, x + 2, y + 4, box->output_err); | |||||
} | |||||
if (box->output_res) | |||||
{ | |||||
caca_set_color_ansi(box->cv, CACA_LIGHTGREEN, CACA_BLUE); | |||||
caca_printf(box->cv, x + 2, y + 4, box->output_res); | |||||
} | |||||
return 0; | |||||
} | |||||
char *widget_ibox_get_text(struct input_box *box) | |||||
{ | |||||
return box->command; | |||||
} | |||||
void widget_ibox_destroy(struct input_box *box) | |||||
{ | |||||
if(!box) return; | |||||
if (box->command) | |||||
free(box->command); | |||||
if (box->output_err) | |||||
free(box->output_err); | |||||
if (box->output_res) | |||||
free(box->output_res); | |||||
} | |||||
void widget_ibox_set_error(struct input_box *box, char *err) | |||||
{ | |||||
box->output_err = err; | |||||
} | |||||
void widget_ibox_set_msg(struct input_box *box, char *msg) | |||||
{ | |||||
box->output_res = msg; | |||||
} | |||||
int widget_ibox_handle_key(struct input_box *box, unsigned int c) | |||||
{ | |||||
if (c == CACA_KEY_ESCAPE) | |||||
{ | |||||
if (box->command) | |||||
{ | |||||
free(box->command); | |||||
box->command = NULL; | |||||
} | |||||
return INPUT_BOX_ESC; | |||||
} | |||||
else if (c == CACA_KEY_LEFT) | |||||
{ | |||||
if (box->x) | |||||
box->x--; | |||||
} | |||||
else if (c == CACA_KEY_RIGHT) | |||||
{ | |||||
if (box->x < box->size - 1) | |||||
box->x++; | |||||
} | |||||
else if (c == CACA_KEY_RETURN) | |||||
{ | |||||
return INPUT_BOX_RET; | |||||
} | |||||
else | |||||
{ | |||||
if (c >= ' ' && c < 127) | |||||
widget_ibox_add_char(box, c); | |||||
else if (c == 8) | |||||
{ | |||||
widget_ibox_del_char(box); | |||||
} | |||||
} | |||||
return INPUT_BOX_NOTHING; | |||||
} | |||||
static void widget_ibox_add_char(struct input_box *box, unsigned int c) | |||||
{ | |||||
/* FIXME handle return values */ | |||||
if (!box->command) | |||||
{ | |||||
box->size = 1; | |||||
box->x = 0; | |||||
box->command = (char *)malloc(2); | |||||
box->command[0] = 0; | |||||
} | |||||
else | |||||
{ | |||||
box->command = (char *)realloc(box->command, box->size + 1); | |||||
} | |||||
memmove(&box->command[box->x + 1], | |||||
&box->command[box->x], (box->size - box->x)); | |||||
box->command[box->x] = c; | |||||
box->x++; | |||||
box->size++; | |||||
} | |||||
static void widget_ibox_del_char(struct input_box *box) | |||||
{ | |||||
if (box->x < 1) | |||||
return; | |||||
if (box->size > 1) | |||||
box->size--; | |||||
else | |||||
return; | |||||
memcpy(&box->command[box->x - 1], &box->command[box->x], box->size - box->x); | |||||
box->command = (char *)realloc(box->command, box->size); | |||||
if (box->x) | |||||
box->x--; | |||||
box->command[box->size - 1] = 0; | |||||
} | |||||
/* * neercs console-based window manager * Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #include "widgets.h" static void widget_ibox_add_char(struct input_box *box, unsigned int c); static void widget_ibox_del_char(struct input_box *box); struct input_box *widget_ibox_init(caca_canvas_t *cv, int w, int h) { struct input_box *box = (struct input_box *)malloc(sizeof(struct input_box)); if (!box) return NULL; box->cv = cv; box->w = w; box->h = h; box->command = NULL; box->output_err = NULL; box->output_res = NULL; return box; } int widget_ibox_draw(struct input_box *box) { int x = (caca_get_canvas_width(box->cv) - box->w) / 2; int y = (caca_get_canvas_height(box->cv) - box->h) / 2; caca_set_color_ansi(box->cv, CACA_BLUE, CACA_BLUE); caca_fill_box(box->cv, x, y, box->w, box->h, '#'); caca_set_color_ansi(box->cv, CACA_DEFAULT, CACA_BLUE); caca_draw_cp437_box(box->cv, x, y, box->w, box->h); caca_printf(box->cv, x, y, "Mini-command"); caca_printf(box->cv, x + 2, y + 2, "[___________________________________________________________]"); if (box->command) { caca_printf(box->cv, x + 3, y + 2, "%s", box->command); caca_gotoxy(box->cv, x + 3 + box->x, y + 2); } else { caca_gotoxy(box->cv, x + 3, y + 2); } if (box->output_err) { caca_set_color_ansi(box->cv, CACA_RED, CACA_BLUE); caca_printf(box->cv, x + 2, y + 4, box->output_err); } if (box->output_res) { caca_set_color_ansi(box->cv, CACA_LIGHTGREEN, CACA_BLUE); caca_printf(box->cv, x + 2, y + 4, box->output_res); } return 0; } char *widget_ibox_get_text(struct input_box *box) { return box->command; } void widget_ibox_destroy(struct input_box *box) { if(!box) return; if (box->command) free(box->command); if (box->output_err) free(box->output_err); if (box->output_res) free(box->output_res); } void widget_ibox_set_error(struct input_box *box, char *err) { box->output_err = err; } void widget_ibox_set_msg(struct input_box *box, char *msg) { box->output_res = msg; } int widget_ibox_handle_key(struct input_box *box, unsigned int c) { if (c == CACA_KEY_ESCAPE) { if (box->command) { free(box->command); box->command = NULL; } return INPUT_BOX_ESC; } else if (c == CACA_KEY_LEFT) { if (box->x) box->x--; } else if (c == CACA_KEY_RIGHT) { if (box->x < box->size - 1) box->x++; } else if (c == CACA_KEY_RETURN) { return INPUT_BOX_RET; } else { if (c >= ' ' && c < 127) widget_ibox_add_char(box, c); else if (c == 8) { widget_ibox_del_char(box); } } return INPUT_BOX_NOTHING; } static void widget_ibox_add_char(struct input_box *box, unsigned int c) { /* FIXME handle return values */ if (!box->command) { box->size = 1; box->x = 0; box->command = (char *)malloc(2); box->command[0] = 0; } else { box->command = (char *)realloc(box->command, box->size + 1); } memmove(&box->command[box->x + 1], &box->command[box->x], (box->size - box->x)); box->command[box->x] = c; box->x++; box->size++; } static void widget_ibox_del_char(struct input_box *box) { if (box->x < 1) return; if (box->size > 1) box->size--; else return; memcpy(&box->command[box->x - 1], &box->command[box->x], box->size - box->x); box->command = (char *)realloc(box->command, box->size); if (box->x) box->x--; box->command[box->size - 1] = 0; } |
@@ -1,45 +1 @@ | |||||
/* | |||||
* neercs console-based window manager | |||||
* Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||||
* All Rights Reserved | |||||
* | |||||
* This program is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://www.wtfpl.net/ for more details. | |||||
*/ | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include <stdlib.h> | |||||
#include <sys/types.h> | |||||
#include <caca.h> | |||||
enum input_box_code | |||||
{ | |||||
INPUT_BOX_ESC, | |||||
INPUT_BOX_RET, | |||||
INPUT_BOX_NOTHING, | |||||
}; | |||||
struct input_box | |||||
{ | |||||
caca_canvas_t *cv; | |||||
int x, y; | |||||
int w, h; | |||||
int size; | |||||
char *command; | |||||
char *output_err; | |||||
char *output_res; | |||||
}; | |||||
struct input_box *widget_ibox_init(caca_canvas_t * cv, int w, int h); | |||||
int widget_ibox_draw(struct input_box *box); | |||||
int widget_ibox_handle_key(struct input_box *box, unsigned int c); | |||||
char* widget_ibox_get_text(struct input_box *box); | |||||
void widget_ibox_destroy(struct input_box *box); | |||||
void widget_ibox_set_error(struct input_box *box, char *err); | |||||
void widget_ibox_set_msg(struct input_box *box, char *msg); | |||||
/* * neercs console-based window manager * Copyright (c) 2009-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> * All Rights Reserved * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://www.wtfpl.net/ for more details. */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <caca.h> enum input_box_code { INPUT_BOX_ESC, INPUT_BOX_RET, INPUT_BOX_NOTHING, }; struct input_box { caca_canvas_t *cv; int x, y; int w, h; int size; char *command; char *output_err; char *output_res; }; struct input_box *widget_ibox_init(caca_canvas_t * cv, int w, int h); int widget_ibox_draw(struct input_box *box); int widget_ibox_handle_key(struct input_box *box, unsigned int c); char* widget_ibox_get_text(struct input_box *box); void widget_ibox_destroy(struct input_box *box); void widget_ibox_set_error(struct input_box *box, char *err); void widget_ibox_set_msg(struct input_box *box, char *msg); |
@@ -1,34 +1 @@ | |||||
// | |||||
// Neercs | |||||
// | |||||
#if !defined __TERM_PTY_H__ | |||||
#define __TERM_PTY_H__ | |||||
class Pty | |||||
{ | |||||
public: | |||||
Pty(); | |||||
~Pty(); | |||||
void Run(char const *command, ivec2 size); | |||||
bool IsEof() const; | |||||
size_t ReadData(char *data, size_t maxlen); | |||||
void UnreadData(char *data, size_t len); | |||||
size_t WriteData(char const *data, size_t len); | |||||
void SetWindowSize(ivec2 size, int64_t fd = -1); | |||||
private: | |||||
int64_t m_fd; | |||||
int64_t m_pid; | |||||
bool m_eof; | |||||
char const *m_argv[2]; | |||||
char *m_unread_data; | |||||
size_t m_unread_len; | |||||
ivec2 m_size; | |||||
}; | |||||
#endif // __TERM_PTY_H__ | |||||
// // Neercs // #if !defined __TERM_PTY_H__ #define __TERM_PTY_H__ class Pty { public: Pty(); ~Pty(); void Run(char const *command, ivec2 size); bool IsEof() const; size_t ReadData(char *data, size_t maxlen); void UnreadData(char *data, size_t len); size_t WriteData(char const *data, size_t len); void SetWindowSize(ivec2 size, int64_t fd = -1); private: int64_t m_fd; int64_t m_pid; bool m_eof; char const *m_argv[2]; char *m_unread_data; size_t m_unread_len; ivec2 m_size; }; #endif // __TERM_PTY_H__ |
@@ -1,133 +1 @@ | |||||
// | |||||
// Neercs | |||||
// | |||||
#if !defined __TERM_TERM_H__ | |||||
#define __TERM_TERM_H__ | |||||
#include "term/pty.h" | |||||
struct Iso2022Conversion | |||||
{ | |||||
Iso2022Conversion() { Reset(); } | |||||
void Reset(); | |||||
/* cs = coding system/coding method: */ | |||||
/* (with standard return) */ | |||||
/* '@' = ISO-2022, */ | |||||
/* 'G' = UTF-8 without implementation level, */ | |||||
/* '8' = UTF-8 (Linux console and imitators), */ | |||||
/* and many others that are rarely used; */ | |||||
/* (without standard return) */ | |||||
/* '/G' = UTF-8 Level 1, */ | |||||
/* '/H' = UTF-8 Level 2, */ | |||||
/* '/I' = UTF-8 Level 3, */ | |||||
/* and many others that are rarely used */ | |||||
uint32_t cs; | |||||
/* ctrl8bit = allow 8-bit controls */ | |||||
uint8_t ctrl8bit; | |||||
/* cn[0] = C0 control charset (0x00 ... 0x1f): | |||||
* '@' = ISO 646, | |||||
* '~' = empty, | |||||
* and many others that are rarely used */ | |||||
/* cn[1] = C1 control charset (0x80 ... 0x9f): | |||||
* 'C' = ISO 6429-1983, | |||||
* '~' = empty, | |||||
* and many others that are rarely used */ | |||||
uint32_t cn[2]; | |||||
/* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e, | |||||
* 94x94-char. 0x21/0x21 ... 0x7e/0x7e), | |||||
* and | |||||
* glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe, | |||||
* 96-char. 0xa0 ... 0xff, | |||||
* 94x94-char. 0xa1/0xa1 ... 0xfe/0xfe, | |||||
* 96x96-char. 0xa0/0xa0 ... 0xff/0xff): | |||||
* 0 = G0, 1 = G1, 2 = G2, 3 = G3 */ | |||||
uint8_t glr[2]; | |||||
/* gn[i] = G0/G1/G2/G3 graphic charset state: | |||||
* (94-char. sets) | |||||
* '0' = DEC ACS (VT100 and imitators), | |||||
* 'B' = US-ASCII, | |||||
* and many others that are rarely used for e.g. various national ASCII variations; | |||||
* (96-char. sets) | |||||
* '.A' = ISO 8859-1 "Latin 1" GR, | |||||
* '.~' = empty 96-char. set, | |||||
* and many others that are rarely used for e.g. ISO 8859-n GR; | |||||
* (double-byte 94x94-charsets) | |||||
* '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978), | |||||
* '$A' = Chinese Character Set (GB 2312), | |||||
* '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983), | |||||
* '$C' = Korean Graphic Character Set (KSC 5601:1987), | |||||
* '$D' = Supplementary Japanese Graphic Character Set (JIS X0212), | |||||
* '$E' = CCITT Chinese Set (GB 2312 + GB 8565), | |||||
* '$G' = CNS 11643 plane 1, | |||||
* '$H' = CNS 11643 plane 2, | |||||
* '$I' = CNS 11643 plane 3, | |||||
* '$J' = CNS 11643 plane 4, | |||||
* '$K' = CNS 11643 plane 5, | |||||
* '$L' = CNS 11643 plane 6, | |||||
* '$M' = CNS 11643 plane 7, | |||||
* '$O' = JIS X 0213 plane 1, | |||||
* '$P' = JIS X 0213 plane 2, | |||||
* '$Q' = JIS X 0213-2004 Plane 1, | |||||
* and many others that are rarely used for e.g. traditional | |||||
* ideographic Vietnamese and BlissSymbolics; | |||||
* (double-byte 96x96-charsets) | |||||
* none standardized or in use on terminals AFAIK (Mule does use | |||||
* some internally) | |||||
*/ | |||||
uint32_t gn[4]; | |||||
/* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */ | |||||
uint8_t ss; | |||||
}; | |||||
class Term : public Entity | |||||
{ | |||||
public: | |||||
Term(ivec2 size); | |||||
~Term(); | |||||
char const *GetName() { return "<term>"; } | |||||
caca_canvas_t *GetCaca() { return m_caca; } | |||||
protected: | |||||
virtual void TickGame(float seconds); | |||||
virtual void TickDraw(float seconds); | |||||
private: | |||||
/* Terminal emulation main entry point */ | |||||
size_t ReadAnsi(void const *data, size_t size); | |||||
size_t SendAnsi(char const *str); | |||||
/* Utility functions for terminal emulation */ | |||||
void ReadGrcm(unsigned int argc, unsigned int const *argv); | |||||
inline int ReadChar(unsigned char c, int *x, int *y); | |||||
inline int ReadDuplet(unsigned char const *buffer, unsigned int *skip, | |||||
int top, int bottom, int width, int height); | |||||
private: | |||||
Pty *m_pty; | |||||
caca_canvas_t *m_caca; | |||||
ivec2 m_size; | |||||
/* Terminal attributes */ | |||||
char *m_title; | |||||
int m_bell, m_init, m_report_mouse; | |||||
int m_changed; /* content was updated */ | |||||
Iso2022Conversion m_conv_state; /* charset mess */ | |||||
uint8_t m_fg, m_bg; /* ANSI-context fg/bg */ | |||||
uint8_t m_dfg, m_dbg; /* Default fg/bg */ | |||||
uint8_t m_bold, m_blink, m_italics, m_negative, m_concealed, m_underline; | |||||
uint8_t m_faint, m_strike, m_proportional; /* unsupported */ | |||||
uint32_t m_clearattr; | |||||
/* Mostly for fancy shit */ | |||||
void DrawFancyShit(); | |||||
float m_time; | |||||
bool m_debug; | |||||
}; | |||||
#endif // __TERM_TERM_H__ | |||||
// // Neercs // #if !defined __TERM_TERM_H__ #define __TERM_TERM_H__ #include "term/pty.h" struct Iso2022Conversion { Iso2022Conversion() { Reset(); } void Reset(); /* cs = coding system/coding method: */ /* (with standard return) */ /* '@' = ISO-2022, */ /* 'G' = UTF-8 without implementation level, */ /* '8' = UTF-8 (Linux console and imitators), */ /* and many others that are rarely used; */ /* (without standard return) */ /* '/G' = UTF-8 Level 1, */ /* '/H' = UTF-8 Level 2, */ /* '/I' = UTF-8 Level 3, */ /* and many others that are rarely used */ uint32_t cs; /* ctrl8bit = allow 8-bit controls */ uint8_t ctrl8bit; /* cn[0] = C0 control charset (0x00 ... 0x1f): * '@' = ISO 646, * '~' = empty, * and many others that are rarely used */ /* cn[1] = C1 control charset (0x80 ... 0x9f): * 'C' = ISO 6429-1983, * '~' = empty, * and many others that are rarely used */ uint32_t cn[2]; /* glr[0] = GL graphic charset (94-char. 0x21 ... 0x7e, * 94x94-char. 0x21/0x21 ... 0x7e/0x7e), * and * glr[1] = GR graphic charset (94-char. 0xa1 ... 0xfe, * 96-char. 0xa0 ... 0xff, * 94x94-char. 0xa1/0xa1 ... 0xfe/0xfe, * 96x96-char. 0xa0/0xa0 ... 0xff/0xff): * 0 = G0, 1 = G1, 2 = G2, 3 = G3 */ uint8_t glr[2]; /* gn[i] = G0/G1/G2/G3 graphic charset state: * (94-char. sets) * '0' = DEC ACS (VT100 and imitators), * 'B' = US-ASCII, * and many others that are rarely used for e.g. various national ASCII variations; * (96-char. sets) * '.A' = ISO 8859-1 "Latin 1" GR, * '.~' = empty 96-char. set, * and many others that are rarely used for e.g. ISO 8859-n GR; * (double-byte 94x94-charsets) * '$@' = Japanese Character Set ("old JIS") (JIS C 6226:1978), * '$A' = Chinese Character Set (GB 2312), * '$B' = Japanese Character Set (JIS X0208/JIS C 6226:1983), * '$C' = Korean Graphic Character Set (KSC 5601:1987), * '$D' = Supplementary Japanese Graphic Character Set (JIS X0212), * '$E' = CCITT Chinese Set (GB 2312 + GB 8565), * '$G' = CNS 11643 plane 1, * '$H' = CNS 11643 plane 2, * '$I' = CNS 11643 plane 3, * '$J' = CNS 11643 plane 4, * '$K' = CNS 11643 plane 5, * '$L' = CNS 11643 plane 6, * '$M' = CNS 11643 plane 7, * '$O' = JIS X 0213 plane 1, * '$P' = JIS X 0213 plane 2, * '$Q' = JIS X 0213-2004 Plane 1, * and many others that are rarely used for e.g. traditional * ideographic Vietnamese and BlissSymbolics; * (double-byte 96x96-charsets) * none standardized or in use on terminals AFAIK (Mule does use * some internally) */ uint32_t gn[4]; /* ss = single-shift state: 0 = GL, 2 = G2, 3 = G3 */ uint8_t ss; }; class Term : public Entity { public: Term(ivec2 size); ~Term(); char const *GetName() { return "<term>"; } caca_canvas_t *GetCaca() { return m_caca; } protected: virtual void TickGame(float seconds); virtual void TickDraw(float seconds); private: /* Terminal emulation main entry point */ size_t ReadAnsi(void const *data, size_t size); size_t SendAnsi(char const *str); /* Utility functions for terminal emulation */ void ReadGrcm(unsigned int argc, unsigned int const *argv); inline int ReadChar(unsigned char c, int *x, int *y); inline int ReadDuplet(unsigned char const *buffer, unsigned int *skip, int top, int bottom, int width, int height); private: Pty *m_pty; caca_canvas_t *m_caca; ivec2 m_size; /* Terminal attributes */ char *m_title; int m_bell, m_init, m_report_mouse; int m_changed; /* content was updated */ Iso2022Conversion m_conv_state; /* charset mess */ uint8_t m_fg, m_bg; /* ANSI-context fg/bg */ uint8_t m_dfg, m_dbg; /* Default fg/bg */ uint8_t m_bold, m_blink, m_italics, m_negative, m_concealed, m_underline; uint8_t m_faint, m_strike, m_proportional; /* unsupported */ uint32_t m_clearattr; /* Mostly for fancy shit */ void DrawFancyShit(); float m_time; bool m_debug; }; #endif // __TERM_TERM_H__ |
@@ -1,38 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D texture; | |||||
uniform vec2 radius; | |||||
void main(void) | |||||
{ | |||||
vec4 total = vec4(0.0); | |||||
vec2 p = pass_TexCoord; | |||||
float mask = 2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0); | |||||
float b = radius.x+radius.y*mask; | |||||
total += texture2D(texture,vec2(p.x-b*4.0,p.y))*0.04; | |||||
total += texture2D(texture,vec2(p.x-b*3.0,p.y))*0.08; | |||||
total += texture2D(texture,vec2(p.x-b*2.0,p.y))*0.12; | |||||
total += texture2D(texture,vec2(p.x-b ,p.y))*0.16; | |||||
total += texture2D(texture,vec2(p.x ,p.y))*0.20; | |||||
total += texture2D(texture,vec2(p.x+b ,p.y))*0.16; | |||||
total += texture2D(texture,vec2(p.x+b*2.0,p.y))*0.12; | |||||
total += texture2D(texture,vec2(p.x+b*3.0,p.y))*0.08; | |||||
total += texture2D(texture,vec2(p.x+b*4.0,p.y))*0.04; | |||||
gl_FragColor = total; | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D texture; uniform vec2 radius; void main(void) { vec4 total = vec4(0.0); vec2 p = pass_TexCoord; float mask = 2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0); float b = radius.x+radius.y*mask; total += texture2D(texture,vec2(p.x-b*4.0,p.y))*0.04; total += texture2D(texture,vec2(p.x-b*3.0,p.y))*0.08; total += texture2D(texture,vec2(p.x-b*2.0,p.y))*0.12; total += texture2D(texture,vec2(p.x-b ,p.y))*0.16; total += texture2D(texture,vec2(p.x ,p.y))*0.20; total += texture2D(texture,vec2(p.x+b ,p.y))*0.16; total += texture2D(texture,vec2(p.x+b*2.0,p.y))*0.12; total += texture2D(texture,vec2(p.x+b*3.0,p.y))*0.08; total += texture2D(texture,vec2(p.x+b*4.0,p.y))*0.04; gl_FragColor = total; } |
@@ -1,39 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D texture; | |||||
uniform vec2 radius; | |||||
void main(void) | |||||
{ | |||||
vec4 total = vec4(0.0); | |||||
vec2 p = pass_TexCoord; | |||||
float mask = 2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0); | |||||
float b = radius.x+radius.y*mask; | |||||
total += texture2D(texture,vec2(p.x,p.y-b*4.0))*0.04; | |||||
total += texture2D(texture,vec2(p.x,p.y-b*3.0))*0.08; | |||||
total += texture2D(texture,vec2(p.x,p.y-b*2.0))*0.12; | |||||
total += texture2D(texture,vec2(p.x,p.y-b ))*0.16; | |||||
total += texture2D(texture,vec2(p.x,p.y ))*0.20; | |||||
total += texture2D(texture,vec2(p.x,p.y+b ))*0.16; | |||||
total += texture2D(texture,vec2(p.x,p.y+b*2.0))*0.12; | |||||
total += texture2D(texture,vec2(p.x,p.y+b*3.0))*0.08; | |||||
total += texture2D(texture,vec2(p.x,p.y+b*4.0))*0.04; | |||||
gl_FragColor = total; | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D texture; uniform vec2 radius; void main(void) { vec4 total = vec4(0.0); vec2 p = pass_TexCoord; float mask = 2.0-p.x*(6.0-p.x*6.0)*p.y*(6.0-p.y*6.0); float b = radius.x+radius.y*mask; total += texture2D(texture,vec2(p.x,p.y-b*4.0))*0.04; total += texture2D(texture,vec2(p.x,p.y-b*3.0))*0.08; total += texture2D(texture,vec2(p.x,p.y-b*2.0))*0.12; total += texture2D(texture,vec2(p.x,p.y-b ))*0.16; total += texture2D(texture,vec2(p.x,p.y ))*0.20; total += texture2D(texture,vec2(p.x,p.y+b ))*0.16; total += texture2D(texture,vec2(p.x,p.y+b*2.0))*0.12; total += texture2D(texture,vec2(p.x,p.y+b*3.0))*0.08; total += texture2D(texture,vec2(p.x,p.y+b*4.0))*0.04; gl_FragColor = total; } |
@@ -1,34 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
uniform sampler2D texture; | |||||
uniform vec2 screen_size; | |||||
uniform vec3 filter; | |||||
uniform vec4 color; | |||||
uniform float flash; | |||||
void main(void) | |||||
{ | |||||
vec2 p = gl_FragCoord.xy / screen_size.xy; | |||||
vec3 c = texture2D(texture,p).xyz; | |||||
float a = (c.x + c.y + c.z) / 3.0; | |||||
c = mix(c, vec3(a), color.w); // grayscale | |||||
c *= filter; // filter | |||||
c += color.z * 0.1; // level | |||||
c *= color.x; // brightness | |||||
c = 0.5 + (c - 0.5) * color.y; // contrast | |||||
c += flash; // flash | |||||
gl_FragColor = vec4(c, 1.0); | |||||
} | |||||
[vert.glsl] #version 120 void main() { gl_Position = gl_Vertex; } [frag.glsl] #version 120 uniform sampler2D texture; uniform vec2 screen_size; uniform vec3 filter; uniform vec4 color; uniform float flash; void main(void) { vec2 p = gl_FragCoord.xy / screen_size.xy; vec3 c = texture2D(texture,p).xyz; float a = (c.x + c.y + c.z) / 3.0; c = mix(c, vec3(a), color.w); // grayscale c *= filter; // filter c += color.z * 0.1; // level c *= color.x; // brightness c = 0.5 + (c - 0.5) * color.y; // contrast c += flash; // flash gl_FragColor = vec4(c, 1.0); } |
@@ -1,42 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D texture; | |||||
uniform vec2 screen_size; | |||||
uniform float time; | |||||
uniform vec4 copper; | |||||
uniform vec3 mask_color; | |||||
void main(void) | |||||
{ | |||||
vec2 p = pass_TexCoord; | |||||
vec3 source = texture2D(texture, p).xyz; | |||||
vec3 color = vec3(0.5); | |||||
color.x += 0.5 * cos(p.y*float(screen_size.y / copper.w) + time); | |||||
color.z += 0.5 * sin(p.y*float(screen_size.y / copper.w) + time); | |||||
color *= copper.x + copper.y * cos(p.y * float(screen_size.x / copper.z));// - time); | |||||
color.x = float(int(color.x * 8.0) * 32) / 256.0; | |||||
color.y = float(int(color.y * 8.0) * 32) / 256.0; | |||||
color.z = float(int(color.z * 8.0) * 32) / 256.0; | |||||
gl_FragColor = vec4((abs(source.x - mask_color.x) < 0.025 && abs(source.y - mask_color.y) < 0.025 && abs(source.z - mask_color.z) < 0.025) ? color : source, 1.0); | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D texture; uniform vec2 screen_size; uniform float time; uniform vec4 copper; uniform vec3 mask_color; void main(void) { vec2 p = pass_TexCoord; vec3 source = texture2D(texture, p).xyz; vec3 color = vec3(0.5); color.x += 0.5 * cos(p.y*float(screen_size.y / copper.w) + time); color.z += 0.5 * sin(p.y*float(screen_size.y / copper.w) + time); color *= copper.x + copper.y * cos(p.y * float(screen_size.x / copper.z));// - time); color.x = float(int(color.x * 8.0) * 32) / 256.0; color.y = float(int(color.y * 8.0) * 32) / 256.0; color.z = float(int(color.z * 8.0) * 32) / 256.0; gl_FragColor = vec4((abs(source.x - mask_color.x) < 0.025 && abs(source.y - mask_color.y) < 0.025 && abs(source.z - mask_color.z) < 0.025) ? color : source, 1.0); } |
@@ -1,28 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D glow; | |||||
uniform sampler2D source; | |||||
uniform vec2 mix; | |||||
void main(void) | |||||
{ | |||||
gl_FragColor = texture2D(source, pass_TexCoord) * mix.x | |||||
+ texture2D(glow, pass_TexCoord) * mix.y; | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D glow; uniform sampler2D source; uniform vec2 mix; void main(void) { gl_FragColor = texture2D(source, pass_TexCoord) * mix.x + texture2D(glow, pass_TexCoord) * mix.y; } |
@@ -1,35 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D texture; | |||||
uniform vec2 screen_size; | |||||
uniform vec4 mirror; | |||||
void main(void) | |||||
{ | |||||
vec2 p = pass_TexCoord; | |||||
vec3 s = texture2D(texture, p).xyz; | |||||
vec3 c = vec3(0.0); | |||||
if(p.x < mirror.x) c += texture2D(texture, vec2(mirror.x + (mirror.x - p.x) * mirror.w, p.y * (0.8 + 2.0 * p.x) + 0.1 - 1.0 * p.x)).xyz * (mirror.z / mirror.x * p.x); | |||||
if(p.x > 1.0 - mirror.x) c += texture2D(texture, vec2(- mirror.x - (mirror.x + p.x) * mirror.w, p.y * (0.8 + 2.0 * (1.0 - p.x)) + 0.1 - 1.0 * (1.0 - p.x))).xyz * (mirror.z / mirror.x * (1.0 - p.x)); | |||||
if(p.y < mirror.y) c += texture2D(texture, vec2(p.x * (0.8 + 2.0 * p.y) + 0.1 - 1.0 * p.y, mirror.y + (mirror.y - p.y) * mirror.w)).xyz * (mirror.z / mirror.y * p.y); | |||||
if(p.y > 1.0 - mirror.y) c += texture2D(texture, vec2(p.x * (0.8 + 2.0 * (1.0 - p.y)) + 0.1 - 1.0 * (1.0 - p.y), - mirror.y - (mirror.y + p.y) * mirror.w)).xyz * (mirror.z / mirror.y * (1.0 - p.y)); | |||||
gl_FragColor = vec4(s + c, 1.0); | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D texture; uniform vec2 screen_size; uniform vec4 mirror; void main(void) { vec2 p = pass_TexCoord; vec3 s = texture2D(texture, p).xyz; vec3 c = vec3(0.0); if(p.x < mirror.x) c += texture2D(texture, vec2(mirror.x + (mirror.x - p.x) * mirror.w, p.y * (0.8 + 2.0 * p.x) + 0.1 - 1.0 * p.x)).xyz * (mirror.z / mirror.x * p.x); if(p.x > 1.0 - mirror.x) c += texture2D(texture, vec2(- mirror.x - (mirror.x + p.x) * mirror.w, p.y * (0.8 + 2.0 * (1.0 - p.x)) + 0.1 - 1.0 * (1.0 - p.x))).xyz * (mirror.z / mirror.x * (1.0 - p.x)); if(p.y < mirror.y) c += texture2D(texture, vec2(p.x * (0.8 + 2.0 * p.y) + 0.1 - 1.0 * p.y, mirror.y + (mirror.y - p.y) * mirror.w)).xyz * (mirror.z / mirror.y * p.y); if(p.y > 1.0 - mirror.y) c += texture2D(texture, vec2(p.x * (0.8 + 2.0 * (1.0 - p.y)) + 0.1 - 1.0 * (1.0 - p.y), - mirror.y - (mirror.y + p.y) * mirror.w)).xyz * (mirror.z / mirror.y * (1.0 - p.y)); gl_FragColor = vec4(s + c, 1.0); } |
@@ -1,38 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
uniform sampler2D texture; | |||||
uniform vec2 screen_size; | |||||
uniform float time; | |||||
uniform vec2 offset; | |||||
uniform float noise; | |||||
uniform vec3 retrace; | |||||
float rand(in vec2 p, in float t, in float v) | |||||
{ | |||||
return fract(sin(dot(p + mod(t, 1.0), vec2(12.9898, 78.2333))) * v); | |||||
} | |||||
void main(void) | |||||
{ | |||||
vec2 p=gl_FragCoord.xy/screen_size.xy; | |||||
float r1=rand(p,time,43758.5453); | |||||
float r2=rand(p,time,70425.2854); | |||||
vec2 o=(offset-offset*2.0*r1)/screen_size; | |||||
vec3 c=texture2D(texture,p+o).xyz; // offset | |||||
c*=1.0+(noise-noise*2.0*r1); // noise | |||||
c-=retrace.x*0.01*mod(p.y*retrace.y+time*retrace.z,1.0); // retrace | |||||
gl_FragColor=vec4(c,1.0); | |||||
} | |||||
[vert.glsl] #version 120 void main() { gl_Position = gl_Vertex; } [frag.glsl] #version 120 uniform sampler2D texture; uniform vec2 screen_size; uniform float time; uniform vec2 offset; uniform float noise; uniform vec3 retrace; float rand(in vec2 p, in float t, in float v) { return fract(sin(dot(p + mod(t, 1.0), vec2(12.9898, 78.2333))) * v); } void main(void) { vec2 p=gl_FragCoord.xy/screen_size.xy; float r1=rand(p,time,43758.5453); float r2=rand(p,time,70425.2854); vec2 o=(offset-offset*2.0*r1)/screen_size; vec3 c=texture2D(texture,p+o).xyz; // offset c*=1.0+(noise-noise*2.0*r1); // noise c-=retrace.x*0.01*mod(p.y*retrace.y+time*retrace.z,1.0); // retrace gl_FragColor=vec4(c,1.0); } |
@@ -1,110 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
uniform sampler2D texture; | |||||
uniform vec2 screen_size; | |||||
uniform vec2 ratio_2d; | |||||
uniform float time; | |||||
uniform vec2 deform; | |||||
uniform vec4 ghost1; | |||||
uniform vec4 ghost2; | |||||
uniform vec4 glass; | |||||
uniform vec3 gradient; | |||||
uniform vec3 gradient_color; | |||||
uniform float vignetting; | |||||
uniform float aberration; | |||||
uniform vec4 moire_h; | |||||
uniform vec4 moire_v; | |||||
uniform vec4 scanline_h; | |||||
uniform vec4 scanline_v; | |||||
uniform vec3 corner; | |||||
uniform float sync; | |||||
uniform float beat; | |||||
const float PI=3.14159265358979323846; | |||||
vec2 angle=screen_size*PI; | |||||
vec2 screen(in vec2 p,in float bend,in float radius) | |||||
{ | |||||
float d=bend+sync*0.0625+beat*0.0375; | |||||
return p*(1.5-(radius*cos(p.x*d)+radius*cos(p.y*d)))-0.5; | |||||
} | |||||
vec3 get_color(in sampler2D tex,in vec2 p) | |||||
{ | |||||
return texture2D(tex,clamp(p,-1.0,0.0)).xyz; | |||||
} | |||||
float letterbox(in vec2 p,in float w,in float radius,in float smooth) | |||||
{ | |||||
return 1.0-smoothstep(smooth,1.0,length(max(abs(p*w+w/2.0)-vec2(radius),0.0))+radius); | |||||
} | |||||
void main(void) | |||||
{ | |||||
vec2 q=gl_FragCoord.xy/screen_size.xy; | |||||
vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy; | |||||
p.y+=0.025*sync; | |||||
vec2 z=screen(p,deform.x,deform.y); | |||||
vec2 z1=screen(p,deform.x,deform.y+ghost1.z); | |||||
vec2 z2=screen(p,deform.x,deform.y+ghost2.z); | |||||
vec2 z3=screen(p,glass.w,deform.y+glass.x-glass.y); | |||||
vec2 z4=screen(p,glass.w,deform.y+glass.x+glass.y); | |||||
float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); | |||||
vec3 source=get_color(texture,z); | |||||
vec3 g1=get_color(texture,z1-ghost1.xy); | |||||
vec3 g2=get_color(texture,z2-ghost2.xy); | |||||
vec3 g3=get_color(texture,z3); | |||||
vec3 g4=get_color(texture,z4); | |||||
vec3 c=source+g1*ghost1.w+g2*ghost2.w; // mix | |||||
float v=aberration/float(screen_size.x/ratio_2d.x); //+aberration/float(screen_size.x)*(2.0-mask); | |||||
vec3 ca1=get_color(texture,vec2(z.x-v,z.y)); | |||||
vec3 ca2=get_color(texture,vec2(z.x+v,z.y)); | |||||
c+=vec3(ca1.x,c.y,ca2.z); // chromatic aberration | |||||
vec3 c1=vec3(gradient_color.x,gradient_color.y,gradient_color.z); | |||||
vec3 c2=vec3(gradient_color.x,gradient_color.y,gradient_color.z)/4; | |||||
vec3 c3=vec3(1.0,1.0,1.0); | |||||
vec3 c4=vec3(gradient_color.z,gradient_color.y,gradient_color.x); | |||||
vec3 c5=vec3(gradient_color.z,gradient_color.y,gradient_color.x)/4; | |||||
vec3 r; | |||||
float r_p=gradient.x; | |||||
float r_h=gradient.y; | |||||
float r_h2=gradient.y/2; | |||||
float k=z.y+1.0; | |||||
if (k <= r_p - r_h2) | |||||
r = mix(c1,c2,k*(1/(r_p-r_h2))); | |||||
else if (k <= r_p) | |||||
r = mix(c2,c3,(k-(r_p-r_h2))*(1/r_h2)); | |||||
else if (k < r_p + r_h) | |||||
r = mix(c3,c4,(k-r_p)*(1/r_h)); | |||||
else | |||||
r = mix(c4,c5,k*((k-(r_p+r_h))/(r_p-r_h))); | |||||
//c*=moire_h.x+moire_h.y*sin(z.y*float(screen_size.y*moire_h.z)/ratio_2d.y)*sin(0.5+z.x*float(screen_size.x*moire_h.w)/ratio_2d.x); // moire h | |||||
//c*=moire_v.x+moire_v.y*sin(z.x*float(screen_size.x*moire_v.z)/ratio_2d.x)*sin(0.5+z.y*float(screen_size.y*moire_v.w)/ratio_2d.y); // moire v | |||||
c*=moire_h.x+moire_h.y*sin(z.y*float(angle.y*moire_h.z)/ratio_2d.y)*sin(PI+z.x*float(screen_size.x*moire_h.w)/ratio_2d.x); // moire h | |||||
c*=moire_v.x+moire_v.y*sin(z.x*float(angle.x*moire_v.z)/ratio_2d.x)*sin(PI+z.y*float(screen_size.y*moire_v.w)/ratio_2d.y); // moire v | |||||
c*=scanline_h.x+scanline_h.y*cos(z.y*float(angle.y*scanline_h.z+scanline_h.w)/ratio_2d.y); // scanline h | |||||
c*=scanline_v.x+scanline_v.y*cos(z.x*float(angle.x*scanline_v.z+scanline_v.w)/ratio_2d.x); // scanline v | |||||
c+=r*gradient.z; // gradient | |||||
c*=mix(1.0,mask,vignetting); // vignetting | |||||
c*=letterbox(z,corner.x+2.0,corner.y,corner.z); // corner | |||||
c+=(g3+g4)*glass.z; // glass | |||||
gl_FragColor=vec4(c,1.0); | |||||
} | |||||
[vert.glsl] #version 120 void main() { gl_Position = gl_Vertex; } [frag.glsl] #version 120 uniform sampler2D texture; uniform vec2 screen_size; uniform vec2 ratio_2d; uniform float time; uniform vec2 deform; uniform vec4 ghost1; uniform vec4 ghost2; uniform vec4 glass; uniform vec3 gradient; uniform vec3 gradient_color; uniform float vignetting; uniform float aberration; uniform vec4 moire_h; uniform vec4 moire_v; uniform vec4 scanline_h; uniform vec4 scanline_v; uniform vec3 corner; uniform float sync; uniform float beat; const float PI=3.14159265358979323846; vec2 angle=screen_size*PI; vec2 screen(in vec2 p,in float bend,in float radius) { float d=bend+sync*0.0625+beat*0.0375; return p*(1.5-(radius*cos(p.x*d)+radius*cos(p.y*d)))-0.5; } vec3 get_color(in sampler2D tex,in vec2 p) { return texture2D(tex,clamp(p,-1.0,0.0)).xyz; } float letterbox(in vec2 p,in float w,in float radius,in float smooth) { return 1.0-smoothstep(smooth,1.0,length(max(abs(p*w+w/2.0)-vec2(radius),0.0))+radius); } void main(void) { vec2 q=gl_FragCoord.xy/screen_size.xy; vec2 p=-1.0+2.0*gl_FragCoord.xy/screen_size.xy; p.y+=0.025*sync; vec2 z=screen(p,deform.x,deform.y); vec2 z1=screen(p,deform.x,deform.y+ghost1.z); vec2 z2=screen(p,deform.x,deform.y+ghost2.z); vec2 z3=screen(p,glass.w,deform.y+glass.x-glass.y); vec2 z4=screen(p,glass.w,deform.y+glass.x+glass.y); float mask=q.x*(6.0-q.x*6.0)*q.y*(6.0-q.y*6.0); vec3 source=get_color(texture,z); vec3 g1=get_color(texture,z1-ghost1.xy); vec3 g2=get_color(texture,z2-ghost2.xy); vec3 g3=get_color(texture,z3); vec3 g4=get_color(texture,z4); vec3 c=source+g1*ghost1.w+g2*ghost2.w; // mix float v=aberration/float(screen_size.x/ratio_2d.x); //+aberration/float(screen_size.x)*(2.0-mask); vec3 ca1=get_color(texture,vec2(z.x-v,z.y)); vec3 ca2=get_color(texture,vec2(z.x+v,z.y)); c+=vec3(ca1.x,c.y,ca2.z); // chromatic aberration vec3 c1=vec3(gradient_color.x,gradient_color.y,gradient_color.z); vec3 c2=vec3(gradient_color.x,gradient_color.y,gradient_color.z)/4; vec3 c3=vec3(1.0,1.0,1.0); vec3 c4=vec3(gradient_color.z,gradient_color.y,gradient_color.x); vec3 c5=vec3(gradient_color.z,gradient_color.y,gradient_color.x)/4; vec3 r; float r_p=gradient.x; float r_h=gradient.y; float r_h2=gradient.y/2; float k=z.y+1.0; if (k <= r_p - r_h2) r = mix(c1,c2,k*(1/(r_p-r_h2))); else if (k <= r_p) r = mix(c2,c3,(k-(r_p-r_h2))*(1/r_h2)); else if (k < r_p + r_h) r = mix(c3,c4,(k-r_p)*(1/r_h)); else r = mix(c4,c5,k*((k-(r_p+r_h))/(r_p-r_h))); //c*=moire_h.x+moire_h.y*sin(z.y*float(screen_size.y*moire_h.z)/ratio_2d.y)*sin(0.5+z.x*float(screen_size.x*moire_h.w)/ratio_2d.x); // moire h //c*=moire_v.x+moire_v.y*sin(z.x*float(screen_size.x*moire_v.z)/ratio_2d.x)*sin(0.5+z.y*float(screen_size.y*moire_v.w)/ratio_2d.y); // moire v c*=moire_h.x+moire_h.y*sin(z.y*float(angle.y*moire_h.z)/ratio_2d.y)*sin(PI+z.x*float(screen_size.x*moire_h.w)/ratio_2d.x); // moire h c*=moire_v.x+moire_v.y*sin(z.x*float(angle.x*moire_v.z)/ratio_2d.x)*sin(PI+z.y*float(screen_size.y*moire_v.w)/ratio_2d.y); // moire v c*=scanline_h.x+scanline_h.y*cos(z.y*float(angle.y*scanline_h.z+scanline_h.w)/ratio_2d.y); // scanline h c*=scanline_v.x+scanline_v.y*cos(z.x*float(angle.x*scanline_v.z+scanline_v.w)/ratio_2d.x); // scanline v c+=r*gradient.z; // gradient c*=mix(1.0,mask,vignetting); // vignetting c*=letterbox(z,corner.x+2.0,corner.y,corner.z); // corner c+=(g3+g4)*glass.z; // glass gl_FragColor=vec4(c,1.0); } |
@@ -1,48 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D texture; | |||||
uniform vec2 screen_size; | |||||
uniform vec4 radial; | |||||
vec3 deform(in vec2 p) | |||||
{ | |||||
float zoom = 0.5; | |||||
vec2 uv = p * zoom - 0.5; | |||||
return texture2D(texture, uv).xyz; | |||||
} | |||||
void main(void) | |||||
{ | |||||
vec2 p = -1.0 + 2.0 * pass_TexCoord; | |||||
vec2 s = p; | |||||
vec3 source=deform(s); | |||||
vec3 color = vec3(1.0,1.0,1.0); | |||||
vec2 d = -p / float(radial.z * radial.x); | |||||
float w = 1.0; | |||||
for(int i = 0; i < radial.z; i++) | |||||
{ | |||||
vec3 c = deform(s); | |||||
color += c * w; | |||||
w *= radial.y; | |||||
s += d; | |||||
} | |||||
gl_FragColor = vec4(source + color * radial.w, 1.0); | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D texture; uniform vec2 screen_size; uniform vec4 radial; vec3 deform(in vec2 p) { float zoom = 0.5; vec2 uv = p * zoom - 0.5; return texture2D(texture, uv).xyz; } void main(void) { vec2 p = -1.0 + 2.0 * pass_TexCoord; vec2 s = p; vec3 source=deform(s); vec3 color = vec3(1.0,1.0,1.0); vec2 d = -p / float(radial.z * radial.x); float w = 1.0; for(int i = 0; i < radial.z; i++) { vec3 c = deform(s); color += c * w; w *= radial.y; s += d; } gl_FragColor = vec4(source + color * radial.w, 1.0); } |
@@ -1,34 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D source; | |||||
uniform sampler2D buffer; | |||||
uniform vec2 mix; | |||||
void main(void) | |||||
{ | |||||
vec4 old_color = texture2D(buffer, pass_TexCoord); | |||||
vec4 new_color = texture2D(source, pass_TexCoord); | |||||
/* The old way */ | |||||
//gl_FragColor = new_color * mix.x + old_color * mix.y; | |||||
/* The new way: if new_color > old_color we want faster updates */ | |||||
gl_FragColor = max(new_color, new_color * mix.x + old_color * mix.y); | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D source; uniform sampler2D buffer; uniform vec2 mix; void main(void) { vec4 old_color = texture2D(buffer, pass_TexCoord); vec4 new_color = texture2D(source, pass_TexCoord); /* The old way */ //gl_FragColor = new_color * mix.x + old_color * mix.y; /* The new way: if new_color > old_color we want faster updates */ gl_FragColor = max(new_color, new_color * mix.x + old_color * mix.y); } |
@@ -1,53 +1 @@ | |||||
// | |||||
// Neercs | |||||
// | |||||
#if !defined __VIDEO_RENDER_H__ | |||||
#define __VIDEO_RENDER_H__ | |||||
class Render : public WorldEntity | |||||
{ | |||||
public: | |||||
Render(caca_canvas_t *caca); | |||||
virtual ~Render(); | |||||
char const *GetName() { return "<title>"; } | |||||
protected: | |||||
virtual void TickGame(float seconds); | |||||
virtual void TickDraw(float seconds); | |||||
void Draw2D(); | |||||
void Draw3D(); | |||||
private: | |||||
int CreateGLWindow(); | |||||
int InitDraw(); | |||||
void ShaderSimple(Framebuffer *fbo_output, int n); | |||||
void TraceQuad(); | |||||
void Pause(); | |||||
void Shader(); | |||||
void InitShaderVar(); | |||||
void UpdateVar(); | |||||
void UpdateSize(); | |||||
caca_canvas_t *m_cv_screen, *m_cv_setup; | |||||
class TextRender *m_txt_screen, *m_txt_setup; | |||||
Entity *m_fps_debug; | |||||
bool m_ready; | |||||
bool m_pause; | |||||
bool m_shader; | |||||
bool m_shader_remanence; | |||||
bool m_shader_glow; | |||||
bool m_shader_blur; | |||||
bool m_shader_postfx; | |||||
bool m_shader_copper; | |||||
bool m_shader_color; | |||||
bool m_shader_noise; | |||||
bool m_shader_mirror; | |||||
bool m_shader_radial; | |||||
}; | |||||
#endif // __VIDEO_RENDER_H__ | |||||
// // Neercs // #if !defined __VIDEO_RENDER_H__ #define __VIDEO_RENDER_H__ class Render : public WorldEntity { public: Render(caca_canvas_t *caca); virtual ~Render(); char const *GetName() { return "<title>"; } protected: virtual void TickGame(float seconds); virtual void TickDraw(float seconds); void Draw2D(); void Draw3D(); private: int CreateGLWindow(); int InitDraw(); void ShaderSimple(Framebuffer *fbo_output, int n); void TraceQuad(); void Pause(); void Shader(); void InitShaderVar(); void UpdateVar(); void UpdateSize(); caca_canvas_t *m_cv_screen, *m_cv_setup; class TextRender *m_txt_screen, *m_txt_setup; Entity *m_fps_debug; bool m_ready; bool m_pause; bool m_shader; bool m_shader_remanence; bool m_shader_glow; bool m_shader_blur; bool m_shader_postfx; bool m_shader_copper; bool m_shader_color; bool m_shader_noise; bool m_shader_mirror; bool m_shader_radial; }; #endif // __VIDEO_RENDER_H__ |
@@ -1,25 +1 @@ | |||||
[vert.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
void main() | |||||
{ | |||||
gl_Position = gl_Vertex; | |||||
pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; | |||||
} | |||||
[frag.glsl] | |||||
#version 120 | |||||
varying vec2 pass_TexCoord; | |||||
uniform sampler2D texture; | |||||
void main(void) | |||||
{ | |||||
gl_FragColor = texture2D(texture, pass_TexCoord); | |||||
} | |||||
[vert.glsl] #version 120 varying vec2 pass_TexCoord; void main() { gl_Position = gl_Vertex; pass_TexCoord = vec2(0.5, 0.5) + 0.5 * gl_Vertex.xy; } [frag.glsl] #version 120 varying vec2 pass_TexCoord; uniform sampler2D texture; void main(void) { gl_FragColor = texture2D(texture, pass_TexCoord); } |
@@ -1,35 +1 @@ | |||||
// | |||||
// Neercs | |||||
// | |||||
#if !defined __TEXT_RENDER_H__ | |||||
#define __TEXT_RENDER_H__ | |||||
class TextRender | |||||
{ | |||||
public: | |||||
TextRender(caca_canvas_t *caca, ivec2 font_size); | |||||
void Init(); | |||||
void Render(); | |||||
void Blit(ivec2 pos, ivec2 size); | |||||
private: | |||||
void CreateBuffers(); | |||||
caca_canvas_t *m_caca; | |||||
ivec2 m_font_size, m_canvas_size, m_fbo_size; | |||||
int m_cells; | |||||
TileSet *m_font; | |||||
Shader *m_shader; | |||||
ShaderAttrib m_color, m_char, m_vertexid; | |||||
ShaderUniform m_texture, m_transform, m_datasize; | |||||
VertexDeclaration *m_vdecl; | |||||
VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3; | |||||
Framebuffer *m_fbo; | |||||
}; | |||||
#endif // __TEXT_RENDER_H__ | |||||
// // Neercs // #if !defined __TEXT_RENDER_H__ #define __TEXT_RENDER_H__ class TextRender { public: TextRender(caca_canvas_t *caca, ivec2 font_size); void Init(); void Render(); void Blit(ivec2 pos, ivec2 size); private: void CreateBuffers(); caca_canvas_t *m_caca; ivec2 m_font_size, m_canvas_size, m_fbo_size; int m_cells; TileSet *m_font; Shader *m_shader; ShaderAttrib m_color, m_char, m_vertexid; ShaderUniform m_texture, m_transform, m_datasize; VertexDeclaration *m_vdecl; VertexBuffer *m_vbo1, *m_vbo2, *m_vbo3; Framebuffer *m_fbo; }; #endif // __TEXT_RENDER_H__ |
@@ -1,104 +1 @@ | |||||
[vert.glsl] | |||||
#version 130 | |||||
#define HAVE_SHADER_4 1 | |||||
#if HAVE_SHADER_4 | |||||
in uint in_Char, in_Attr; | |||||
#else | |||||
attribute vec4 in_Char, in_Attr; | |||||
attribute float in_VertexID; | |||||
# define out varying | |||||
#endif | |||||
out vec4 pass_Foreground; | |||||
out vec4 pass_Background; | |||||
out vec2 pass_UV; | |||||
uniform vec2 u_DataSize; | |||||
uniform mat4 u_Transform; | |||||
void main() | |||||
{ | |||||
#if HAVE_SHADER_4 | |||||
float u = float(in_Char & 0xfu) / 32.0 + 0.0; | |||||
float v = float((in_Char >> 4u) & 0xfu) / 32.0 + 0.5; | |||||
#else | |||||
vec4 tmp_Char = in_Char * 255.0; | |||||
float u = mod(tmp_Char.x, 16.0) / 32.0 + 0.0; | |||||
float v = floor(tmp_Char.x / 16.0) / 32.0 + 0.5; | |||||
#endif | |||||
pass_UV = vec2(u, v); | |||||
#if HAVE_SHADER_4 | |||||
float A = float(in_Attr >> 29u) / 7.0; | |||||
float B = float((in_Attr >> 25u) & 0xfu) / 15.0; | |||||
float C = float((in_Attr >> 21u) & 0xfu) / 15.0; | |||||
float D = float((in_Attr >> 18u) & 0x7u) / 7.0; | |||||
float E = float((in_Attr >> 15u) & 0x7u) / 7.0; | |||||
float F = float((in_Attr >> 11u) & 0xfu) / 15.0; | |||||
float G = float((in_Attr >> 7u) & 0xfu) / 15.0; | |||||
float H = float((in_Attr >> 4u) & 0x7u) / 7.0; | |||||
#else | |||||
vec4 tmp_Attr = in_Attr * 255.0; | |||||
float A = floor(tmp_Attr.w / 32.0) / 7.0; | |||||
float B = mod(floor(tmp_Attr.w / 2.0), 16.0) / 15.0; | |||||
float C = (mod(tmp_Attr.w, 2.0) * 8.0 + floor(tmp_Attr.z / 32.0)) / 15.0; | |||||
float D = mod(floor(tmp_Attr.z / 4.0), 8.0) / 7.0; | |||||
float E = (mod(tmp_Attr.z, 4.0) * 2.0 + floor(tmp_Attr.y / 128.0)) / 7.0; | |||||
float F = mod(floor(tmp_Attr.y / 8.0), 16.0) / 15.0; | |||||
float G = (mod(tmp_Attr.y, 8.0) * 2.0 + floor(tmp_Attr.x / 128.0)) / 15.0; | |||||
float H = mod(floor(tmp_Attr.x / 16.0), 8.0) / 7.0; | |||||
#endif | |||||
pass_Background = vec4(B + 0.0625, C + 0.125, D + 0.125, 1.0 - A); | |||||
pass_Foreground = vec4(F, G, H, 1.0 - E); | |||||
if (B + C + D < 0.01) A = 1.0; | |||||
if (F + G + H < 0.01) E = 1.0; | |||||
// This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); | |||||
gl_PointSize = u_DataSize[1]; | |||||
#if HAVE_SHADER_4 | |||||
vec2 coord = vec2(gl_VertexID % int(u_DataSize[0]), | |||||
gl_VertexID / int(u_DataSize[0])); | |||||
#else | |||||
vec2 coord = vec2(mod(in_VertexID, u_DataSize[0]), | |||||
floor(in_VertexID / u_DataSize[0])); | |||||
#endif | |||||
gl_Position = u_Transform * vec4(coord, 0.0, 1.0); | |||||
} | |||||
[frag.glsl] | |||||
#version 130 | |||||
#define HAVE_SHADER_4 1 | |||||
#if HAVE_SHADER_4 | |||||
out vec4 out_Color; | |||||
#else | |||||
# define out_Color gl_FragColor | |||||
# define in varying | |||||
# define out | |||||
#endif | |||||
in vec4 pass_Foreground; | |||||
in vec4 pass_Background; | |||||
in vec2 pass_UV; | |||||
uniform sampler2D u_Texture; | |||||
void main(void) | |||||
{ | |||||
vec2 c = gl_PointCoord * (1.0 / 32.0) + pass_UV; | |||||
float t = texture2D(u_Texture, c).x; | |||||
out_Color = mix(pass_Background, pass_Foreground, t); | |||||
} | |||||
[vert.glsl] #version 130 #define HAVE_SHADER_4 1 #if HAVE_SHADER_4 in uint in_Char, in_Attr; #else attribute vec4 in_Char, in_Attr; attribute float in_VertexID; # define out varying #endif out vec4 pass_Foreground; out vec4 pass_Background; out vec2 pass_UV; uniform vec2 u_DataSize; uniform mat4 u_Transform; void main() { #if HAVE_SHADER_4 float u = float(in_Char & 0xfu) / 32.0 + 0.0; float v = float((in_Char >> 4u) & 0xfu) / 32.0 + 0.5; #else vec4 tmp_Char = in_Char * 255.0; float u = mod(tmp_Char.x, 16.0) / 32.0 + 0.0; float v = floor(tmp_Char.x / 16.0) / 32.0 + 0.5; #endif pass_UV = vec2(u, v); #if HAVE_SHADER_4 float A = float(in_Attr >> 29u) / 7.0; float B = float((in_Attr >> 25u) & 0xfu) / 15.0; float C = float((in_Attr >> 21u) & 0xfu) / 15.0; float D = float((in_Attr >> 18u) & 0x7u) / 7.0; float E = float((in_Attr >> 15u) & 0x7u) / 7.0; float F = float((in_Attr >> 11u) & 0xfu) / 15.0; float G = float((in_Attr >> 7u) & 0xfu) / 15.0; float H = float((in_Attr >> 4u) & 0x7u) / 7.0; #else vec4 tmp_Attr = in_Attr * 255.0; float A = floor(tmp_Attr.w / 32.0) / 7.0; float B = mod(floor(tmp_Attr.w / 2.0), 16.0) / 15.0; float C = (mod(tmp_Attr.w, 2.0) * 8.0 + floor(tmp_Attr.z / 32.0)) / 15.0; float D = mod(floor(tmp_Attr.z / 4.0), 8.0) / 7.0; float E = (mod(tmp_Attr.z, 4.0) * 2.0 + floor(tmp_Attr.y / 128.0)) / 7.0; float F = mod(floor(tmp_Attr.y / 8.0), 16.0) / 15.0; float G = (mod(tmp_Attr.y, 8.0) * 2.0 + floor(tmp_Attr.x / 128.0)) / 15.0; float H = mod(floor(tmp_Attr.x / 16.0), 8.0) / 7.0; #endif pass_Background = vec4(B + 0.0625, C + 0.125, D + 0.125, 1.0 - A); pass_Foreground = vec4(F, G, H, 1.0 - E); if (B + C + D < 0.01) A = 1.0; if (F + G + H < 0.01) E = 1.0; // This only works with glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); gl_PointSize = u_DataSize[1]; #if HAVE_SHADER_4 vec2 coord = vec2(gl_VertexID % int(u_DataSize[0]), gl_VertexID / int(u_DataSize[0])); #else vec2 coord = vec2(mod(in_VertexID, u_DataSize[0]), floor(in_VertexID / u_DataSize[0])); #endif gl_Position = u_Transform * vec4(coord, 0.0, 1.0); } [frag.glsl] #version 130 #define HAVE_SHADER_4 1 #if HAVE_SHADER_4 out vec4 out_Color; #else # define out_Color gl_FragColor # define in varying # define out #endif in vec4 pass_Foreground; in vec4 pass_Background; in vec2 pass_UV; uniform sampler2D u_Texture; void main(void) { vec2 c = gl_PointCoord * (1.0 / 32.0) + pass_UV; float t = texture2D(u_Texture, c).x; out_Color = mix(pass_Background, pass_Foreground, t); } |