Skip to content

Commit ad23acd

Browse files
AgalinAgalin
Agalin
authored and
Agalin
committed
Register callbacks for forced redraw
1 parent 57c2bd5 commit ad23acd

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Pidgin MacOS Integration/main.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ enum GTypes : UInt {
214214
static var notificationSounds = getSystemNotificationSounds()
215215
var selectedNotification : String?
216216

217+
var configuredWindows = Set<UnsafeMutablePointer<GtkWidget>?>()
218+
217219
enum DefaultSounds : String {
218220
case Default
219221
case None
@@ -470,6 +472,12 @@ enum GTypes : UInt {
470472
}
471473
return 0
472474
}, "conversation-created", selfPtr!)
475+
register_conversation_created_callback(instance, {conversation, data in
476+
if let selfRef : Plugin = tryCast(data) {
477+
return selfRef.handleConversationDestroyed(conversation: conversation)
478+
}
479+
return 0
480+
}, "deleting-conversation", selfPtr!)
473481
}
474482

475483
func unsetMenu() {
@@ -486,11 +494,53 @@ enum GTypes : UInt {
486494
NSApp.delegate = nil
487495
}
488496

497+
static func forceRedraw(widget: UnsafeMutablePointer<GtkWidget>?) {
498+
gtk_widget_queue_draw(widget)
499+
while (gtk_events_pending () != 0)
500+
{
501+
gtk_main_iteration()
502+
}
503+
}
504+
505+
func registerRedrawCallbacks(conversationWindow: UnsafeMutablePointer<PidginWindow>?) {
506+
let window = conversationWindow?.pointee.window
507+
register_configuration_event_callback(window, { window, event, data in
508+
debug("Redraw")
509+
gtk_widget_queue_draw(window)
510+
return FALSE
511+
})
512+
let callbacks = ["switch_page", "page-added", "page-removed"]
513+
for cb in callbacks {
514+
register_switch_page_callback(conversationWindow?.pointee.notebook, cb, window) { (notebook, page, page_index, window) -> gboolean in
515+
debug("Redraw")
516+
Plugin.forceRedraw(widget: window)
517+
return FALSE
518+
}
519+
520+
}
521+
}
522+
523+
func handleConversationDestroyed(conversation: UnsafeMutablePointer<PurpleConversation>?) -> gboolean {
524+
debug("Handling destroyed conversation")
525+
let pidginConversation = conversation?.pointee.ui_data.assumingMemoryBound(to: PidginConversation.self)
526+
let conversationWindow = pidgin_conv_get_window(pidginConversation)
527+
Plugin.forceRedraw(widget: conversationWindow?.pointee.window)
528+
return 0
529+
}
530+
489531
func handleConversationCreated(conversation: UnsafeMutablePointer<PurpleConversation>?) -> gboolean {
490532
let pidginConversation = conversation?.pointee.ui_data.assumingMemoryBound(to: PidginConversation.self)
491533
let conversationWindow = pidgin_conv_get_window(pidginConversation)
492534
let menu = conversationWindow?.pointee.menu.menubar
493535
syncMenuBar(menu, visible: true)
536+
if configuredWindows.insert(conversationWindow?.pointee.window).inserted {
537+
debug("Configuring new window. Current count: \(configuredWindows.count)")
538+
registerRedrawCallbacks(conversationWindow: conversationWindow)
539+
}
540+
else {
541+
debug("Window already registered.")
542+
}
543+
Plugin.forceRedraw(widget: conversationWindow?.pointee.window)
494544
return 0
495545
}
496546

0 commit comments

Comments
 (0)