restore window

Linux specific forum
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

restore window

Post by GBeebe »

How do I (with code) restore a window after hiding it by clicking the show desktop button?
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Re: restore window

Post by remi_meier »

Code: Select all

*win.GtkWidget = WindowID(0)
gdk_window_show_(*win\window)
gdk_window_raise_(*win\window)
greetz
remi
Athlon64 3700+, 1024MB Ram, Radeon X1600
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: restore window

Post by ts-soft »

does SetWindowState(#Window, #PB_Window_Normal) not work?
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

Re: restore window

Post by GBeebe »

@remi_meier, does that work for you? It kinda' does here, but I have to unminimize another window by hand and then my window will show up. Perhaps there's a way to ignore being minimized all the time. What I'm doing is writing a little app that sticks to the desktop (gdk_window_set_keep_below_) and doesn't have a taskbar entry (gdk_window_set_skip_taskbar_hint_). I would like it not to disappear at all, but thought I could atleast make it come back on its own.

@ts-soft, not in this situation, it doesn't.
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Re: restore window

Post by remi_meier »

This seems to work perfectly here:

Code: Select all

OpenWindow(0,300, 300, 300, 300, "test", #PB_Window_Normal|#PB_Window_MinimizeGadget)

*win.GtkWidget = WindowID(0)
gdk_window_set_keep_below_(*win\window, #True)
gdk_window_set_skip_taskbar_hint_(*win\window, #True)

Repeat
  event = WaitWindowEvent()
  
  If event = #PB_Event_MinimizeWindow
    *win.GtkWidget = WindowID(0)
    gdk_window_show_(*win\window)
    gdk_window_raise_(*win\window)
    Debug "now"
  EndIf
  
Until event = #PB_Event_CloseWindow
I have Compiz with Metacity running on Ubuntu 9.10 here.
Could it be that you don't process the events correctly? You
could try to add a gdk_flush_().
Athlon64 3700+, 1024MB Ram, Radeon X1600
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

Re: restore window

Post by GBeebe »

That still has the problem, here, where my window only becomes visible after another window becomes visible. The line: Debug "now" makes it appear to work the first time because it brings up the debug window. If I close it and try again, it doesn't come back until I open another window.

This is what I've been working on, be sure to change the first line to pint to a valid image:

Code: Select all

#gui_PB_Icon = "/media/virtbox/programs/purebasic/logo.png"

UseJPEGImageDecoder()
UseJPEG2000ImageDecoder()
UsePNGImageDecoder()

Global Main_Window
Global img_bg
Global gimg_mainview

Procedure ImgDraw(srcImage, dstImage, x, y, width = -1, height = -1, clearcolor = -1)
; Draw image with a transparent colour
;Protected dw, dh, w, h, *tmp, a, b, c.l 
Protected dw, dh, dw0, dh0, w, h, sw0, sh0, *tmp, a, b, c.l
StartDrawing(ImageOutput(srcImage))
If OutputDepth() = 32
    b32 =1
    DrawingMode( #PB_2DDrawing_AlphaBlend)
EndIf

If width = -1
    w = OutputWidth() 
Else
    w = width
EndIf
If height = -1    
    h = OutputHeight() 
Else
    h = height
EndIf   

*tmp = AllocateMemory(w*h*4) ; Temporary memory for source image data
; Loop through the image to collect data
For a = 0 To w-1
  For b = 0 To h-1
    If a > -1 And b > -1
        c = Point(a, b) ; Get the color
        PokeL(*tmp + (b*w+a)*4, c)    ; Save the color
    EndIf    
   
  Next
Next
StopDrawing()
; Draw the temporary image data on the destination
StartDrawing(ImageOutput(dstImage))
;If OutputDepth = 32
If b32
    DrawingMode( #PB_2DDrawing_AlphaBlend)
EndIf
;EndIf

For a = 0 To w-1
    For b = 0 To h-1
        If a + x > -1 And b + y > -1 And a + x < OutputWidth() And b + y < OutputHeight()
            c = PeekL(*tmp + (b*w+a)*4)    
            If Not (b32 = 0 And c = clearcolor)
                Plot(a + x, b + y, c)
            EndIf
        EndIf    
    Next
Next
StopDrawing()
FreeMemory(*tmp) ; Clean up
EndProcedure

Procedure NewBox()
If Not IsWindow(Main_Window) 
;712
    Main_Window = OpenWindow(#PB_Any, 700, 200, 48, 48, "bLauncher - PureBasic", #PB_Window_BorderLess)
    
    Gimg_MainView = ImageGadget(#PB_Any, 0, 0, 48, 48, 0)
    
EndIf
EndProcedure

*screen = gdk_screen_get_default_()
h =gdk_screen_get_height_(*screen)
w =gdk_screen_get_width_(*screen)

image.s = ""
option.s = ""
bgcolor.s = ""
backcolor = 0
img_root = 0

infile = OpenFile(#PB_Any,  GetHomeDirectory() + ".gconf/desktop/gnome/background/%gconf.xml")
If infile
    Repeat
        in.s = LTrim(RTrim(ReadString(infile), " "), " ")
            If FindString(LCase(in.s), "primary_color", 0)
                Repeat  
                    bg.s = LTrim(RTrim(ReadString(infile), " "), " ")
                    bg.s = RemoveString(bg.s, "<stringvalue>", #PB_String_NoCase)
                    bg.s = RemoveString(bg.s, "</stringvalue>", #PB_String_NoCase)
                    bg.s = RemoveString(LTrim(RTrim(bg.s, " "), " "), "#")
                Until bg.s <> "" Or Eof(infile)
                BackColor = Val("$" + Mid(bg.s, 1, 2) + Mid(bg.s, 5, 2) + Mid(bg.s, 9, 2))
                If Red(BackColor) <> Val("$" + Mid(bg.s, 1, 2)) ;Endian fix
                    BackColor = RGB(Blue(BackColor), Green(BackColor), Red(BackColor))
                EndIf    
            EndIf
            If FindString(LCase(in.s), "picture_filename", 0)
                Repeat  
                    image.s = LTrim(RTrim(ReadString(infile), " "), " ")
                    image.s = RemoveString(image.s, "<stringvalue>", #PB_String_NoCase)
                    image.s = RemoveString(image.s, "</stringvalue>", #PB_String_NoCase)
                    image.s = LTrim(RTrim(image.s, " "), " ")
                Until image.s <> "" Or Eof(infile)
            EndIf
            If FindString(LCase(in.s), "picture_options", 0)    
                Repeat  
                    option.s = LTrim(RTrim(ReadString(infile), " "), " ")
                    option.s = RemoveString(option.s, "<stringvalue>", #PB_String_NoCase)
                    option.s = RemoveString(option.s, "</stringvalue>", #PB_String_NoCase)
                    option.s = LTrim(RTrim(UCase(option.s), " "), " ")
                Until option.s <> "" Or Eof(infile)
            EndIf
    Until Eof(infile)
EndIf   

 img_root = CreateImage(#PB_Any, w, h)
    StartDrawing(ImageOutput(img_root))
        FillArea(1, 1, -1, BackColor)
    StopDrawing()   

If image.s <> ""
    tmp = LoadImage(#PB_Any, image.s)
    Select option.s
        Case "ZOOM"
            ;get a ratio.
            wr.f = w/ImageWidth(tmp)
            hr.f = h/ImageHeight(tmp)
            ;Debug wr
            ;Debug hr
            If wr > hr
                ResizeImage(tmp, w, ImageHeight(tmp) * wr)
            ElseIf wr < hr
                ResizeImage(tmp, ImageWidth(tmp) * hr, h)
            Else
                ResizeImage(tmp, w, h)
            EndIf
    EndSelect
    
    ImgDraw(tmp, img_root, (w/2) - (ImageWidth(tmp) / 2), (h/2) - (ImageHeight(tmp) / 2))
    
EndIf
    


NewBox()

*x = AllocateMemory(SizeOf(Integer))
*y = AllocateMemory(SizeOf(Integer))
*Widget.GtkWidget = WindowID(Main_Window)
*GdkWindow = *Widget\Window
gtk_window_set_skip_taskbar_hint_(*Widget, #True)
gtk_window_set_skip_pager_hint_(*Widget, #True)
gtk_window_stick_(*Widget)  ;makes this window appear on all desktops.
gdk_window_set_type_hint_(*GdkWindow, #GDK_WINDOW_TYPE_HINT_DESKTOP)
gdk_window_set_keep_above_(*GdkWindow, 1)
;gdk_window_set_keep_below_(*GdkWindow, 1)
gdk_window_get_origin_(*GdkWindow, *x, *y)

i = LoadImage(#PB_Any, #gui_PB_Icon) ;Purebasic logo
bglg = GrabImage(img_root, #PB_Any, PeekL(*x), PeekL(*y), 48, 48)  ;background large icon
ResizeImage(i, 48, 48)
ImgDraw(i, bglg, 0, 0)

bgsm = GrabImage(img_root, #PB_Any, PeekL(*x), PeekL(*y), 48, 48) ;background small icon
ResizeImage(i, 32, 32)
ImgDraw(i, bgsm, 8, 8)

hover = 1

Repeat

;some garbage i've been trying...
    ;If gdk_window_get_state_(*GdkWindow) <> 0
    ;If gtk_widget_get_child_visible_(*Widget) = 0
    ;    gdk_window_show_(*GdkWindow)
    ;    SetWindowState(Main_Window, #PB_Window_Normal)
    ;    ;gdk_window_deiconify_(*GdkWindow)
    ;    ;gtk_window_deiconify_(*Widget)
    ;EndIf   
    
WE = WindowEvent()
 
;  Without gdk_window_set_type_hint_(*GdkWindow, #GDK_WINDOW_TYPE_HINT_DESKTOP) above, the below doesn't work very well.
;   If WE = #PB_Event_MinimizeWindow
;     gdk_window_show_(*GdkWindow)
;     gdk_window_raise_(*GdkWindow)
;     Debug "now"
;   EndIf
 
;change image on mouse over. 
If WindowMouseX(Main_Window) > 0 And WindowMouseX(Main_Window) < 48 And WindowMouseY(Main_Window) > 0 And WindowMouseY(Main_Window) < 48
    SetGadgetState(gimg_mainview, ImageID(bglg))
    hover = 1
ElseIf hover = 1
    SetGadgetState(gimg_mainview, ImageID(bgsm))
    hover = 0
EndIf

Until WE = #PB_Event_CloseWindow
I'm not using a composite manager, as you'll see, I have a work around for that... And yes, I know I only have it working with "Zoom" wallpaper settings so far.
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

Re: restore window

Post by GBeebe »

Hah! Change #GDK_WINDOW_TYPE_HINT_DESKTOP to #GDK_WINDOW_TYPE_HINT_DOCK and it works!

Now, the next step is to set the background of the window while not hiding other gadgets.
Post Reply