restore window
Posted: Wed Apr 07, 2010 6:17 am
How do I (with code) restore a window after hiding it by clicking the show desktop button?
Code: Select all
*win.GtkWidget = WindowID(0)
gdk_window_show_(*win\window)
gdk_window_raise_(*win\window)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_CloseWindowCode: 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