From ee80cb07525b16057864f5133ed15010e33a4168 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B6rn=20Lindqvist?= Date: Fri, 17 Jun 2016 16:35:15 +0200 Subject: [PATCH] ui.backend.gtk: use a global variable to store the icon data It's easier than the previous code that replaced the get-icon-data word during deployment. Also GTK support for icon.ico icons. --- .../tools/deploy/shaker/strip-gtk-icon.factor | 11 +----- basis/ui/backend/gtk/gtk-docs.factor | 6 ++- basis/ui/backend/gtk/gtk-tests.factor | 8 +++- basis/ui/backend/gtk/gtk.factor | 39 ++++++++++++------- core/vocabs/loader/loader-docs.factor | 7 ++-- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/basis/tools/deploy/shaker/strip-gtk-icon.factor b/basis/tools/deploy/shaker/strip-gtk-icon.factor index e444d9a390..23c9b32a5a 100644 --- a/basis/tools/deploy/shaker/strip-gtk-icon.factor +++ b/basis/tools/deploy/shaker/strip-gtk-icon.factor @@ -1,13 +1,6 @@ ! Copyright (C) 2010 Philipp Brüschweiler ! See http://factorcode.org/license.txt for BSD license. -USING: kernel tools.deploy.shaker literals namespaces -vocabs.loader io.pathnames io.files io.encodings.binary ; +USING: namespaces tools.deploy.shaker ; IN: ui.backend.gtk -CONSTANT: get-icon-data - $[ - deploy-vocab get - dup vocab-dir "icon.png" append-path vocab-append-path - [ exists? ] keep "resource:misc/icons/Factor_128x128.png" ? - binary file-contents - ] +deploy-vocab get vocab-icon-data icon-data set-global diff --git a/basis/ui/backend/gtk/gtk-docs.factor b/basis/ui/backend/gtk/gtk-docs.factor index de069ee1e3..958259b686 100644 --- a/basis/ui/backend/gtk/gtk-docs.factor +++ b/basis/ui/backend/gtk/gtk-docs.factor @@ -1,4 +1,5 @@ -USING: alien gdk.ffi gtk.ffi help.markup help.syntax kernel ; +USING: alien byte-arrays gdk.ffi gtk.ffi help.markup help.syntax +kernel ; IN: ui.backend.gtk HELP: configure-im @@ -6,6 +7,9 @@ HELP: configure-im { $description "Configures the input methods of the window. Must only be run after the window has been realized." } { $see-also gtk_widget_realize } ; +HELP: icon-data +{ $var-description "Contains a " { $link byte-array } " or " { $link f } " which is the data for the icon to be used for gtk windows. The variable is updated to contain a vocab-specific icon when deploying. See " { $link "vocabs.icons" } " and 'tools.deploy.shaker.strip-gtk-icon'." } ; + HELP: on-configure { $values { "win" alien } diff --git a/basis/ui/backend/gtk/gtk-tests.factor b/basis/ui/backend/gtk/gtk-tests.factor index 69ea1806da..a3a285a477 100644 --- a/basis/ui/backend/gtk/gtk-tests.factor +++ b/basis/ui/backend/gtk/gtk-tests.factor @@ -1,5 +1,5 @@ -USING: alien.syntax classes.struct gdk.ffi kernel system tools.test -ui.backend.gtk ui.gestures ; +USING: alien.syntax classes.struct gdk.ffi kernel sequences system +tools.test ui.backend.gtk ui.gestures ; IN: ui.backend.gtk.tests : gdk-key-release-event ( -- event ) @@ -59,3 +59,7 @@ os linux? [ gdk-space-key-press-event key-event>gesture ] unit-test ] when + +{ 9854 } [ + "gpu.demos.bunny" vocab-icon-data length +] unit-test diff --git a/basis/ui/backend/gtk/gtk.factor b/basis/ui/backend/gtk/gtk.factor index f693893e3f..e1616b5f34 100644 --- a/basis/ui/backend/gtk/gtk.factor +++ b/basis/ui/backend/gtk/gtk.factor @@ -1,16 +1,15 @@ ! Copyright (C) 2010, 2011 Anton Gorenko, Philipp Bruschweiler. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.accessors alien.c-types alien.data -alien.strings arrays assocs classes.struct combinators -continuations destructors environment gdk.ffi gdk.gl.ffi -gdk.pixbuf.ffi glib.ffi gobject-introspection.standard-types -gobject.ffi gtk.ffi gtk.gl.ffi io.encodings.binary -io.encodings.utf8 io.files kernel libc literals locals math -math.bitwise math.vectors namespaces sequences strings system -threads ui ui.backend ui.backend.gtk.input-methods -ui.backend.gtk.io ui.clipboards ui.event-loop ui.gadgets -ui.gadgets.private ui.gadgets.worlds ui.gestures -ui.pixel-formats ui.pixel-formats.private ui.private +alien.strings arrays assocs classes.struct combinators continuations +destructors environment gdk.ffi gdk.gl.ffi gdk.pixbuf.ffi glib.ffi +gobject-introspection.standard-types gobject.ffi gtk.ffi gtk.gl.ffi +io.encodings.binary io.encodings.utf8 io.files io.pathnames kernel +libc literals locals math math.bitwise math.vectors namespaces +sequences strings system threads ui ui.backend +ui.backend.gtk.input-methods ui.backend.gtk.io ui.clipboards +ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds +ui.gestures ui.pixel-formats ui.pixel-formats.private ui.private vocabs.loader ; IN: ui.backend.gtk @@ -215,15 +214,25 @@ CONSTANT: action-key-codes : on-focus-out ( win event user-data -- ? ) 2drop window unfocus-world t ; -! This word gets replaced when deploying. See 'Vocabulary icons' -! in the docs and tools.deploy.shaker.gtk-icon -: get-icon-data ( -- byte-array/f ) +CONSTANT: default-icon-path "resource:misc/icons/Factor_128x128.png" + +: default-icon-data ( -- byte-array/f ) [ - "resource:misc/icons/Factor_128x128.png" binary file-contents + default-icon-path binary file-contents ] [ drop f ] recover ; +SYMBOL: icon-data + +icon-data [ default-icon-data ] initialize + +: vocab-icon-data ( vocab-name -- byte-array ) + dup vocab-dir { "icon.png" "icon.ico" } [ + append-path vocab-append-path + ] 2with map default-icon-path suffix + [ exists? ] find nip binary file-contents ; + : load-icon ( -- ) - get-icon-data [ + icon-data get [ [ data>GInputStream &g_object_unref GInputStream>GdkPixbuf gtk_window_set_default_icon diff --git a/core/vocabs/loader/loader-docs.factor b/core/vocabs/loader/loader-docs.factor index b1f1796e14..6d8bad2536 100755 --- a/core/vocabs/loader/loader-docs.factor +++ b/core/vocabs/loader/loader-docs.factor @@ -30,10 +30,11 @@ ARTICLE: "vocabs.roots" "Vocabulary roots" ARTICLE: "vocabs.icons" "Vocabulary icons" "An icon file representing the vocabulary can be provided for use by " { $link "tools.deploy" } ". If any of the following files exist inside the vocabulary directory, they will be used as icons when the application is deployed." { $list - { { $snippet "icon.ico" } " on Windows" } + { { $snippet "icon.ico" } " on Windows and Linux" } { { $snippet "icon.icns" } " on MacOS X" } - { { $snippet "icon.png" } " on Linux and *BSD" } -} ; + { { $snippet "icon.png" } " on Linux" } +} +"The icon file will be embedded in the vocab's image file." ; ARTICLE: "vocabs.loader" "Vocabulary loader" "The " { $link POSTPONE: USE: } " and " { $link POSTPONE: USING: } " words load vocabularies using the vocabulary loader. The vocabulary loader is implemented in the " { $vocab-link "vocabs.loader" } " vocabulary." -- 2.34.1