Replace xtext's transparency with full window transparency

Xtext's transparency barely worked on windows, didn't work on any modern
linux wm and used fake transparency.
This uses gtk's built in window opacity that works on more systems and
is real transparency.
Text area only transparency may return with a transition to cairo, if it
works on Windows.
This commit is contained in:
TingPing 2013-09-26 23:24:27 -04:00
parent f23bda9e46
commit 449553ffb0
11 changed files with 48 additions and 829 deletions

View File

@ -49,7 +49,6 @@ AH_VERBATIM([USE_LIBCANBERRA],[#undef USE_LIBCANBERRA])
AH_VERBATIM([USE_IPV6],[#undef USE_IPV6])
AH_VERBATIM([USE_OPENSSL],[#undef USE_OPENSSL])
AH_VERBATIM([USE_PLUGIN],[#undef USE_PLUGIN])
AH_VERBATIM([USE_XLIB],[#undef USE_XLIB])
AH_VERBATIM([USE_SIGACTION],[#undef USE_SIGACTION])
AH_VERBATIM([USING_FREEBSD],[#undef USING_FREEBSD])
AH_VERBATIM([USING_LINUX],[#undef USING_LINUX])
@ -100,10 +99,6 @@ AC_ARG_ENABLE(textfe,
[AS_HELP_STRING([--enable-textfe],[build the text frontend (default: no)])],
textfe=$enableval, textfe=no)
AC_ARG_ENABLE(xlib,
[AS_HELP_STRING([--disable-xlib],[disable use of xlib (for non X11 systems)])],
xlib=$enableval, xlib=yes)
AC_ARG_ENABLE(python,
[AS_HELP_STRING([--enable-python=pythonversion],[build the python plugin; possible values: "python2", "python3" or specific such as "python3.3" (default on, python2)])],
python=$enableval, python=python2)
@ -214,19 +209,6 @@ fi
GUI_LIBS="$GUI_LIBS $GTK_LIBS"
GUI_CFLAGS="$GUI_CFLAGS $GTK_CFLAGS -DG_DISABLE_SINGLE_INCLUDES -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES -DGTK_DISABLE_SINGLE_INCLUDES"
dnl *********************************************************************
dnl ** XLIB *************************************************************
dnl *********************************************************************
if test "$xlib" = yes; then
AC_DEFINE(USE_XLIB)
if test "$system" = "SunOS"; then
LIBS="$LIBS -L/usr/openwin/lib -lX11"
else
AC_CHECK_LIB(X11, XSetWMHints)
fi
fi
dnl *********************************************************************
dnl ** PERL *************************************************************
dnl *********************************************************************

View File

@ -457,6 +457,7 @@ const struct prefs vars[] =
{"gui_tab_utils", P_OFFINT (hex_gui_tab_utils), TYPE_BOOL},
{"gui_throttlemeter", P_OFFINT (hex_gui_throttlemeter), TYPE_INT},
{"gui_topicbar", P_OFFINT (hex_gui_topicbar), TYPE_BOOL},
{"gui_transparency", P_OFFINT (hex_gui_transparency), TYPE_INT},
{"gui_tray", P_OFFINT (hex_gui_tray), TYPE_BOOL},
{"gui_tray_away", P_OFFINT (hex_gui_tray_away), TYPE_BOOL},
{"gui_tray_blink", P_OFFINT (hex_gui_tray_blink), TYPE_BOOL},
@ -585,9 +586,6 @@ const struct prefs vars[] =
{"text_stripcolor_replay", P_OFFINT (hex_text_stripcolor_replay), TYPE_BOOL},
{"text_stripcolor_topic", P_OFFINT (hex_text_stripcolor_topic), TYPE_BOOL},
{"text_thin_sep", P_OFFINT (hex_text_thin_sep), TYPE_BOOL},
{"text_tint_blue", P_OFFINT (hex_text_tint_blue), TYPE_INT},
{"text_tint_green", P_OFFINT (hex_text_tint_green), TYPE_INT},
{"text_tint_red", P_OFFINT (hex_text_tint_red), TYPE_INT},
{"text_transparent", P_OFFINT (hex_text_transparent), TYPE_BOOL},
{"text_wordwrap", P_OFFINT (hex_text_wordwrap), TYPE_BOOL},
@ -721,6 +719,7 @@ load_default_config(void)
prefs.hex_gui_tab_server = 1;
prefs.hex_gui_tab_sort = 1;
prefs.hex_gui_topicbar = 1;
prefs.hex_gui_transparency = 255;
prefs.hex_gui_tray = 1;
prefs.hex_gui_tray_blink = 1;
prefs.hex_gui_ulist_count = 1;
@ -789,9 +788,6 @@ load_default_config(void)
prefs.hex_notify_timeout = 15;
prefs.hex_text_max_indent = 256;
prefs.hex_text_max_lines = 500;
prefs.hex_text_tint_blue = 195;
prefs.hex_text_tint_green = 195;
prefs.hex_text_tint_red = 195;
prefs.hex_url_grabber_limit = 100; /* 0 means unlimited */
/* STRINGS */

View File

@ -284,6 +284,7 @@ struct hexchatprefs
int hex_gui_tab_pos;
int hex_gui_tab_small;
int hex_gui_tab_trunc;
int hex_gui_transparency;
int hex_gui_throttlemeter;
int hex_gui_ulist_pos;
int hex_gui_ulist_sort;
@ -306,9 +307,6 @@ struct hexchatprefs
int hex_notify_timeout;
int hex_text_max_indent;
int hex_text_max_lines;
int hex_text_tint_blue;
int hex_text_tint_green;
int hex_text_tint_red;
int hex_url_grabber_limit;
/* STRINGS */

View File

@ -52,10 +52,6 @@
#include "urlgrab.h"
#include "setup.h"
#ifdef USE_XLIB
#include <gdk/gdkx.h>
#endif
#ifdef USE_LIBCANBERRA
#include <canberra.h>
#endif
@ -66,49 +62,6 @@ GdkPixmap *channelwin_pix;
static ca_context *ca_con;
#endif
#ifdef USE_XLIB
static void
redraw_trans_xtexts (void)
{
GSList *list = sess_list;
session *sess;
int done_main = FALSE;
while (list)
{
sess = list->data;
if (GTK_XTEXT (sess->gui->xtext)->transparent)
{
if (!sess->gui->is_tab || !done_main)
gtk_xtext_refresh (GTK_XTEXT (sess->gui->xtext), 1);
if (sess->gui->is_tab)
done_main = TRUE;
}
list = list->next;
}
}
static GdkFilterReturn
root_event_cb (GdkXEvent *xev, GdkEventProperty *event, gpointer data)
{
static Atom at = None;
XEvent *xevent = (XEvent *)xev;
if (xevent->type == PropertyNotify)
{
if (at == None)
at = XInternAtom (xevent->xproperty.display, "_XROOTPMAP_ID", True);
if (at == xevent->xproperty.atom)
redraw_trans_xtexts ();
}
return GDK_FILTER_CONTINUE;
}
#endif
/* === command-line parameter parsing : requires glib 2.6 === */
static char *arg_cfgdir = NULL;
@ -281,11 +234,6 @@ fe_args (int argc, char *argv[])
gtk_init (&argc, &argv);
#ifdef USE_XLIB
gdk_window_set_events (gdk_get_default_root_window (), GDK_PROPERTY_CHANGE_MASK);
gdk_window_add_filter (gdk_get_default_root_window (), (GdkFilterFunc)root_event_cb, NULL);
#endif
return -1;
}

View File

@ -804,10 +804,6 @@ key_dialog_show ()
gtk_box_pack_end (GTK_BOX (vbox), hbox2, 0, 0, 1);
wid = gtk_xtext_new (colors, 0);
gtk_xtext_set_tint (GTK_XTEXT (wid), prefs.hex_text_tint_red, prefs.hex_text_tint_green, prefs.hex_text_tint_blue);
gtk_xtext_set_background (GTK_XTEXT (wid),
channelwin_pix,
prefs.hex_text_transparent);
gtk_widget_set_usize (wid, 0, 75);
gtk_box_pack_start (GTK_BOX (hbox2), wid, 1, 1, 1);
gtk_xtext_set_font (GTK_XTEXT (wid), prefs.hex_text_font);

View File

@ -529,9 +529,6 @@ mg_configure_cb (GtkWidget *wid, GdkEventConfigure *event, session *sess)
gtk_window_get_size (GTK_WINDOW (wid), &prefs.hex_gui_dialog_width,
&prefs.hex_gui_dialog_height);
}
if (((GtkXText *) sess->gui->xtext)->transparent)
gtk_widget_queue_draw (sess->gui->xtext);
}
return FALSE;
@ -2333,8 +2330,7 @@ mg_update_xtext (GtkWidget *wid)
gtk_xtext_set_palette (xtext, colors);
gtk_xtext_set_max_lines (xtext, prefs.hex_text_max_lines);
gtk_xtext_set_tint (xtext, prefs.hex_text_tint_red, prefs.hex_text_tint_green, prefs.hex_text_tint_blue);
gtk_xtext_set_background (xtext, channelwin_pix, prefs.hex_text_transparent);
gtk_xtext_set_background (xtext, channelwin_pix);
gtk_xtext_set_wordwrap (xtext, prefs.hex_text_wordwrap);
gtk_xtext_set_show_marker (xtext, prefs.hex_text_show_marker);
gtk_xtext_set_show_separator (xtext, prefs.hex_text_indent ? prefs.hex_text_show_sep : 0);
@ -2345,23 +2341,7 @@ mg_update_xtext (GtkWidget *wid)
exit (1);
}
gtk_xtext_refresh (xtext, FALSE);
}
/* handle errors reported by xtext */
static void
mg_xtext_error (int type)
{
switch (type)
{
case 0:
fe_message (_("Unable to set transparent background!\n\n"
"You may be using a non-compliant window\n"
"manager that is not currently supported.\n"), FE_MSG_WARN);
prefs.hex_text_transparent = 0;
/* no others exist yet */
}
gtk_xtext_refresh (xtext);
}
static void
@ -2394,7 +2374,6 @@ mg_create_textarea (session *sess, GtkWidget *box)
xtext = GTK_XTEXT (gui->xtext);
gtk_xtext_set_max_indent (xtext, prefs.hex_text_max_indent);
gtk_xtext_set_thin_separator (xtext, prefs.hex_text_thin_sep);
gtk_xtext_set_error_function (xtext, mg_xtext_error);
gtk_xtext_set_urlcheck_function (xtext, mg_word_check);
gtk_xtext_set_max_lines (xtext, prefs.hex_text_max_lines);
gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (xtext));
@ -3207,6 +3186,7 @@ mg_create_topwindow (session *sess)
prefs.hex_gui_win_height, 0);
sess->gui->window = win;
gtk_container_set_border_width (GTK_CONTAINER (win), GUI_BORDER);
gtk_window_set_opacity (GTK_WINDOW (win), (prefs.hex_gui_transparency / 255.));
g_signal_connect (G_OBJECT (win), "focus_in_event",
G_CALLBACK (mg_topwin_focus_cb), sess);
@ -3311,6 +3291,7 @@ mg_create_tabwindow (session *sess)
gtk_window_maximize (GTK_WINDOW (win));
if (prefs.hex_gui_win_fullscreen)
gtk_window_fullscreen (GTK_WINDOW (win));
gtk_window_set_opacity (GTK_WINDOW (win), (prefs.hex_gui_transparency / 255.));
gtk_container_set_border_width (GTK_CONTAINER (win), GUI_BORDER);
g_signal_connect (G_OBJECT (win), "delete_event",

View File

@ -121,9 +121,6 @@ open_rawlog (struct server *serv)
gtk_widget_show (hbox);
serv->gui->rawlog_textlist = gtk_xtext_new (colors, 0);
gtk_xtext_set_tint (GTK_XTEXT (serv->gui->rawlog_textlist), prefs.hex_text_tint_red, prefs.hex_text_tint_green, prefs.hex_text_tint_blue);
gtk_xtext_set_background (GTK_XTEXT (serv->gui->rawlog_textlist),
channelwin_pix, prefs.hex_text_transparent);
gtk_container_add (GTK_CONTAINER (hbox), serv->gui->rawlog_textlist);
gtk_xtext_set_font (GTK_XTEXT (serv->gui->rawlog_textlist), prefs.hex_text_font);

View File

@ -159,19 +159,11 @@ static const setting appearance_settings[] =
{ST_HEADER, N_("Text Box"),0,0,0},
{ST_TOGGLE, N_("Colored nick names"), P_OFFINTNL(hex_text_color_nicks), N_("Give each person on IRC a different color"),0,0},
{ST_TOGGLR, N_("Indent nick names"), P_OFFINTNL(hex_text_indent), N_("Make nick names right-justified"),0,0},
#if defined(USE_XLIB) || defined(WIN32)
{ST_TOGGLE, N_("Transparent background"), P_OFFINTNL(hex_text_transparent),0,0,0},
{ST_TOGGLR, N_("Show marker line"), P_OFFINTNL(hex_text_show_marker), N_("Insert a red line after the last read text."),0,0},
{ST_EFILE, N_("Background image:"), P_OFFSETNL(hex_text_background), 0, 0, sizeof prefs.hex_text_background},
{ST_TOGGLE, N_ ("Show marker line"), P_OFFINTNL (hex_text_show_marker), N_ ("Insert a red line after the last read text."), 0, 0},
{ST_EFILE, N_ ("Background image:"), P_OFFSETNL (hex_text_background), 0, 0, sizeof prefs.hex_text_background},
{ST_HEADER, N_("Transparency Settings"), 0,0,0},
{ST_HSCALE, N_("Red:"), P_OFFINTNL(hex_text_tint_red),0,0,0},
{ST_HSCALE, N_("Green:"), P_OFFINTNL(hex_text_tint_green),0,0,0},
{ST_HSCALE, N_("Blue:"), P_OFFINTNL(hex_text_tint_blue),0,0,0},
#else
{ST_TOGGLE, N_("Show marker line"), P_OFFINTNL(hex_text_show_marker), N_("Insert a red line after the last read text."),0,0},
{ST_EFILE, N_("Background image:"), P_OFFSETNL(hex_text_background), 0, 0, sizeof prefs.hex_text_background},
#endif
{ST_HSCALE, N_("Window Opacity:"), P_OFFINTNL(hex_gui_transparency),0,0,0},
{ST_HEADER, N_("Time Stamps"),0,0,0},
{ST_TOGGLE, N_("Enable time stamps"), P_OFFINTNL(hex_stamp_text),0,0,1},
@ -839,12 +831,13 @@ setup_create_spin (GtkWidget *table, int row, const setting *set)
}
static gint
setup_apply_tint (int *tag)
setup_apply_trans (int *tag)
{
prefs.hex_text_tint_red = setup_prefs.hex_text_tint_red;
prefs.hex_text_tint_green = setup_prefs.hex_text_tint_green;
prefs.hex_text_tint_blue = setup_prefs.hex_text_tint_blue;
mg_update_xtext (current_sess->gui->xtext);
prefs.hex_gui_transparency = setup_prefs.hex_gui_transparency;
gtk_window_set_opacity (GTK_WINDOW (current_sess->gui->window),
(prefs.hex_gui_transparency / 255.));
/* mg_update_xtext (current_sess->gui->xtext); */
*tag = 0;
return 0;
}
@ -858,7 +851,7 @@ setup_hscale_cb (GtkHScale *wid, const setting *set)
if (tag == 0)
{
tag = g_idle_add ((GSourceFunc) setup_apply_tint, &tag);
tag = g_idle_add ((GSourceFunc) setup_apply_trans, &tag);
}
}
@ -879,6 +872,12 @@ setup_create_hscale (GtkWidget *table, int row, const setting *set)
G_CALLBACK (setup_hscale_cb), (gpointer)set);
gtk_table_attach (GTK_TABLE (table), wid, 3, 6, row, row + 1,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
#ifndef WIN32 /* Windows always supports this */
/* Only used for transparency currently */
if (!gtk_widget_is_composited (current_sess->gui->window))
gtk_widget_set_sensitive (wid, FALSE);
#endif
}

View File

@ -383,9 +383,6 @@ pevent_dialog_show ()
G_CALLBACK (pevent_dialog_select), store);
pevent_dialog_twid = gtk_xtext_new (colors, 0);
gtk_xtext_set_tint (GTK_XTEXT (pevent_dialog_twid), prefs.hex_text_tint_red, prefs.hex_text_tint_green, prefs.hex_text_tint_blue);
gtk_xtext_set_background (GTK_XTEXT (pevent_dialog_twid),
channelwin_pix, prefs.hex_text_transparent);
pevent_dialog_entry = gtk_entry_new_with_max_length (255);
g_signal_connect (G_OBJECT (pevent_dialog_entry), "activate",

View File

@ -21,9 +21,7 @@
*
*/
#define TINT_VALUE 195 /* 195/255 of the brightness. */
#define GDK_MULTIHEAD_SAFE
#define MARGIN 2 /* dont touch. */
#define REFRESH_TIMEOUT 20
#define WORDWRAP_LIMIT 24
@ -36,7 +34,7 @@
#ifdef WIN32
#include "../../config-win32.h"
#else
#include "../../config.h" /* can define USE_XLIB here */
#include "../../config.h"
#endif
#include "../common/hexchat.h"
@ -111,10 +109,6 @@ char *nocasestrstr (const char *text, const char *tofind); /* util.c */
int xtext_get_stamp_str (time_t, char **);
static void gtk_xtext_render_page (GtkXText * xtext);
static void gtk_xtext_calc_lines (xtext_buffer *buf, int);
#if defined(USE_XLIB) || defined(WIN32)
static void gtk_xtext_load_trans (GtkXText * xtext);
static void gtk_xtext_free_trans (GtkXText * xtext);
#endif
static char *gtk_xtext_selection_get_text (GtkXText *xtext, int *len_ret);
static textentry *gtk_xtext_nth (GtkXText *xtext, int line, int *subline);
static void gtk_xtext_adjustment_changed (GtkAdjustment * adj,
@ -162,50 +156,7 @@ gtk_xtext_text_width_8bit (GtkXText *xtext, unsigned char *str, int len)
return width;
}
#ifdef WIN32
static void
win32_draw_bg (GtkXText *xtext, int x, int y, int width, int height)
{
HDC hdc;
HWND hwnd;
HRGN rgn;
if (xtext->shaded)
{
/* xtext->pixmap is really a GdkImage, created in win32_tint() */
gdk_draw_image (xtext->draw_buf, xtext->bgc, (GdkImage*)xtext->pixmap,
x, y, x, y, width, height);
} else
{
hwnd = GDK_WINDOW_HWND (xtext->draw_buf);
hdc = GetDC (hwnd);
rgn = CreateRectRgn (x, y, x + width, y + height);
SelectClipRgn (hdc, rgn);
PaintDesktop (hdc);
ReleaseDC (hwnd, hdc);
DeleteObject (rgn);
}
}
static void
xtext_draw_bg (GtkXText *xtext, int x, int y, int width, int height)
{
if (xtext->transparent)
win32_draw_bg (xtext, x, y, width, height);
else
gdk_draw_rectangle (xtext->draw_buf, xtext->bgc, 1, x, y, width, height);
}
#else
#define xtext_draw_bg(xt,x,y,w,h) gdk_draw_rectangle(xt->draw_buf, xt->bgc, \
1,x,y,w,h);
#endif
#define xtext_draw_bg(xt,x,y,w,h) gdk_draw_rectangle(xt->draw_buf, xt->bgc, 1, x, y, w, h);
/* ======================================= */
/* ============ PANGO BACKEND ============ */
@ -363,21 +314,13 @@ backend_draw_text (GtkXText *xtext, int dofill, GdkGC *gc, int x, int y,
if (dofill)
{
#ifdef WIN32
if (xtext->transparent && !xtext->backcolor)
win32_draw_bg (xtext, x, y - xtext->font->ascent, str_width,
xtext->fontsize);
else
#endif
{
gdk_gc_get_values (gc, &val);
col.pixel = val.background.pixel;
gdk_gc_set_foreground (gc, &col);
gdk_draw_rectangle (xtext->draw_buf, gc, 1, x, y -
xtext->font->ascent, str_width, xtext->fontsize);
col.pixel = val.foreground.pixel;
gdk_gc_set_foreground (gc, &col);
}
gdk_gc_get_values (gc, &val);
col.pixel = val.background.pixel;
gdk_gc_set_foreground (gc, &col);
gdk_draw_rectangle (xtext->draw_buf, gc, 1, x, y -
xtext->font->ascent, str_width, xtext->fontsize);
col.pixel = val.foreground.pixel;
gdk_gc_set_foreground (gc, &col);
}
line = pango_layout_get_lines (xtext->layout)->data;
@ -453,7 +396,6 @@ gtk_xtext_init (GtkXText * xtext)
xtext->clip_x2 = 1000000;
xtext->clip_y = 0;
xtext->clip_y2 = 1000000;
xtext->error_function = NULL;
xtext->urlcheck_function = NULL;
xtext->color_paste = FALSE;
xtext->skip_border_fills = FALSE;
@ -464,7 +406,6 @@ gtk_xtext_init (GtkXText * xtext)
xtext->dont_render = FALSE;
xtext->dont_render2 = FALSE;
xtext->overdraw = FALSE;
xtext->tint_red = xtext->tint_green = xtext->tint_blue = TINT_VALUE;
xtext->adj = (GtkAdjustment *) gtk_adjustment_new (0, 0, 1, 1, 1, 1);
g_object_ref (G_OBJECT (xtext->adj));
@ -599,12 +540,7 @@ gtk_xtext_destroy (GtkObject * object)
if (xtext->pixmap)
{
#if defined(USE_XLIB) || defined(WIN32)
if (xtext->transparent)
gtk_xtext_free_trans (xtext);
else
#endif
g_object_unref (xtext->pixmap);
g_object_unref (xtext->pixmap);
xtext->pixmap = NULL;
}
@ -769,12 +705,6 @@ gtk_xtext_realize (GtkWidget * widget)
/* draw directly to window */
xtext->draw_buf = widget->window;
#if defined(USE_XLIB) || defined(WIN32)
if (xtext->transparent)
{
gtk_xtext_load_trans (xtext);
} else
#endif
if (xtext->pixmap)
{
gdk_gc_set_tile (xtext->bgc, xtext->pixmap);
@ -804,17 +734,10 @@ gtk_xtext_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
{
GtkXText *xtext = GTK_XTEXT (widget);
int height_only = FALSE;
int do_trans = TRUE;
if (allocation->width == xtext->buffer->window_width)
height_only = TRUE;
if (allocation->x == widget->allocation.x &&
allocation->y == widget->allocation.y && xtext->avoid_trans)
do_trans = FALSE;
xtext->avoid_trans = FALSE;
widget->allocation = *allocation;
if (GTK_WIDGET_REALIZED (widget))
{
@ -831,13 +754,6 @@ gtk_xtext_size_allocate (GtkWidget * widget, GtkAllocation * allocation)
xtext->buffer->pagetop_ent = NULL;
gtk_xtext_adjustment_set (xtext->buffer, FALSE);
}
#if defined(USE_XLIB) || defined(WIN32)
if (do_trans && xtext->transparent && xtext->shaded)
{
gtk_xtext_free_trans (xtext);
gtk_xtext_load_trans (xtext);
}
#endif
if (xtext->buffer->scrollbar_down)
gtk_adjustment_set_value (xtext->adj, xtext->adj->upper -
xtext->adj->page_size);
@ -1065,31 +981,6 @@ gtk_xtext_paint (GtkWidget *widget, GdkRectangle *area)
textentry *ent_start, *ent_end;
int x, y;
#if defined(USE_XLIB) || defined(WIN32)
if (xtext->transparent)
{
gdk_window_get_origin (widget->window, &x, &y);
/* update transparency only if it moved */
if (xtext->last_win_x != x || xtext->last_win_y != y)
{
xtext->last_win_x = x;
xtext->last_win_y = y;
#ifndef WIN32
if (xtext->shaded)
{
xtext->recycle = TRUE;
gtk_xtext_load_trans (xtext);
xtext->recycle = FALSE;
} else
#endif
{
gtk_xtext_free_trans (xtext);
gtk_xtext_load_trans (xtext);
}
}
}
#endif
if (area->x == 0 && area->y == 0 &&
area->height == widget->allocation.height &&
area->width == widget->allocation.width)
@ -2595,22 +2486,17 @@ gtk_xtext_render_flush (GtkXText * xtext, int x, int y, unsigned char *str,
goto dounder;
}
#ifdef WIN32
if (!xtext->transparent)
#endif
pix = gdk_pixmap_new (xtext->draw_buf, str_width, xtext->fontsize, xtext->depth);
if (pix)
{
pix = gdk_pixmap_new (xtext->draw_buf, str_width, xtext->fontsize, xtext->depth);
if (pix)
{
dest_x = x;
dest_y = y - xtext->font->ascent;
dest_x = x;
dest_y = y - xtext->font->ascent;
gdk_gc_set_ts_origin (xtext->bgc, xtext->ts_x - x, xtext->ts_y - dest_y);
gdk_gc_set_ts_origin (xtext->bgc, xtext->ts_x - x, xtext->ts_y - dest_y);
x = 0;
y = xtext->font->ascent;
xtext->draw_buf = pix;
}
x = 0;
y = xtext->font->ascent;
xtext->draw_buf = pix;
}
dofill = TRUE;
@ -3149,500 +3035,6 @@ gtk_xtext_render_str (GtkXText * xtext, int y, textentry * ent,
return ret;
}
#ifdef USE_XLIB
/* get the desktop/root window */
static Window desktop_window = None;
static Window
get_desktop_window (Display *xdisplay, Window the_window)
{
Atom prop, type;
int format;
unsigned long length, after;
unsigned char *data;
unsigned int nchildren;
Window w, root, *children, parent;
prop = XInternAtom (xdisplay, "_XROOTPMAP_ID", True);
if (prop == None)
{
prop = XInternAtom (xdisplay, "_XROOTCOLOR_PIXEL", True);
if (prop == None)
return None;
}
for (w = the_window; w; w = parent)
{
if ((XQueryTree (xdisplay, w, &root, &parent, &children,
&nchildren)) == False)
return None;
if (nchildren)
XFree (children);
XGetWindowProperty (xdisplay, w, prop, 0L, 1L, False,
AnyPropertyType, &type, &format, &length, &after,
&data);
if (data)
XFree (data);
if (type != None)
return (desktop_window = w);
}
return (desktop_window = None);
}
/* find the root window (backdrop) Pixmap */
static Pixmap
get_pixmap_prop (Display *xdisplay, Window the_window)
{
Atom type;
int format;
unsigned long length, after;
unsigned char *data;
Pixmap pix = None;
static Atom prop = None;
if (desktop_window == None)
desktop_window = get_desktop_window (xdisplay, the_window);
if (desktop_window == None)
desktop_window = DefaultRootWindow (xdisplay);
if (prop == None)
prop = XInternAtom (xdisplay, "_XROOTPMAP_ID", True);
if (prop == None)
return None;
XGetWindowProperty (xdisplay, desktop_window, prop, 0L, 1L, False,
AnyPropertyType, &type, &format, &length, &after,
&data);
if (data)
{
if (type == XA_PIXMAP)
pix = *((Pixmap *) data);
XFree (data);
}
return pix;
}
/* slow generic routine, for the depths/bpp we don't know about */
static void
shade_ximage_generic (GdkVisual *visual, XImage *ximg, int bpl, int w, int h, int rm, int gm, int bm, int bg)
{
int x, y;
int bgr = (256 - rm) * (bg & visual->red_mask);
int bgg = (256 - gm) * (bg & visual->green_mask);
int bgb = (256 - bm) * (bg & visual->blue_mask);
for (x = 0; x < w; x++)
{
for (y = 0; y < h; y++)
{
unsigned long pixel = XGetPixel (ximg, x, y);
int r, g, b;
r = rm * (pixel & visual->red_mask) + bgr;
g = gm * (pixel & visual->green_mask) + bgg;
b = bm * (pixel & visual->blue_mask) + bgb;
XPutPixel (ximg, x, y,
((r >> 8) & visual->red_mask) |
((g >> 8) & visual->green_mask) |
((b >> 8) & visual->blue_mask));
}
}
}
#endif
/* Fast shading routine. Based on code by Willem Monsuwe <willem@stack.nl> */
#define SHADE_IMAGE(bytes, type, rmask, gmask, bmask) \
unsigned char *ptr; \
int x, y; \
int bgr = (256 - rm) * (bg & rmask); \
int bgg = (256 - gm) * (bg & gmask); \
int bgb = (256 - bm) * (bg & bmask); \
ptr = (unsigned char *) data + (w * bytes); \
for (y = h; --y >= 0;) \
{ \
for (x = -w; x < 0; x++) \
{ \
int r, g, b; \
b = ((type *) ptr)[x]; \
r = rm * (b & rmask) + bgr; \
g = gm * (b & gmask) + bgg; \
b = bm * (b & bmask) + bgb; \
((type *) ptr)[x] = ((r >> 8) & rmask) \
| ((g >> 8) & gmask) \
| ((b >> 8) & bmask); \
} \
ptr += bpl; \
}
/* RGB 15 */
static void
shade_ximage_15 (void *data, int bpl, int w, int h, int rm, int gm, int bm, int bg)
{
SHADE_IMAGE (2, guint16, 0x7c00, 0x3e0, 0x1f);
}
/* RGB 16 */
static void
shade_ximage_16 (void *data, int bpl, int w, int h, int rm, int gm, int bm, int bg)
{
SHADE_IMAGE (2, guint16, 0xf800, 0x7e0, 0x1f);
}
/* RGB 24 */
static void
shade_ximage_24 (void *data, int bpl, int w, int h, int rm, int gm, int bm, int bg)
{
/* 24 has to be a special case, there's no guint24, or 24bit MOV :) */
unsigned char *ptr;
int x, y;
int bgr = (256 - rm) * ((bg & 0xff0000) >> 16);
int bgg = (256 - gm) * ((bg & 0xff00) >> 8);
int bgb = (256 - bm) * (bg & 0xff);
ptr = (unsigned char *) data + (w * 3);
for (y = h; --y >= 0;)
{
for (x = -(w * 3); x < 0; x += 3)
{
int r, g, b;
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
r = (ptr[x + 0] * rm + bgr) >> 8;
g = (ptr[x + 1] * gm + bgg) >> 8;
b = (ptr[x + 2] * bm + bgb) >> 8;
ptr[x + 0] = r;
ptr[x + 1] = g;
ptr[x + 2] = b;
#else
r = (ptr[x + 2] * rm + bgr) >> 8;
g = (ptr[x + 1] * gm + bgg) >> 8;
b = (ptr[x + 0] * bm + bgb) >> 8;
ptr[x + 2] = r;
ptr[x + 1] = g;
ptr[x + 0] = b;
#endif
}
ptr += bpl;
}
}
/* RGB 32 */
static void
shade_ximage_32 (void *data, int bpl, int w, int h, int rm, int gm, int bm, int bg)
{
SHADE_IMAGE (4, guint32, 0xff0000, 0xff00, 0xff);
}
static void
shade_image (GdkVisual *visual, void *data, int bpl, int bpp, int w, int h,
int rm, int gm, int bm, int bg, int depth)
{
switch (depth)
{
case 15:
shade_ximage_15 (data, bpl, w, h, rm, gm, bm, bg);
break;
case 16:
shade_ximage_16 (data, bpl, w, h, rm, gm, bm, bg);
break;
case 24:
if (bpp != 32)
{
shade_ximage_24 (data, bpl, w, h, rm, gm, bm, bg);
break;
}
case 32:
shade_ximage_32 (data, bpl, w, h, rm, gm, bm, bg);
}
}
#ifdef USE_XLIB
static GdkPixmap *
shade_pixmap (GtkXText * xtext, Pixmap p, int x, int y, int w, int h)
{
unsigned int dummy, width, height, depth;
GdkPixmap *shaded_pix;
Window root;
Pixmap tmp;
XImage *ximg;
XGCValues gcv;
GC tgc;
Display *xdisplay = GDK_WINDOW_XDISPLAY (xtext->draw_buf);
XGetGeometry (xdisplay, p, &root, &dummy, &dummy, &width, &height,
&dummy, &depth);
if (width < x + w || height < y + h || x < 0 || y < 0)
{
gcv.subwindow_mode = IncludeInferiors;
gcv.graphics_exposures = False;
tgc = XCreateGC (xdisplay, p, GCGraphicsExposures|GCSubwindowMode,
&gcv);
tmp = XCreatePixmap (xdisplay, p, w, h, depth);
XSetTile (xdisplay, tgc, p);
XSetFillStyle (xdisplay, tgc, FillTiled);
XSetTSOrigin (xdisplay, tgc, -x, -y);
XFillRectangle (xdisplay, tmp, tgc, 0, 0, w, h);
XFreeGC (xdisplay, tgc);
ximg = XGetImage (xdisplay, tmp, 0, 0, w, h, -1, ZPixmap);
XFreePixmap (xdisplay, tmp);
} else
{
ximg = XGetImage (xdisplay, p, x, y, w, h, -1, ZPixmap);
}
if (!ximg)
return NULL;
if (depth <= 14)
{
shade_ximage_generic (gdk_drawable_get_visual (GTK_WIDGET (xtext)->window),
ximg, ximg->bytes_per_line, w, h, xtext->tint_red,
xtext->tint_green, xtext->tint_blue,
xtext->palette[XTEXT_BG]);
} else
{
shade_image (gdk_drawable_get_visual (GTK_WIDGET (xtext)->window),
ximg->data, ximg->bytes_per_line, ximg->bits_per_pixel,
w, h, xtext->tint_red, xtext->tint_green, xtext->tint_blue,
xtext->palette[XTEXT_BG], depth);
}
if (xtext->recycle)
shaded_pix = xtext->pixmap;
else
{
{
shaded_pix = gdk_pixmap_new (GTK_WIDGET (xtext)->window, w, h, depth);
}
}
XPutImage (xdisplay, GDK_WINDOW_XWINDOW (shaded_pix),
GDK_GC_XGC (xtext->fgc), ximg, 0, 0, 0, 0, w, h);
XDestroyImage (ximg);
return shaded_pix;
}
#endif /* !USE_XLIB */
/* free transparency xtext->pixmap */
#if defined(USE_XLIB) || defined(WIN32)
static void
gtk_xtext_free_trans (GtkXText * xtext)
{
if (xtext->pixmap)
{
g_object_unref (xtext->pixmap);
xtext->pixmap = NULL;
}
}
#endif
#ifdef WIN32
static GdkPixmap *
win32_tint (GtkXText *xtext, GdkImage *img, int width, int height)
{
guchar *pixelp;
int x, y;
GdkPixmap *pix;
GdkVisual *visual = gdk_drawable_get_visual (GTK_WIDGET (xtext)->window);
guint32 pixel;
int r, g, b;
if (img->depth <= 14)
{
/* slow generic routine */
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
if (img->depth == 1)
{
pixel = (((guchar *) img->mem)[y * img->bpl + (x >> 3)] & (1 << (7 - (x & 0x7)))) != 0;
goto here;
}
if (img->depth == 4)
{
pixelp = (guchar *) img->mem + y * img->bpl + (x >> 1);
if (x&1)
{
pixel = (*pixelp) & 0x0F;
goto here;
}
pixel = (*pixelp) >> 4;
goto here;
}
pixelp = (guchar *) img->mem + y * img->bpl + x * img->bpp;
switch (img->bpp)
{
case 1:
pixel = *pixelp; break;
/* Windows is always LSB, no need to check img->byte_order. */
case 2:
pixel = pixelp[0] | (pixelp[1] << 8); break;
case 3:
pixel = pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16); break;
case 4:
pixel = pixelp[0] | (pixelp[1] << 8) | (pixelp[2] << 16); break;
}
here:
r = (pixel & visual->red_mask) >> visual->red_shift;
g = (pixel & visual->green_mask) >> visual->green_shift;
b = (pixel & visual->blue_mask) >> visual->blue_shift;
/* actual tinting is only these 3 lines */
pixel = ((r * xtext->tint_red) >> 8) << visual->red_shift |
((g * xtext->tint_green) >> 8) << visual->green_shift |
((b * xtext->tint_blue) >> 8) << visual->blue_shift;
if (img->depth == 1)
if (pixel & 1)
((guchar *) img->mem)[y * img->bpl + (x >> 3)] |= (1 << (7 - (x & 0x7)));
else
((guchar *) img->mem)[y * img->bpl + (x >> 3)] &= ~(1 << (7 - (x & 0x7)));
else if (img->depth == 4)
{
pixelp = (guchar *) img->mem + y * img->bpl + (x >> 1);
if (x&1)
{
*pixelp &= 0xF0;
*pixelp |= (pixel & 0x0F);
} else
{
*pixelp &= 0x0F;
*pixelp |= (pixel << 4);
}
} else
{
pixelp = (guchar *) img->mem + y * img->bpl + x * img->bpp;
/* Windows is always LSB, no need to check img->byte_order. */
switch (img->bpp)
{
case 4:
pixelp[3] = 0;
case 3:
pixelp[2] = ((pixel >> 16) & 0xFF);
case 2:
pixelp[1] = ((pixel >> 8) & 0xFF);
case 1:
pixelp[0] = (pixel & 0xFF);
}
}
}
}
} else
{
shade_image (visual, img->mem, img->bpl, img->bpp, width, height,
xtext->tint_red, xtext->tint_green, xtext->tint_blue,
xtext->palette[XTEXT_BG], visual->depth);
}
/* no need to dump it to a Pixmap, it's one and the same on win32 */
pix = (GdkPixmap *)img;
return pix;
}
#endif /* !WIN32 */
/* grab pixmap from root window and set xtext->pixmap */
#if defined(USE_XLIB) || defined(WIN32)
static void
gtk_xtext_load_trans (GtkXText * xtext)
{
#ifdef WIN32
GdkImage *img;
int width, height;
HDC hdc;
HWND hwnd;
/* if not shaded, we paint directly with PaintDesktop() */
if (!xtext->shaded)
return;
hwnd = GDK_WINDOW_HWND (GTK_WIDGET (xtext)->window);
hdc = GetDC (hwnd);
PaintDesktop (hdc);
ReleaseDC (hwnd, hdc);
gdk_drawable_get_size (GTK_WIDGET (xtext)->window, &width, &height);
img = gdk_drawable_get_image (GTK_WIDGET (xtext)->window, 0, 0, width+128, height);
xtext->pixmap = win32_tint (xtext, img, img->width, img->height);
#else
Pixmap rootpix;
GtkWidget *widget = GTK_WIDGET (xtext);
int x, y;
rootpix = get_pixmap_prop (GDK_WINDOW_XDISPLAY (widget->window), GDK_WINDOW_XWINDOW (widget->window));
if (rootpix == None)
{
if (xtext->error_function)
xtext->error_function (0);
xtext->transparent = FALSE;
return;
}
gdk_window_get_origin (widget->window, &x, &y);
if (xtext->shaded)
{
int width, height;
gdk_drawable_get_size (GTK_WIDGET (xtext)->window, &width, &height);
xtext->pixmap = shade_pixmap (xtext, rootpix, x, y, width+105, height);
if (xtext->pixmap == NULL)
{
xtext->shaded = 0;
goto noshade;
}
gdk_gc_set_tile (xtext->bgc, xtext->pixmap);
gdk_gc_set_ts_origin (xtext->bgc, 0, 0);
xtext->ts_x = xtext->ts_y = 0;
} else
{
noshade:
xtext->pixmap = gdk_pixmap_foreign_new_for_display (gdk_drawable_get_display (GTK_WIDGET (xtext)->window), rootpix);
gdk_gc_set_tile (xtext->bgc, xtext->pixmap);
gdk_gc_set_ts_origin (xtext->bgc, -x, -y);
xtext->ts_x = -x;
xtext->ts_y = -y;
}
gdk_gc_set_fill (xtext->bgc, GDK_TILED);
#endif /* !WIN32 */
}
#endif /* ! XLIB || WIN32 */
/* walk through str until this line doesn't fit anymore */
static int
@ -4060,42 +3452,16 @@ gtk_xtext_set_font (GtkXText *xtext, char *name)
}
void
gtk_xtext_set_background (GtkXText * xtext, GdkPixmap * pixmap, gboolean trans)
gtk_xtext_set_background (GtkXText * xtext, GdkPixmap * pixmap)
{
GdkGCValues val;
gboolean shaded = FALSE;
if (trans && (xtext->tint_red != 255 || xtext->tint_green != 255 || xtext->tint_blue != 255))
shaded = TRUE;
#if !defined(USE_XLIB) && !defined(WIN32)
shaded = FALSE;
trans = FALSE;
#endif
if (xtext->pixmap)
{
#if defined(USE_XLIB) || defined(WIN32)
if (xtext->transparent)
gtk_xtext_free_trans (xtext);
else
#endif
g_object_unref (xtext->pixmap);
g_object_unref (xtext->pixmap);
xtext->pixmap = NULL;
}
xtext->transparent = trans;
#if defined(USE_XLIB) || defined(WIN32)
if (trans)
{
xtext->shaded = shaded;
if (GTK_WIDGET_REALIZED (xtext))
gtk_xtext_load_trans (xtext);
return;
}
#endif
dontscroll (xtext->buffer);
xtext->pixmap = pixmap;
@ -4390,11 +3756,7 @@ gtk_xtext_render_page (GtkXText * xtext)
overlap = xtext->buffer->last_pixel_pos - pos;
xtext->buffer->last_pixel_pos = pos;
#ifdef WIN32
if (!xtext->transparent && !xtext->pixmap && abs (overlap) < height)
#else
if (!xtext->pixmap && abs (overlap) < height)
#endif
if (abs (overlap) < height)
{
/* so the obscured regions are exposed */
gdk_gc_set_exposures (xtext->fgc, TRUE);
@ -4454,17 +3816,10 @@ gtk_xtext_render_page (GtkXText * xtext)
}
void
gtk_xtext_refresh (GtkXText * xtext, int do_trans)
gtk_xtext_refresh (GtkXText * xtext)
{
if (GTK_WIDGET_REALIZED (GTK_WIDGET (xtext)))
{
#if defined(USE_XLIB) || defined(WIN32)
if (xtext->transparent && do_trans)
{
gtk_xtext_free_trans (xtext);
gtk_xtext_load_trans (xtext);
}
#endif
gtk_xtext_render_page (xtext);
}
}
@ -4638,7 +3993,7 @@ gtk_xtext_clear (xtext_buffer *buf, int lines)
if (buf->xtext->buffer == buf)
{
gtk_xtext_calc_lines (buf, TRUE);
gtk_xtext_refresh (buf->xtext, 0);
gtk_xtext_refresh (buf->xtext);
} else
{
gtk_xtext_calc_lines (buf, FALSE);
@ -5361,12 +4716,6 @@ gtk_xtext_foreach (xtext_buffer *buf, GtkXTextForeach func, void *data)
}
}
void
gtk_xtext_set_error_function (GtkXText *xtext, void (*error_function) (int))
{
xtext->error_function = error_function;
}
void
gtk_xtext_set_indent (GtkXText *xtext, gboolean indent)
{
@ -5409,17 +4758,6 @@ gtk_xtext_set_time_stamp (xtext_buffer *buf, gboolean time_stamp)
buf->time_stamp = time_stamp;
}
void
gtk_xtext_set_tint (GtkXText *xtext, int tint_red, int tint_green, int tint_blue)
{
xtext->tint_red = tint_red;
xtext->tint_green = tint_green;
xtext->tint_blue = tint_blue;
/*if (xtext->tint_red != 255 || xtext->tint_green != 255 || xtext->tint_blue != 255)
shaded = TRUE;*/
}
void
gtk_xtext_set_urlcheck_function (GtkXText *xtext, int (*urlcheck_function) (GtkWidget *, char *))
{
@ -5512,10 +4850,6 @@ gtk_xtext_buffer_show (GtkXText *xtext, xtext_buffer *buf, int render)
gtk_xtext_render_page (xtext);
gtk_adjustment_changed (xtext->adj);
} else
{
/* avoid redoing the transparency */
xtext->avoid_trans = TRUE;
}
}

View File

@ -135,10 +135,6 @@ struct _GtkXText
int last_win_h;
int last_win_w;
int tint_red;
int tint_green;
int tint_blue;
GdkGC *bgc; /* backing pixmap */
GdkGC *fgc; /* text foreground color */
GdkGC *light_gc; /* sep bar */
@ -190,7 +186,6 @@ struct _GtkXText
unsigned char scratch_buffer[4096];
void (*error_function) (int type);
int (*urlcheck_function) (GtkWidget * xtext, char *word);
int jump_out_offset; /* point at which to stop rendering */
@ -233,15 +228,12 @@ struct _GtkXText
unsigned int in_hilight:1;
unsigned int un_hilight:1;
unsigned int recycle:1;
unsigned int avoid_trans:1;
unsigned int force_render:1;
unsigned int color_paste:1; /* CTRL was pressed when selection finished */
/* settings/prefs */
unsigned int auto_indent:1;
unsigned int thinline:1;
unsigned int transparent:1;
unsigned int shaded:1;
unsigned int marker:1;
unsigned int separator:1;
unsigned int wordwrap:1;
@ -262,11 +254,11 @@ void gtk_xtext_append_indent (xtext_buffer *buf,
unsigned char *right_text, int right_len,
time_t stamp);
int gtk_xtext_set_font (GtkXText *xtext, char *name);
void gtk_xtext_set_background (GtkXText * xtext, GdkPixmap * pixmap, gboolean trans);
void gtk_xtext_set_background (GtkXText * xtext, GdkPixmap * pixmap);
void gtk_xtext_set_palette (GtkXText * xtext, GdkColor palette[]);
void gtk_xtext_clear (xtext_buffer *buf, int lines);
void gtk_xtext_save (GtkXText * xtext, int fh);
void gtk_xtext_refresh (GtkXText * xtext, int do_trans);
void gtk_xtext_refresh (GtkXText * xtext);
int gtk_xtext_lastlog (xtext_buffer *out, xtext_buffer *search_area);
textentry *gtk_xtext_search (GtkXText * xtext, const gchar *text, gtk_xtext_search_flags flags, GError **err);
void gtk_xtext_reset_marker_pos (GtkXText *xtext);
@ -284,7 +276,6 @@ void gtk_xtext_set_show_marker (GtkXText *xtext, gboolean show_marker);
void gtk_xtext_set_show_separator (GtkXText *xtext, gboolean show_separator);
void gtk_xtext_set_thin_separator (GtkXText *xtext, gboolean thin_separator);
void gtk_xtext_set_time_stamp (xtext_buffer *buf, gboolean timestamp);
void gtk_xtext_set_tint (GtkXText *xtext, int tint_red, int tint_green, int tint_blue);
void gtk_xtext_set_urlcheck_function (GtkXText *xtext, int (*urlcheck_function) (GtkWidget *, char *));
void gtk_xtext_set_wordwrap (GtkXText *xtext, gboolean word_wrap);