167
204
gtk_statusbar_push(GTK_STATUSBAR(fe->statusbar), fe->statusctx, text);
170
void gtk_start_draw(void *handle)
172
frontend *fe = (frontend *)handle;
207
/* ----------------------------------------------------------------------
208
* Cairo drawing functions.
213
static void setup_drawing(frontend *fe)
215
fe->cr = cairo_create(fe->image);
216
cairo_set_antialias(fe->cr, CAIRO_ANTIALIAS_GRAY);
217
cairo_set_line_width(fe->cr, 1.0);
218
cairo_set_line_cap(fe->cr, CAIRO_LINE_CAP_SQUARE);
219
cairo_set_line_join(fe->cr, CAIRO_LINE_JOIN_ROUND);
222
static void teardown_drawing(frontend *fe)
226
cairo_destroy(fe->cr);
229
cr = gdk_cairo_create(fe->pixmap);
230
cairo_set_source_surface(cr, fe->image, 0, 0);
234
fe->bbox_r - fe->bbox_l + 2,
235
fe->bbox_d - fe->bbox_u + 2);
240
static void snaffle_colours(frontend *fe)
242
fe->colours = midend_colours(fe->me, &fe->ncolours);
245
static void set_colour(frontend *fe, int colour)
247
cairo_set_source_rgb(fe->cr,
248
fe->colours[3*colour + 0],
249
fe->colours[3*colour + 1],
250
fe->colours[3*colour + 2]);
253
static void set_window_background(frontend *fe, int colour)
257
colmap = gdk_colormap_get_system();
258
fe->background.red = fe->colours[3*colour + 0] * 65535;
259
fe->background.green = fe->colours[3*colour + 1] * 65535;
260
fe->background.blue = fe->colours[3*colour + 2] * 65535;
261
if (!gdk_colormap_alloc_color(colmap, &fe->background, FALSE, FALSE)) {
262
g_error("couldn't allocate background (#%02x%02x%02x)\n",
263
fe->background.red >> 8, fe->background.green >> 8,
264
fe->background.blue >> 8);
266
gdk_window_set_background(fe->area->window, &fe->background);
267
gdk_window_set_background(fe->window->window, &fe->background);
270
static PangoLayout *make_pango_layout(frontend *fe)
272
return (pango_cairo_create_layout(fe->cr));
275
static void draw_pango_layout(frontend *fe, PangoLayout *layout,
278
cairo_move_to(fe->cr, x, y);
279
pango_cairo_show_layout(fe->cr, layout);
282
static void save_screenshot_png(frontend *fe, const char *screenshot_file)
284
cairo_surface_write_to_png(fe->image, screenshot_file);
287
static void do_clip(frontend *fe, int x, int y, int w, int h)
289
cairo_new_path(fe->cr);
290
cairo_rectangle(fe->cr, x, y, w, h);
294
static void do_unclip(frontend *fe)
296
cairo_reset_clip(fe->cr);
299
static void do_draw_rect(frontend *fe, int x, int y, int w, int h)
302
cairo_new_path(fe->cr);
303
cairo_set_antialias(fe->cr, CAIRO_ANTIALIAS_NONE);
304
cairo_rectangle(fe->cr, x, y, w, h);
306
cairo_restore(fe->cr);
309
static void do_draw_line(frontend *fe, int x1, int y1, int x2, int y2)
311
cairo_new_path(fe->cr);
312
cairo_move_to(fe->cr, x1 + 0.5, y1 + 0.5);
313
cairo_line_to(fe->cr, x2 + 0.5, y2 + 0.5);
314
cairo_stroke(fe->cr);
317
static void do_draw_thick_line(frontend *fe, float thickness,
318
float x1, float y1, float x2, float y2)
321
cairo_set_line_width(fe->cr, thickness);
322
cairo_new_path(fe->cr);
323
cairo_move_to(fe->cr, x1, y1);
324
cairo_line_to(fe->cr, x2, y2);
325
cairo_stroke(fe->cr);
326
cairo_restore(fe->cr);
329
static void do_draw_poly(frontend *fe, int *coords, int npoints,
330
int fillcolour, int outlinecolour)
334
cairo_new_path(fe->cr);
335
for (i = 0; i < npoints; i++)
336
cairo_line_to(fe->cr, coords[i*2] + 0.5, coords[i*2 + 1] + 0.5);
337
cairo_close_path(fe->cr);
338
if (fillcolour >= 0) {
339
set_colour(fe, fillcolour);
340
cairo_fill_preserve(fe->cr);
342
assert(outlinecolour >= 0);
343
set_colour(fe, outlinecolour);
344
cairo_stroke(fe->cr);
347
static void do_draw_circle(frontend *fe, int cx, int cy, int radius,
348
int fillcolour, int outlinecolour)
350
cairo_new_path(fe->cr);
351
cairo_arc(fe->cr, cx + 0.5, cy + 0.5, radius, 0, 2*PI);
352
cairo_close_path(fe->cr); /* Just in case... */
353
if (fillcolour >= 0) {
354
set_colour(fe, fillcolour);
355
cairo_fill_preserve(fe->cr);
357
assert(outlinecolour >= 0);
358
set_colour(fe, outlinecolour);
359
cairo_stroke(fe->cr);
362
static void setup_blitter(blitter *bl, int w, int h)
364
bl->image = cairo_image_surface_create(CAIRO_FORMAT_RGB24, w, h);
367
static void teardown_blitter(blitter *bl)
369
cairo_surface_destroy(bl->image);
372
static void do_blitter_save(frontend *fe, blitter *bl, int x, int y)
374
cairo_t *cr = cairo_create(bl->image);
376
cairo_set_source_surface(cr, fe->image, -x, -y);
381
static void do_blitter_load(frontend *fe, blitter *bl, int x, int y)
383
cairo_set_source_surface(fe->cr, bl->image, x, y);
387
static void clear_backing_store(frontend *fe)
392
static void setup_backing_store(frontend *fe)
397
fe->pixmap = gdk_pixmap_new(fe->area->window, fe->pw, fe->ph, -1);
398
fe->image = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
401
for (i = 0; i < 3; i++) {
403
case 0: cr = cairo_create(fe->image); break;
404
case 1: cr = gdk_cairo_create(fe->pixmap); break;
405
case 2: cr = gdk_cairo_create(fe->area->window); break;
407
cairo_set_source_rgb(cr,
408
fe->colours[0], fe->colours[1], fe->colours[2]);
414
static int backing_store_ok(frontend *fe)
416
return (!!fe->image);
419
static void teardown_backing_store(frontend *fe)
421
cairo_surface_destroy(fe->image);
422
gdk_pixmap_unref(fe->pixmap);
428
/* ----------------------------------------------------------------------
429
* GDK drawing functions.
434
static void setup_drawing(frontend *fe)
173
436
fe->gc = gdk_gc_new(fe->area->window);
180
void gtk_clip(void *handle, int x, int y, int w, int h)
182
frontend *fe = (frontend *)handle;
439
static void teardown_drawing(frontend *fe)
441
gdk_gc_unref(fe->gc);
445
static void snaffle_colours(frontend *fe)
451
fe->colmap = gdk_colormap_get_system();
452
colours = midend_colours(fe->me, &ncolours);
453
fe->ncolours = ncolours;
454
fe->colours = snewn(ncolours, GdkColor);
455
for (i = 0; i < ncolours; i++) {
456
fe->colours[i].red = colours[i*3] * 0xFFFF;
457
fe->colours[i].green = colours[i*3+1] * 0xFFFF;
458
fe->colours[i].blue = colours[i*3+2] * 0xFFFF;
460
success = snewn(ncolours, gboolean);
461
gdk_colormap_alloc_colors(fe->colmap, fe->colours, ncolours,
462
FALSE, FALSE, success);
463
for (i = 0; i < ncolours; i++) {
465
g_error("couldn't allocate colour %d (#%02x%02x%02x)\n",
466
i, fe->colours[i].red >> 8,
467
fe->colours[i].green >> 8,
468
fe->colours[i].blue >> 8);
473
static void set_window_background(frontend *fe, int colour)
475
fe->backgroundindex = colour;
476
gdk_window_set_background(fe->area->window, &fe->colours[colour]);
477
gdk_window_set_background(fe->window->window, &fe->colours[colour]);
480
static void set_colour(frontend *fe, int colour)
482
gdk_gc_set_foreground(fe->gc, &fe->colours[colour]);
486
static PangoLayout *make_pango_layout(frontend *fe)
488
return (pango_layout_new(gtk_widget_get_pango_context(fe->area)));
491
static void draw_pango_layout(frontend *fe, PangoLayout *layout,
494
gdk_draw_layout(fe->pixmap, fe->gc, x, y, layout);
498
static void save_screenshot_png(frontend *fe, const char *screenshot_file)
501
GError *gerror = NULL;
503
midend_redraw(fe->me);
505
pb = gdk_pixbuf_get_from_drawable(NULL, fe->pixmap,
506
NULL, 0, 0, 0, 0, -1, -1);
507
gdk_pixbuf_save(pb, screenshot_file, "png", &gerror, NULL);
510
static void do_clip(frontend *fe, int x, int y, int w, int h)
183
512
GdkRectangle rect;
190
518
gdk_gc_set_clip_rectangle(fe->gc, &rect);
193
void gtk_unclip(void *handle)
521
static void do_unclip(frontend *fe)
195
frontend *fe = (frontend *)handle;
196
523
GdkRectangle rect;
200
527
rect.width = fe->w;
201
528
rect.height = fe->h;
203
529
gdk_gc_set_clip_rectangle(fe->gc, &rect);
206
void gtk_draw_text(void *handle, int x, int y, int fonttype, int fontsize,
207
int align, int colour, char *text)
209
frontend *fe = (frontend *)handle;
213
* Find or create the font.
215
for (i = 0; i < fe->nfonts; i++)
216
if (fe->fonts[i].type == fonttype && fe->fonts[i].size == fontsize)
219
if (i == fe->nfonts) {
220
if (fe->fontsize <= fe->nfonts) {
221
fe->fontsize = fe->nfonts + 10;
222
fe->fonts = sresize(fe->fonts, fe->fontsize, struct font);
227
fe->fonts[i].type = fonttype;
228
fe->fonts[i].size = fontsize;
232
* Use Pango to find the closest match to the requested
236
PangoFontDescription *fd;
238
fd = pango_font_description_new();
239
/* `Monospace' and `Sans' are meta-families guaranteed to exist */
240
pango_font_description_set_family(fd, fonttype == FONT_FIXED ?
241
"Monospace" : "Sans");
242
pango_font_description_set_weight(fd, PANGO_WEIGHT_BOLD);
244
* I found some online Pango documentation which
245
* described a function called
246
* pango_font_description_set_absolute_size(), which is
247
* _exactly_ what I want here. Unfortunately, none of
248
* my local Pango installations have it (presumably
249
* they're too old), so I'm going to have to hack round
250
* it by figuring out the point size myself. This
251
* limits me to X and probably also breaks in later
252
* Pango installations, so ideally I should add another
253
* CHECK_VERSION type ifdef and use set_absolute_size
254
* where available. All very annoying.
256
#ifdef HAVE_SENSIBLE_ABSOLUTE_SIZE_FUNCTION
257
pango_font_description_set_absolute_size(fd, PANGO_SCALE*fontsize);
260
Display *d = GDK_DISPLAY();
261
int s = DefaultScreen(d);
263
(PANGO_SCALE * 72.27 / 25.4) *
264
((double) DisplayWidthMM(d, s) / DisplayWidth (d, s));
265
pango_font_description_set_size(fd, resolution * fontsize);
268
fe->fonts[i].desc = fd;
273
* In GTK 1.2, I don't know of any plausible way to
274
* pick a suitable font, so I'm just going to be
277
fe->fonts[i].font = gdk_font_load(fonttype == FONT_FIXED ?
278
"fixed" : "variable");
286
gdk_gc_set_foreground(fe->gc, &fe->colours[colour]);
297
layout = pango_layout_new(gtk_widget_get_pango_context(fe->area));
298
pango_layout_set_font_description(layout, fe->fonts[i].desc);
299
pango_layout_set_text(layout, text, strlen(text));
300
pango_layout_get_pixel_extents(layout, NULL, &rect);
302
if (align & ALIGN_VCENTRE)
303
rect.y -= rect.height / 2;
305
rect.y -= rect.height;
307
if (align & ALIGN_HCENTRE)
308
rect.x -= rect.width / 2;
309
else if (align & ALIGN_HRIGHT)
310
rect.x -= rect.width;
312
gdk_draw_layout(fe->pixmap, fe->gc, rect.x + x, rect.y + y, layout);
314
g_object_unref(layout);
319
* Find string dimensions and process alignment.
322
int lb, rb, wid, asc, desc;
325
* Measure vertical string extents with respect to the same
328
gdk_string_extents(fe->fonts[i].font,
329
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
330
&lb, &rb, &wid, &asc, &desc);
331
if (align & ALIGN_VCENTRE)
332
y += asc - (asc+desc)/2;
337
* ... but horizontal extents with respect to the provided
338
* string. This means that multiple pieces of text centred
339
* on the same y-coordinate don't have different baselines.
341
gdk_string_extents(fe->fonts[i].font, text,
342
&lb, &rb, &wid, &asc, &desc);
344
if (align & ALIGN_HCENTRE)
346
else if (align & ALIGN_HRIGHT)
352
* Actually draw the text.
354
gdk_draw_string(fe->pixmap, fe->fonts[i].font, fe->gc, x, y, text);
359
void gtk_draw_rect(void *handle, int x, int y, int w, int h, int colour)
361
frontend *fe = (frontend *)handle;
362
gdk_gc_set_foreground(fe->gc, &fe->colours[colour]);
532
static void do_draw_rect(frontend *fe, int x, int y, int w, int h)
363
534
gdk_draw_rectangle(fe->pixmap, fe->gc, 1, x, y, w, h);
366
void gtk_draw_line(void *handle, int x1, int y1, int x2, int y2, int colour)
368
frontend *fe = (frontend *)handle;
369
gdk_gc_set_foreground(fe->gc, &fe->colours[colour]);
370
gdk_draw_line(fe->pixmap, fe->gc, x1, y1, x2, y2);
373
void gtk_draw_poly(void *handle, int *coords, int npoints,
374
int fillcolour, int outlinecolour)
376
frontend *fe = (frontend *)handle;
537
static void do_draw_line(frontend *fe, int x1, int y1, int x2, int y2)
539
gdk_draw_line(fe->pixmap, fe->gc, x1, y1, x2, y2);
542
static void do_draw_thick_line(frontend *fe, float thickness,
543
float x1, float y1, float x2, float y2)
547
gdk_gc_get_values(fe->gc, &save);
548
gdk_gc_set_line_attributes(fe->gc,
553
gdk_draw_line(fe->pixmap, fe->gc, x1, y1, x2, y2);
554
gdk_gc_set_line_attributes(fe->gc,
561
static void do_draw_poly(frontend *fe, int *coords, int npoints,
562
int fillcolour, int outlinecolour)
377
564
GdkPoint *points = snewn(npoints, GdkPoint);
406
void gtk_draw_circle(void *handle, int cx, int cy, int radius,
407
int fillcolour, int outlinecolour)
593
static void do_draw_circle(frontend *fe, int cx, int cy, int radius,
594
int fillcolour, int outlinecolour)
409
frontend *fe = (frontend *)handle;
410
596
if (fillcolour >= 0) {
411
gdk_gc_set_foreground(fe->gc, &fe->colours[fillcolour]);
597
set_colour(fe, fillcolour);
412
598
gdk_draw_arc(fe->pixmap, fe->gc, TRUE,
413
599
cx - radius, cy - radius,
414
600
2 * radius, 2 * radius, 0, 360 * 64);
417
603
assert(outlinecolour >= 0);
418
gdk_gc_set_foreground(fe->gc, &fe->colours[outlinecolour]);
604
set_colour(fe, outlinecolour);
419
605
gdk_draw_arc(fe->pixmap, fe->gc, FALSE,
420
606
cx - radius, cy - radius,
421
607
2 * radius, 2 * radius, 0, 360 * 64);
429
blitter *gtk_blitter_new(void *handle, int w, int h)
610
static void setup_blitter(blitter *bl, int w, int h)
432
613
* We can't create the pixmap right now, because fe->window
433
614
* might not yet exist. So we just cache w and h and create it
434
615
* during the firs call to blitter_save.
620
static void teardown_blitter(blitter *bl)
623
gdk_pixmap_unref(bl->pixmap);
626
static void do_blitter_save(frontend *fe, blitter *bl, int x, int y)
629
bl->pixmap = gdk_pixmap_new(fe->area->window, bl->w, bl->h, -1);
630
gdk_draw_pixmap(bl->pixmap,
631
fe->area->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
633
x, y, 0, 0, bl->w, bl->h);
636
static void do_blitter_load(frontend *fe, blitter *bl, int x, int y)
639
gdk_draw_pixmap(fe->pixmap,
640
fe->area->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
642
0, 0, x, y, bl->w, bl->h);
645
static void clear_backing_store(frontend *fe)
650
static void setup_backing_store(frontend *fe)
654
fe->pixmap = gdk_pixmap_new(fe->area->window, fe->pw, fe->ph, -1);
656
gc = gdk_gc_new(fe->area->window);
657
gdk_gc_set_foreground(gc, &fe->colours[0]);
658
gdk_draw_rectangle(fe->pixmap, gc, 1, 0, 0, fe->pw, fe->ph);
659
gdk_draw_rectangle(fe->area->window, gc, 1, 0, 0, fe->w, fe->h);
663
static int backing_store_ok(frontend *fe)
665
return (!!fe->pixmap);
668
static void teardown_backing_store(frontend *fe)
670
gdk_pixmap_unref(fe->pixmap);
676
static void repaint_rectangle(frontend *fe, GtkWidget *widget,
677
int x, int y, int w, int h)
679
GdkGC *gc = gdk_gc_new(widget->window);
681
gdk_gc_set_foreground(gc, &fe->background);
683
gdk_gc_set_foreground(gc, &fe->colours[fe->backgroundindex]);
686
gdk_draw_rectangle(widget->window, gc,
687
TRUE, x, y, fe->ox - x, h);
692
gdk_draw_rectangle(widget->window, gc,
693
TRUE, x, y, w, fe->oy - y);
698
gdk_draw_rectangle(widget->window, gc,
699
TRUE, x + fe->pw, y, w - fe->pw, h);
703
gdk_draw_rectangle(widget->window, gc,
704
TRUE, x, y + fe->ph, w, h - fe->ph);
707
gdk_draw_pixmap(widget->window, gc, fe->pixmap,
708
x - fe->ox, y - fe->oy, x, y, w, h);
712
/* ----------------------------------------------------------------------
713
* Pango font functions.
718
static void add_font(frontend *fe, int index, int fonttype, int fontsize)
721
* Use Pango to find the closest match to the requested
724
PangoFontDescription *fd;
726
fd = pango_font_description_new();
727
/* `Monospace' and `Sans' are meta-families guaranteed to exist */
728
pango_font_description_set_family(fd, fonttype == FONT_FIXED ?
729
"Monospace" : "Sans");
730
pango_font_description_set_weight(fd, PANGO_WEIGHT_BOLD);
732
* I found some online Pango documentation which
733
* described a function called
734
* pango_font_description_set_absolute_size(), which is
735
* _exactly_ what I want here. Unfortunately, none of
736
* my local Pango installations have it (presumably
737
* they're too old), so I'm going to have to hack round
738
* it by figuring out the point size myself. This
739
* limits me to X and probably also breaks in later
740
* Pango installations, so ideally I should add another
741
* CHECK_VERSION type ifdef and use set_absolute_size
742
* where available. All very annoying.
744
#ifdef HAVE_SENSIBLE_ABSOLUTE_SIZE_FUNCTION
745
pango_font_description_set_absolute_size(fd, PANGO_SCALE*fontsize);
748
Display *d = GDK_DISPLAY();
749
int s = DefaultScreen(d);
751
(PANGO_SCALE * 72.27 / 25.4) *
752
((double) DisplayWidthMM(d, s) / DisplayWidth (d, s));
753
pango_font_description_set_size(fd, resolution * fontsize);
756
fe->fonts[index].desc = fd;
759
static void align_and_draw_text(frontend *fe,
760
int index, int align, int x, int y,
766
layout = make_pango_layout(fe);
771
pango_layout_set_font_description(layout, fe->fonts[index].desc);
772
pango_layout_set_text(layout, text, strlen(text));
773
pango_layout_get_pixel_extents(layout, NULL, &rect);
775
if (align & ALIGN_VCENTRE)
776
rect.y -= rect.height / 2;
778
rect.y -= rect.height;
780
if (align & ALIGN_HCENTRE)
781
rect.x -= rect.width / 2;
782
else if (align & ALIGN_HRIGHT)
783
rect.x -= rect.width;
785
draw_pango_layout(fe, layout, rect.x + x, rect.y + y);
787
g_object_unref(layout);
792
/* ----------------------------------------------------------------------
793
* Old-fashioned font functions.
798
static void add_font(int index, int fonttype, int fontsize)
801
* In GTK 1.2, I don't know of any plausible way to
802
* pick a suitable font, so I'm just going to be
805
fe->fonts[i].font = gdk_font_load(fonttype == FONT_FIXED ?
806
"fixed" : "variable");
809
static void align_and_draw_text(int index, int align, int x, int y,
812
int lb, rb, wid, asc, desc;
815
* Measure vertical string extents with respect to the same
818
gdk_string_extents(fe->fonts[i].font,
819
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
820
&lb, &rb, &wid, &asc, &desc);
821
if (align & ALIGN_VCENTRE)
822
y += asc - (asc+desc)/2;
827
* ... but horizontal extents with respect to the provided
828
* string. This means that multiple pieces of text centred
829
* on the same y-coordinate don't have different baselines.
831
gdk_string_extents(fe->fonts[i].font, text,
832
&lb, &rb, &wid, &asc, &desc);
834
if (align & ALIGN_HCENTRE)
836
else if (align & ALIGN_HRIGHT)
840
* Actually draw the text.
842
gdk_draw_string(fe->pixmap, fe->fonts[i].font, fe->gc, x, y, text);
847
/* ----------------------------------------------------------------------
848
* The exported drawing functions.
851
void gtk_start_draw(void *handle)
853
frontend *fe = (frontend *)handle;
861
void gtk_clip(void *handle, int x, int y, int w, int h)
863
frontend *fe = (frontend *)handle;
864
do_clip(fe, x, y, w, h);
867
void gtk_unclip(void *handle)
869
frontend *fe = (frontend *)handle;
873
void gtk_draw_text(void *handle, int x, int y, int fonttype, int fontsize,
874
int align, int colour, char *text)
876
frontend *fe = (frontend *)handle;
880
* Find or create the font.
882
for (i = 0; i < fe->nfonts; i++)
883
if (fe->fonts[i].type == fonttype && fe->fonts[i].size == fontsize)
886
if (i == fe->nfonts) {
887
if (fe->fontsize <= fe->nfonts) {
888
fe->fontsize = fe->nfonts + 10;
889
fe->fonts = sresize(fe->fonts, fe->fontsize, struct font);
894
fe->fonts[i].type = fonttype;
895
fe->fonts[i].size = fontsize;
896
add_font(fe, i, fonttype, fontsize);
902
set_colour(fe, colour);
903
align_and_draw_text(fe, i, align, x, y, text);
906
void gtk_draw_rect(void *handle, int x, int y, int w, int h, int colour)
908
frontend *fe = (frontend *)handle;
909
set_colour(fe, colour);
910
do_draw_rect(fe, x, y, w, h);
913
void gtk_draw_line(void *handle, int x1, int y1, int x2, int y2, int colour)
915
frontend *fe = (frontend *)handle;
916
set_colour(fe, colour);
917
do_draw_line(fe, x1, y1, x2, y2);
920
void gtk_draw_thick_line(void *handle, float thickness,
921
float x1, float y1, float x2, float y2, int colour)
923
frontend *fe = (frontend *)handle;
924
set_colour(fe, colour);
925
do_draw_thick_line(fe, thickness, x1, y1, x2, y2);
928
void gtk_draw_poly(void *handle, int *coords, int npoints,
929
int fillcolour, int outlinecolour)
931
frontend *fe = (frontend *)handle;
932
do_draw_poly(fe, coords, npoints, fillcolour, outlinecolour);
935
void gtk_draw_circle(void *handle, int cx, int cy, int radius,
936
int fillcolour, int outlinecolour)
938
frontend *fe = (frontend *)handle;
939
do_draw_circle(fe, cx, cy, radius, fillcolour, outlinecolour);
942
blitter *gtk_blitter_new(void *handle, int w, int h)
436
944
blitter *bl = snew(blitter);
945
setup_blitter(bl, w, h);
1224
1714
GdkAtom compound_text_atom, utf8_string_atom;
1225
1715
int paste_initialised = FALSE;
1229
unsigned char empty[] = { 0 };
1231
if (paste_initialised)
1234
if (!compound_text_atom)
1235
compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
1236
if (!utf8_string_atom)
1237
utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
1240
* Ensure that all the cut buffers exist - according to the
1241
* ICCCM, we must do this before we start using cut buffers.
1243
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1244
XA_CUT_BUFFER0, XA_STRING, 8, PropModeAppend, empty, 0);
1245
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1246
XA_CUT_BUFFER1, XA_STRING, 8, PropModeAppend, empty, 0);
1247
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1248
XA_CUT_BUFFER2, XA_STRING, 8, PropModeAppend, empty, 0);
1249
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1250
XA_CUT_BUFFER3, XA_STRING, 8, PropModeAppend, empty, 0);
1251
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1252
XA_CUT_BUFFER4, XA_STRING, 8, PropModeAppend, empty, 0);
1253
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1254
XA_CUT_BUFFER5, XA_STRING, 8, PropModeAppend, empty, 0);
1255
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1256
XA_CUT_BUFFER6, XA_STRING, 8, PropModeAppend, empty, 0);
1257
XChangeProperty(GDK_DISPLAY(), GDK_ROOT_WINDOW(),
1258
XA_CUT_BUFFER7, XA_STRING, 8, PropModeAppend, empty, 0);
1261
/* Store data in a cut-buffer. */
1262
void store_cutbuffer(char *ptr, int len)
1264
/* ICCCM says we must rotate the buffers before storing to buffer 0. */
1265
XRotateBuffers(GDK_DISPLAY(), 1);
1266
XStoreBytes(GDK_DISPLAY(), ptr, len);
1269
void write_clip(frontend *fe, char *data)
1274
sfree(fe->paste_data);
1717
static void set_selection(frontend *fe, GdkAtom selection)
1719
if (!paste_initialised) {
1720
compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);
1721
utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);
1722
paste_initialised = TRUE;
1277
1726
* For this simple application we can safely assume that the