repo: rxvt-unicode-sixel action: commit revision: path_from: revision_from: 47f1935ea8c0f4cdfbc2e8ef0197a4fc58a81403: path_to: revision_to:
commit 47f1935ea8c0f4cdfbc2e8ef0197a4fc58a81403 Author: Marc LehmannDate: Sun Feb 20 00:09:25 2005 +0000 *** empty log message *** diff --git a/Changes b/Changes
--- a/Changes
+++ b/Changes
@@ -17,6 +17,9 @@ WISH: just for fun, do shade and tint with XRender.
that uses an existing pty for I/O instead of starting
a command.
- implement enough of XEMBED to allow for correct focus.
+ - added doc/embed-tk, an embedding example in Perl/Tk,
+ and doc/rxvt-tabbed, a primitive tabbed shell implemented
+ in Perl/Gtk2.
- fix assertioan failure ("crash") on mousewheel-scrolling
when the terminal height is small, by removing the assert.
(reported by Mikael Magnusson).
diff --git a/MANIFEST b/MANIFEST
--- a/MANIFEST
+++ b/MANIFEST
@@ -11,6 +11,8 @@ reconf
genac
doc/embed
+doc/embed-tk
+doc/rxvt-tabbed
doc/pty-fd
doc/etc/rxvt-unicode.terminfo
doc/etc/rxvt-unicode.termcap
diff --git a/doc/embed-tk b/doc/embed-tk
new file mode 100755
index 0000000000000000000000000000000000000000..e502314ac31a4cc770e9aa9005ae04ec52239a66
--- /dev/null
+++ b/doc/embed-tk
@@ -0,0 +1,16 @@
+#!/usr/bin/perl
+
+# sample script to illustrate the -embed option
+# using Tk
+# resizes do not work yet.
+
+use Tk;
+
+my $mw = new MainWindow;
+
+my $frame = $mw->Frame (width => 700, height => 400, container => 1)
+ ->pack (fill => "both", expand => 1);
+
+system "rxvt -embed " . ($frame->id) . " &";
+
+MainLoop;
diff --git a/doc/rxvt-tabbed b/doc/rxvt-tabbed
new file mode 100755
index 0000000000000000000000000000000000000000..64247ba4cb1f59e505405d59560c69be8241d7a6
--- /dev/null
+++ b/doc/rxvt-tabbed
@@ -0,0 +1,142 @@
+#!/usr/bin/perl
+
+# I tried to write this with Tk, as it uses elss memory and is
+# more widely available. Alas, Tk is rather broken with respect to embedding.
+
+# on debian, do:
+# apt-get install libgtk2-perl
+
+my $RXVT_BASENAME = "rxvt";
+
+use Gtk2;
+use Encode;
+
+my $event_cb; # $wid => $cb
+
+init Gtk2;
+
+my $window = new Gtk2::Window 'toplevel';
+
+my $vbox = new Gtk2::VBox;
+$window->add ($vbox);
+
+my $notebook = new Gtk2::Notebook;
+$vbox->pack_start ($notebook, 1, 1, 0);
+
+$notebook->can_focus (0);
+$notebook->set (scrollable => 1);
+
+sub new_terminal {
+ my ($title, @args) = @_;
+
+ my $label = new Gtk2::Label $title;
+
+ my $rxvt = new Gtk2::Socket;
+ $rxvt->can_focus (1);
+
+ my $wm_normal_hints = sub {
+ my ($window) = @_;
+ my ($type, $format, @data)
+ = $window->property_get (
+ Gtk2::Gdk::Atom->intern ("WM_NORMAL_HINTS", 0),
+ Gtk2::Gdk::Atom->intern ("WM_SIZE_HINTS", 0),
+ 0, 70*4, 0
+ );
+ my ($width_inc, $height_inc, $base_width, $base_height) = @data[9,10,15,16];
+
+ my $hints = new Gtk2::Gdk::Geometry;
+ $hints->base_width ($base_width); $hints->base_height ($base_height);
+ $hints->width_inc ($width_inc); $hints->height_inc ($height_inc);
+
+ $rxvt->get_toplevel->set_geometry_hints ($rxvt, $hints, [qw(base-size resize-inc)]);
+ };
+
+ $rxvt->signal_connect_after (realize => sub {
+ my $win = $_[0]->window;
+
+ if (fork == 0) {
+ exec $RXVT_BASENAME,
+ -embed => $win->get_xid, @args;
+ exit (255);
+ }
+
+ 0
+ });
+
+ $rxvt->signal_connect_after (plug_added => sub {
+ my ($socket) = @_;
+ my $plugged = ($socket->window->get_children)[0];
+
+ $plugged->set_events ($plugged->get_events + ["property-change-mask"]);
+
+ $wm_normal_hints->($plugged);
+
+ $event_cb{$plugged} = sub {
+ my ($event) = @_;
+ my $window = $event->window;
+
+ if (Gtk2::Gdk::Event::Configure:: eq ref $event) {
+ $wm_normal_hints->($window);
+ } elsif (Gtk2::Gdk::Event::Property:: eq ref $event) {
+ my $atom = $event->atom;
+ my $name = $atom->name;
+
+ return if $event->state; # GDK_PROPERTY_NEW_VALUE == 0
+
+
+ if ($name eq "_NET_WM_NAME") {
+ my ($type, $format, $data)
+ = $window->property_get (
+ $atom,
+ Gtk2::Gdk::Atom->intern ("UTF8_STRING", 0),
+ 0, 128, 0
+ );
+
+ $label->set_text (Encode::decode_utf8 $data);
+ }
+ }
+
+ 0;
+ };
+
+ 0;
+ });
+
+ $rxvt->signal_connect_after (map_event => sub {
+ $_[0]->grab_focus;
+ 0
+ });
+
+ $notebook->append_page ($rxvt, $label);
+
+ $rxvt->show_all;
+
+ $notebook->set_current_page ($notebook->page_num ($rxvt));
+
+ $rxvt;
+}
+
+my $new = new Gtk2::Frame;
+$notebook->prepend_page ($new, "New");
+
+$notebook->signal_connect_after (switch_page => sub {
+ if ($_[2] == 0) {
+ new_terminal $RXVT_BASENAME;
+ }
+});
+
+$window->set_default_size (700, 400);
+$window->show_all;
+
+# ugly, but gdk_window_filters are ot available in perl
+
+Gtk2::Gdk::Event->handler_set (sub {
+ my ($event) = @_;
+ my $window = $event->window;
+
+ ($event_cb{$window} && $event_cb{$window}->($event))
+ or Gtk2->main_do_event ($event);
+});
+
+main Gtk2;
+
diff --git a/src/init.C b/src/init.C
--- a/src/init.C
+++ b/src/init.C
@@ -205,6 +205,7 @@ const char *const xa_names[] =
#endif
#if ENABLE_XEMBED
"_XEMBED",
+ "_XEMBED_INFO",
#endif
};
@@ -931,7 +932,7 @@ rxvt_term::create_windows (int argc, const char *const *argv)
long vt_emask;
XSetWindowAttributes attributes;
XWindowAttributes gattr;
- Window top;
+ Window top, parent;
dDisp;
#ifdef USING_W11LIB
@@ -979,59 +980,44 @@ rxvt_term::create_windows (int argc, const char *const *argv)
if (!set_fonts ())
rxvt_fatal ("unable to load base fontset, please specify a valid one using -fn, aborting.\n");
+ parent = DefaultRootWindow (disp);
+
#if ENABLE_XEMBED
if (rs[Rs_embed])
{
XWindowAttributes wattr;
- top = strtol (rs[Rs_embed], 0, 0);
+ parent = strtol (rs[Rs_embed], 0, 0);
- if (!XGetWindowAttributes (disp, top, &wattr))
+ if (!XGetWindowAttributes (disp, parent, &wattr))
rxvt_fatal ("invalid window-id specified with -embed, aborting.\n");
window_calc (wattr.width, wattr.height);
-
-#if 0
- if (wattr.map_state == IsViewable)
- {
- TermWin.mapped = 1;
- refresh_type = FAST_REFRESH;
- XClearWindow (disp, top);
- // TODO: make XMapNotify-event-code a function and call it
- // TODO: how can I detect visibility without unmap/map?
- // TODO: focusin etc.
- }
-#else
- // it's easiest just to unmap/map to get all state correctly set-up
- XUnmapWindow (disp, top);
-#endif
}
- else
+
#endif
- {
- window_calc (0, 0);
+ window_calc (0, 0);
- /* sub-window placement & size in rxvt_resize_subwindows () */
+ /* sub-window placement & size in rxvt_resize_subwindows () */
#ifdef PREFER_24BIT
- attributes.background_pixel = pix_colors_focused[Color_border];
- attributes.border_pixel = pix_colors_focused[Color_border];
- attributes.colormap = display->cmap;
- top = XCreateWindow (disp, DefaultRootWindow (disp),
- szHint.x, szHint.y,
- szHint.width, szHint.height,
- TermWin.ext_bwidth,
- display->depth, InputOutput,
- display->visual,
- CWColormap | CWBackPixel | CWBorderPixel, &attributes);
+ attributes.background_pixel = pix_colors_focused[Color_border];
+ attributes.border_pixel = pix_colors_focused[Color_border];
+ attributes.colormap = display->cmap;
+ top = XCreateWindow (disp, parent,
+ szHint.x, szHint.y,
+ szHint.width, szHint.height,
+ TermWin.ext_bwidth,
+ display->depth, InputOutput,
+ display->visual,
+ CWColormap | CWBackPixel | CWBorderPixel, &attributes);
#else
- top = XCreateSimpleWindow (disp, DefaultRootWindow (disp),
- szHint.x, szHint.y,
- szHint.width, szHint.height,
- TermWin.ext_bwidth,
- pix_colors_focused[Color_border],
- pix_colors_focused[Color_border]);
+ top = XCreateSimpleWindow (disp, parent,
+ szHint.x, szHint.y,
+ szHint.width, szHint.height,
+ TermWin.ext_bwidth,
+ pix_colors_focused[Color_border],
+ pix_colors_focused[Color_border]);
#endif
- }
TermWin.parent[0] = top;
@@ -1187,8 +1173,13 @@ rxvt_term::create_windows (int argc, const char *const *argv)
scr_recolour ();
#if ENABLE_XEMBED
- // why this is necessary, I don't know, race condition??
- XMoveWindow (disp, TermWin.vt, window_vt_x, window_vt_y);
+ if (rs[Rs_embed])
+ {
+ long info[2] = { 0, XEMBED_MAPPED };
+
+ XChangeProperty (disp, parent, xa[XA_XEMBED_INFO], xa[XA_XEMBED_INFO],
+ 32, PropModeReplace, (unsigned char *)&info, 2);
+ }
#endif
}
diff --git a/src/main.C b/src/main.C
--- a/src/main.C
+++ b/src/main.C
@@ -254,11 +254,7 @@ rxvt_term::~rxvt_term ()
#endif
delete TermWin.drawable;
// destroy all windows
- if (TermWin.parent[0]
-#if ENABLE_XEMBED
- && !rs[Rs_embed]
-#endif
- )
+ if (TermWin.parent[0])
XDestroyWindow (disp, TermWin.parent[0]);
}
diff --git a/src/rxvt.h b/src/rxvt.h
--- a/src/rxvt.h
+++ b/src/rxvt.h
@@ -204,6 +204,8 @@ typedef struct _mwmhints {
# define XEMBED_FOCUS_CURRENT 0
# define XEMBED_FOCUS_FIRST 1
# define XEMBED_FOCUS_LAST 2
+
+# define XEMBED_MAPPED (1 << 0)
#endif
/*
@@ -698,6 +700,7 @@ enum {
#endif
#if ENABLE_XEMBED
XA_XEMBED,
+ XA_XEMBED_INFO,
#endif
NUM_XA
};
-----END OF PAGE-----