diff --git a/widget/gtk/nsDeviceContextSpecG.cpp b/widget/gtk/nsDeviceContextSpecG.cpp index 0bd87bd85d..a381de50a7 100644 --- a/widget/gtk/nsDeviceContextSpecG.cpp +++ b/widget/gtk/nsDeviceContextSpecG.cpp @@ -250,6 +250,12 @@ gboolean nsDeviceContextSpecGTK::PrinterEnumerator(GtkPrinter *aPrinter, gpointer aData) { nsDeviceContextSpecGTK *spec = (nsDeviceContextSpecGTK*)aData; + if (spec->mHasEnumerationFoundAMatch) { + // We're already done, but we're letting the enumeration run its course, + // to avoid a GTK bug. + return FALSE; + } + // Find the printer whose name matches the one inside the settings. nsXPIDLString printerName; nsresult rv = @@ -266,7 +272,14 @@ gboolean nsDeviceContextSpecGTK::PrinterEnumerator(GtkPrinter *aPrinter, // GTK bug (https://bugzilla.gnome.org/show_bug.cgi?id=753041). We // sidestep this by deferring the print to the next tick. NS_DispatchToCurrentThread(NewRunnableMethod(spec, &nsDeviceContextSpecGTK::StartPrintJob)); - return TRUE; + + // We're already done, but we need to let the enumeration run its course, + // to avoid a GTK bug. So we record that we've found a match and + // then return FALSE. + // TODO: If/when we can be sure that GTK handles this OK, we could + // return TRUE here to avoid some needless enumeration. + spec->mHasEnumerationFoundAMatch = true; + return FALSE; } } @@ -290,6 +303,7 @@ void nsDeviceContextSpecGTK::StartPrintJob() { void nsDeviceContextSpecGTK::EnumeratePrinters() { + mHasEnumerationFoundAMatch = false; gtk_enumerate_printers(&nsDeviceContextSpecGTK::PrinterEnumerator, this, nullptr, TRUE); } diff --git a/widget/gtk/nsDeviceContextSpecG.h b/widget/gtk/nsDeviceContextSpecG.h index 921c6275c1..ea12f9cb9c 100644 --- a/widget/gtk/nsDeviceContextSpecG.h +++ b/widget/gtk/nsDeviceContextSpecG.h @@ -54,6 +54,8 @@ protected: nsCString mSpoolName; nsCOMPtr mSpoolFile; nsCString mTitle; + // Helper for EnumeratePrinters / PrinterEnumerator: + bool mHasEnumerationFoundAMatch = false; private: void EnumeratePrinters();