[gtk] Let printer enumeration run to completion, to avoid a GTK bug.

This commit is contained in:
Daniel Holbert 2024-01-24 16:21:26 +01:00 committed by roytam1
commit ce3cc6b74d
2 changed files with 17 additions and 1 deletions

View file

@ -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);
}

View file

@ -54,6 +54,8 @@ protected:
nsCString mSpoolName;
nsCOMPtr<nsIFile> mSpoolFile;
nsCString mTitle;
// Helper for EnumeratePrinters / PrinterEnumerator:
bool mHasEnumerationFoundAMatch = false;
private:
void EnumeratePrinters();