@@ -214,6 +214,8 @@ enum GTypes : UInt {
214
214
static var notificationSounds = getSystemNotificationSounds ( )
215
215
var selectedNotification : String ?
216
216
217
+ var configuredWindows = Set < UnsafeMutablePointer < GtkWidget > ? > ( )
218
+
217
219
enum DefaultSounds : String {
218
220
case Default
219
221
case None
@@ -470,6 +472,12 @@ enum GTypes : UInt {
470
472
}
471
473
return 0
472
474
} , " 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!)
473
481
}
474
482
475
483
func unsetMenu( ) {
@@ -486,11 +494,53 @@ enum GTypes : UInt {
486
494
NSApp . delegate = nil
487
495
}
488
496
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
+
489
531
func handleConversationCreated( conversation: UnsafeMutablePointer < PurpleConversation > ? ) -> gboolean {
490
532
let pidginConversation = conversation? . pointee. ui_data. assumingMemoryBound ( to: PidginConversation . self)
491
533
let conversationWindow = pidgin_conv_get_window ( pidginConversation)
492
534
let menu = conversationWindow? . pointee. menu. menubar
493
535
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)
494
544
return 0
495
545
}
496
546
0 commit comments