mirror of
https://github.com/irssi/irssi.git
synced 2026-08-11 12:53:42 +02:00
Dependencies finally work correctly in perl libraries (they're each compiled
separately now). Added statusbar code to available to perl, it's now possible to create new statusbar items with perl scripts. statusbar_items_redraw(char *name) can now be used to easily redraw all named statusbar items in screen. Probably several other changes I've already forgotten :) git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1861 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
17f4d6b5de
commit
76c6e9ab83
48 changed files with 430 additions and 126 deletions
|
|
@ -1,7 +1,7 @@
|
|||
Makefile
|
||||
Makefile.PL
|
||||
TextUI.c
|
||||
TextUI.bs
|
||||
*.c
|
||||
*.o
|
||||
pm_to_blib
|
||||
blib
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use ExtUtils::MakeMaker;
|
|||
|
||||
WriteMakefile('NAME' => 'Irssi::TextUI',
|
||||
'LIBS' => '',
|
||||
'OBJECT' => '$(O_FILES)',
|
||||
'TYPEMAPS' => ['../common/typemap', '../ui/typemap'],
|
||||
'INC' => '-I../../.. -I@top_srcdir@/src -I@top_srcdir@/src/core -I@top_srcdir@/src/fe-common/core -I@top_srcdir@/src/fe-text @GLIB_CFLAGS@',
|
||||
'VERSION_FROM' => '@srcdir@/TextUI.pm');
|
||||
|
|
|
|||
159
src/perl/textui/Statusbar.xs
Normal file
159
src/perl/textui/Statusbar.xs
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
#include "module.h"
|
||||
|
||||
static GHashTable *perl_sbar_defs;
|
||||
|
||||
static int check_sbar_destroy(char *key, char *value, char *script)
|
||||
{
|
||||
if (strncmp(key, script, strlen(script)) == 0 &&
|
||||
key[strlen(script)] == ':') {
|
||||
g_free(key);
|
||||
g_free(value);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void sig_script_destroy(PERL_SCRIPT_REC *script)
|
||||
{
|
||||
g_hash_table_foreach_remove(perl_sbar_defs,
|
||||
(GHRFunc) check_sbar_destroy,
|
||||
script->name);
|
||||
}
|
||||
|
||||
void perl_statusbar_init(void)
|
||||
{
|
||||
perl_sbar_defs = g_hash_table_new((GHashFunc) g_str_hash,
|
||||
(GCompareFunc) g_str_equal);
|
||||
signal_add("script destroy", (SIGNAL_FUNC) sig_script_destroy);
|
||||
}
|
||||
|
||||
static void statusbar_item_def_destroy(void *key, void *value)
|
||||
{
|
||||
g_free(key);
|
||||
g_free(value);
|
||||
}
|
||||
|
||||
void perl_statusbar_deinit(void)
|
||||
{
|
||||
signal_remove("script destroy", (SIGNAL_FUNC) sig_script_destroy);
|
||||
|
||||
g_hash_table_foreach(perl_sbar_defs,
|
||||
(GHFunc) statusbar_item_def_destroy, NULL);
|
||||
g_hash_table_destroy(perl_sbar_defs);
|
||||
}
|
||||
|
||||
static void perl_statusbar_event(char *function, SBAR_ITEM_REC *item,
|
||||
int get_size_only)
|
||||
{
|
||||
dSP;
|
||||
int retcount;
|
||||
SV *item_sv, **sv;
|
||||
HV *hv;
|
||||
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
|
||||
PUSHMARK(SP);
|
||||
item_sv = plain_bless(item, "Irssi::TextUI::StatusbarItem");
|
||||
XPUSHs(sv_2mortal(item_sv));
|
||||
XPUSHs(sv_2mortal(newSViv(get_size_only)));
|
||||
PUTBACK;
|
||||
|
||||
retcount = perl_call_pv(function, G_EVAL|G_DISCARD);
|
||||
SPAGAIN;
|
||||
|
||||
if (SvTRUE(ERRSV)) {
|
||||
STRLEN n_a;
|
||||
char *package;
|
||||
|
||||
package = perl_function_get_package(function);
|
||||
signal_emit("script error", 2,
|
||||
perl_script_find_package(package),
|
||||
SvPV(ERRSV, n_a));
|
||||
g_free(package);
|
||||
}
|
||||
|
||||
/* min_size and max_size can be changed, move them to SBAR_ITEM_REC */
|
||||
hv = hvref(item_sv);
|
||||
if (hv != NULL) {
|
||||
sv = hv_fetch(hv, "min_size", 8, 0);
|
||||
if (sv != NULL) item->min_size = SvIV(*sv);
|
||||
sv = hv_fetch(hv, "max_size", 8, 0);
|
||||
if (sv != NULL) item->max_size = SvIV(*sv);
|
||||
}
|
||||
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
}
|
||||
|
||||
|
||||
static void sig_perl_statusbar(SBAR_ITEM_REC *item, int get_size_only)
|
||||
{
|
||||
char *function;
|
||||
|
||||
function = g_hash_table_lookup(perl_sbar_defs, item->config->name);
|
||||
if (function != NULL)
|
||||
perl_statusbar_event(function, item, get_size_only);
|
||||
else {
|
||||
/* use default function - this shouldn't actually happen.. */
|
||||
statusbar_item_default_handler(item, get_size_only, NULL, "", TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
MODULE = Irssi::TextUI::Statusbar PACKAGE = Irssi
|
||||
PROTOTYPES: ENABLE
|
||||
|
||||
void
|
||||
statusbar_item_register(name, value, func = NULL)
|
||||
char *name
|
||||
char *value
|
||||
char *func
|
||||
CODE:
|
||||
statusbar_item_register(name, value, func == NULL || *func == '\0' ? NULL : sig_perl_statusbar);
|
||||
if (func != NULL) {
|
||||
g_hash_table_insert(perl_sbar_defs, g_strdup(name),
|
||||
g_strdup_printf("%s::%s", perl_get_package(), func));
|
||||
}
|
||||
|
||||
void
|
||||
statusbar_item_unregister(name)
|
||||
char *name
|
||||
PREINIT:
|
||||
gpointer key, value;
|
||||
CODE:
|
||||
if (g_hash_table_lookup_extended(perl_sbar_defs, name, &key, &value)) {
|
||||
g_hash_table_remove(perl_sbar_defs, name);
|
||||
g_free(key);
|
||||
g_free(value);
|
||||
}
|
||||
statusbar_item_unregister(name);
|
||||
|
||||
void
|
||||
statusbar_items_redraw(name)
|
||||
char *name
|
||||
|
||||
void
|
||||
statusbars_recreate_items()
|
||||
|
||||
#*******************************
|
||||
MODULE = Irssi::TextUI::Statusbar PACKAGE = Irssi::TextUI::StatusbarItem PREFIX = statusbar_item_
|
||||
#*******************************
|
||||
|
||||
void
|
||||
statusbar_item_default_handler(item, get_size_only, str, data, escape_vars = TRUE)
|
||||
Irssi::TextUI::StatusbarItem item
|
||||
int get_size_only
|
||||
char *str
|
||||
char *data
|
||||
int escape_vars
|
||||
PREINIT:
|
||||
HV *hv;
|
||||
CODE:
|
||||
statusbar_item_default_handler(item, get_size_only,
|
||||
*str == '\0' ? NULL : str,
|
||||
data, escape_vars);
|
||||
hv = hvref(ST(0));
|
||||
hv_store(hv, "min_size", 8, newSViv(item->min_size), 0);
|
||||
hv_store(hv, "max_size", 8, newSViv(item->max_size), 0);
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
MODULE = Irssi::TextUI PACKAGE = Irssi
|
||||
#include "module.h"
|
||||
|
||||
MODULE = Irssi::TextUI::TextBuffer PACKAGE = Irssi
|
||||
PROTOTYPES: ENABLE
|
||||
|
||||
Irssi::TextUI::TextBuffer
|
||||
textbuffer_create()
|
||||
|
||||
#*******************************
|
||||
MODULE = Irssi::TextUI PACKAGE = Irssi::TextUI::TextBuffer PREFIX = textbuffer_
|
||||
MODULE = Irssi::TextUI::TextBuffer PACKAGE = Irssi::TextUI::TextBuffer PREFIX = textbuffer_
|
||||
#*******************************
|
||||
|
||||
void
|
||||
|
|
@ -36,7 +39,7 @@ textbuffer_remove_all_lines(buffer)
|
|||
Irssi::TextUI::TextBuffer buffer
|
||||
|
||||
#*******************************
|
||||
MODULE = Irssi::TextUI PACKAGE = Irssi::TextUI::Line PREFIX = textbuffer_line_
|
||||
MODULE = Irssi::TextUI::TextBuffer PACKAGE = Irssi::TextUI::Line PREFIX = textbuffer_line_
|
||||
#*******************************
|
||||
|
||||
Irssi::TextUI::Line
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
MODULE = Irssi::TextUI PACKAGE = Irssi::TextUI::TextBuffer PREFIX = textbuffer_
|
||||
#include "module.h"
|
||||
|
||||
MODULE = Irssi::TextUI::TextBufferView PACKAGE = Irssi::TextUI::TextBuffer PREFIX = textbuffer_
|
||||
PROTOTYPES: ENABLE
|
||||
|
||||
Irssi::TextUI::TextBufferView
|
||||
textbuffer_view_create(buffer, width, height, default_indent, longword_noindent, scroll)
|
||||
|
|
@ -10,7 +13,7 @@ textbuffer_view_create(buffer, width, height, default_indent, longword_noindent,
|
|||
int scroll
|
||||
|
||||
#*******************************
|
||||
MODULE = Irssi::TextUI PACKAGE = Irssi::TextUI::TextBufferView PREFIX = textbuffer_view_
|
||||
MODULE = Irssi::TextUI::TextBufferView PACKAGE = Irssi::TextUI::TextBufferView PREFIX = textbuffer_view_
|
||||
#*******************************
|
||||
|
||||
void
|
||||
|
|
@ -92,7 +95,7 @@ textbuffer_view_redraw(view)
|
|||
Irssi::TextUI::TextBufferView view
|
||||
|
||||
#*******************************
|
||||
MODULE = Irssi::TextUI PACKAGE = Irssi::UI::Window
|
||||
MODULE = Irssi::TextUI::TextBufferView PACKAGE = Irssi::UI::Window
|
||||
#*******************************
|
||||
|
||||
Irssi::TextUI::TextBufferView
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package Irssi::TextUI;
|
|||
use strict;
|
||||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
|
||||
|
||||
$VERSION = "0.8";
|
||||
$VERSION = "0.9";
|
||||
|
||||
require Exporter;
|
||||
require DynaLoader;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,14 @@ static void perl_line_info_fill_hash(HV *hv, LINE_INFO_REC *info)
|
|||
hv_store(hv, "time", 4, newSViv(info->time), 0);
|
||||
}
|
||||
|
||||
static void perl_statusbar_item_fill_hash(HV *hv, SBAR_ITEM_REC *item)
|
||||
{
|
||||
hv_store(hv, "min_size", 8, newSViv(item->min_size), 0);
|
||||
hv_store(hv, "max_size", 8, newSViv(item->max_size), 0);
|
||||
hv_store(hv, "xpos", 4, newSViv(item->xpos), 0);
|
||||
hv_store(hv, "size", 4, newSViv(item->size), 0);
|
||||
}
|
||||
|
||||
static PLAIN_OBJECT_INIT_REC textui_plains[] = {
|
||||
{ "Irssi::TextUI::MainWindow", (PERL_OBJECT_FUNC) perl_main_window_fill_hash },
|
||||
{ "Irssi::TextUI::TextBuffer", (PERL_OBJECT_FUNC) perl_text_buffer_fill_hash },
|
||||
|
|
@ -68,6 +76,7 @@ static PLAIN_OBJECT_INIT_REC textui_plains[] = {
|
|||
{ "Irssi::TextUI::Line", (PERL_OBJECT_FUNC) perl_line_fill_hash },
|
||||
{ "Irssi::TextUI::LineCache", (PERL_OBJECT_FUNC) perl_line_cache_fill_hash },
|
||||
{ "Irssi::TextUI::LineInfo", (PERL_OBJECT_FUNC) perl_line_info_fill_hash },
|
||||
{ "Irssi::TextUI::StatusbarItem", (PERL_OBJECT_FUNC) perl_statusbar_item_fill_hash },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
@ -86,6 +95,12 @@ CODE:
|
|||
initialized = TRUE;
|
||||
|
||||
irssi_add_plains(textui_plains);
|
||||
perl_statusbar_init();
|
||||
|
||||
void
|
||||
deinit()
|
||||
CODE:
|
||||
perl_statusbar_deinit();
|
||||
|
||||
MODULE = Irssi::TextUI PACKAGE = Irssi
|
||||
|
||||
|
|
@ -95,5 +110,7 @@ gui_printtext(xpos, ypos, str)
|
|||
int ypos
|
||||
char *str
|
||||
|
||||
INCLUDE: TextBuffer.xs
|
||||
INCLUDE: TextBufferView.xs
|
||||
BOOT:
|
||||
irssi_boot(TextUI__Statusbar);
|
||||
irssi_boot(TextUI__TextBuffer);
|
||||
irssi_boot(TextUI__TextBufferView);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "mainwindows.h"
|
||||
#include "gui-windows.h"
|
||||
#include "gui-printtext.h"
|
||||
#include "statusbar.h"
|
||||
#include "textbuffer.h"
|
||||
#include "textbuffer-view.h"
|
||||
|
||||
|
|
@ -12,3 +13,4 @@ typedef TEXT_BUFFER_VIEW_REC *Irssi__TextUI__TextBufferView;
|
|||
typedef LINE_REC *Irssi__TextUI__Line;
|
||||
typedef LINE_CACHE_REC *Irssi__TextUI__LineCache;
|
||||
typedef LINE_INFO_REC *Irssi__TextUI__LineInfo;
|
||||
typedef SBAR_ITEM_REC *Irssi__TextUI__StatusbarItem;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Irssi::TextUI::TextBufferView T_PlainObj
|
|||
Irssi::TextUI::Line T_PlainObj
|
||||
Irssi::TextUI::LineCache T_PlainObj
|
||||
Irssi::TextUI::LineInfo T_PlainObj
|
||||
Irssi::TextUI::StatusbarItem T_PlainObj
|
||||
|
||||
INPUT
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue