From: slebetman@yahoo.com on
Uwe Klein wrote:
> exactement!
>
> very nice,
> the "-topmost" option to [wm attributes] breaks on X11.

Sorry about that. It will also break on Macs. Should have done a
platform check but this was a quick and dirty hack.

> everything being indented at least one space sugests
> you have already put it on the wiki?
>

No, it's not on the wiki yet. It's just how I format my code for usenet
(just a single step in my editor: replace all \t with two spaces). I'll
put it up later. To closer meet the OP's original requirement add this:

array set foo {
h {} m {} s {}
H 0 M 0 S 0
}

proc tick {} {
global foo
after 1000 tick
set now [clock seconds]
set now [clock format $now -format "%I.%M.%S"]
foreach {H M S} [split $now .] break

# The code can indeed be simpler than this
# but the simple version flickers too much
# for my tastes. All this voodoo is merely
# to reduce flicker:
if {$H != $foo(H)} {
set foo(H) $H
foreach x $foo(h) {destroy $x}
set foo(h) [drawTransNumber .trans 10 10 $H]
}
if {$M != $foo(M)} {
set foo(M) $M
foreach x $foo(m) {destroy $x}
set foo(m) [drawTransNumber .trans 240 10 $M]
}
if {$S != $foo(S)} {
set foo(S) $S
foreach x $foo(s) {destroy $x}
set foo(s) [drawTransNumber .trans 470 10 $S]
}
}
tick

# To allow us to easily kill this beast:
pack [button .exit -command exit -text Exit]

From: walton.paul on
That is awesome. I haven´t tried it out yet though; I still need to
figure out how to compile twapi first. I think this will be a very
powerful feature though. This should enable us to easily make shaped
windows, windows with holes in them, and desktop widgets like this
transparent clock. Excellent!


palmtcl(a)yahoo.com wrote:
> Following Jeff's pointer below, I added an interface to
> SetLayeredWindowAttributes to TWAPI. Sample code to do what you want is
> below. Note you need TWAPI 1.1, currently only in CVS, as 1.0 does not
> have the SetLayeredWindowAttributes call (or you could use FFIDL to do
> the same thing without needing all of TWAPI)
>
> Working code - this works on my sample of one (XP SP2). Note to drag
> the clock around you have to click the mouse on an opaque area.
>
> package require Tk
> package require twapi 1.1
>
> proc every { ms body } {
> eval $body
> after $ms [list every $ms $body]
>
> }
>
> proc dragStart {windowX windowY} {
> set ::DragHoldPosition(x) $windowX
> set ::DragHoldPosition(y) $windowY
>
> }
>
> proc dragTo {screenX screenY} {
> set positionX [expr { $screenX - $::DragHoldPosition(x) }]
> set positionY [expr { $screenY - $::DragHoldPosition(y) }]
> wm geometry . [winfo width .]x[winfo height .]+$positionX+$positionY
>
> }
>
> bind . <Button-1> { dragStart %x %y }
> bind . <Button1-Motion> { dragTo %X %Y }
> bind . <Button-2> { destroy . }
>
> pack [label .lab -textvariable timevar -font "ansi 54 bold" -foreground
> \#aa66ff -background red]
> every 500 {set ::timevar [clock format [clock sec] -format %H:%M:%S]}
>
> wm overrideredirect . 1
> wm attributes . -topmost 1
>
> # For some reason, we cannot change style bits until window is
> visible/mapped
> update idletasks
>
> # Get the parent of the Tk toplevel - this is the real toplevel from
> # the Windows perspective
> set top_id [twapi::get_parent_window [winfo id .]]
> # Set its style bits to allow layering
> foreach {style exstyle} [twapi::get_window_style $top_id] break
> twapi::set_window_style $top_id $style [expr {0x80000+$exstyle}]
> # Set transparency color (red is 0x0000ff as per Windows COLORREF
> struct
> ::twapi::SetLayeredWindowAttributes $top_id 0xff 255 1
>
>
> /Ashok
>
> Jeff Hobbs wrote:
> >
> > Look for how SetLayeredWindowAttributes is called in tk/win/tkWinWm.c.
> > Instead of LWA_ALPHA, if you use LWA_COLORKEY and specify an RGB color
> > that should be transparent, then you could do essentially what you want.
> > Combine it with a wm overrideredirect window, making it white where
> > white is the transparent color, anything you draw on that will be all
> > that you should see. More info at:
> Jeff Hobbs, The Tcl Guy, http://www.activestate.com/

From: Jeff Hobbs on
walton.paul(a)gmail.com wrote:
> That is awesome. I haven�t tried it out yet though; I still need to
> figure out how to compile twapi first. I think this will be a very
> powerful feature though. This should enable us to easily make shaped
> windows, windows with holes in them, and desktop widgets like this
> transparent clock. Excellent!

You will also find this in 8.5 as
wm attributes $win -transparentcolor ?color?
for Windows. It doesn't appear that X11 or Aqua have this feature, so
don't expect to see it anywhere else.

--

Jeff Hobbs, The Tcl Guy, http://www.activestate.com/
From: Daniel A. Steffen on
Jeff,

Jeff Hobbs wrote:
> You will also find this in 8.5 as
> wm attributes $win -transparentcolor ?color?
> for Windows. It doesn't appear that X11 or Aqua have this feature, so
> don't expect to see it anywhere else.

While Aqua does not have exactly this feature, of course CG has full
RGBA support, so it is perfecly possible to have a fully transparent
window without titlebar (i.e. an overrideredirect filled with a fully
transparent color) and then draw some more or less transparent content
drawn onto it.
However, integrating the CG model fully with Tk would require support
for alpha in Tk throughout (and probably factoring out of many of the
"erase before drawing" assumptions from X11), not exactly a short term
project ;-)

Cheers,

Daniel