~ubuntu-branches/ubuntu/precise/mutter/precise

« back to all changes in this revision

Viewing changes to src/core/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-08-24 14:53:37 UTC
  • mfrom: (0.9.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110824145337-ciqrupsuyrbyfg3l
Tags: 3.1.4-0ubuntu1
* New upstream release
  - Fix Adwaita window decoration (LP: #828543)
* debian/control.in: Bump libclutter-1.0-dev build-dependency to 1.7.5
* debian/patches/03_link_gles2.patch: Refreshed
* debian/libmutter0.symbols: Adjust .symbols file

Show diffs side-by-side

added added

removed removed

Lines of Context:
584
584
    }
585
585
}
586
586
 
 
587
/* Command line arguments are passed in the locale encoding; in almost
 
588
 * all cases, we'd hope that is UTF-8 and no conversion is necessary.
 
589
 * If it's not UTF-8, then it's possible that the message isn't
 
590
 * representable in the locale encoding.
 
591
 */
 
592
static void
 
593
append_argument (GPtrArray  *args,
 
594
                 const char *arg)
 
595
{
 
596
  char *locale_arg = g_locale_from_utf8 (arg, -1, NULL, NULL, NULL);
 
597
 
 
598
  /* This is cheesy, but it's better to have a few ???'s in the dialog
 
599
   * for an unresponsive application than no dialog at all appear */
 
600
  if (!locale_arg)
 
601
    locale_arg = g_strdup ("???");
 
602
 
 
603
  g_ptr_array_add (args, locale_arg);
 
604
}
 
605
 
587
606
GPid
588
607
meta_show_dialog (const char *type,
589
608
                  const char *message,
597
616
{
598
617
  GError *error = NULL;
599
618
  GSList *tmp;
600
 
  int i=0;
601
619
  GPid child_pid;
602
 
  const char **argvl = g_malloc(sizeof (char*) *
603
 
                                (17 +
604
 
                                 g_slist_length (columns)*2 +
605
 
                                 g_slist_length (entries)));
606
 
 
607
 
  argvl[i++] = "zenity";
608
 
  argvl[i++] = type;
609
 
  argvl[i++] = "--display";
610
 
  argvl[i++] = display;
611
 
  argvl[i++] = "--class";
612
 
  argvl[i++] = "mutter-dialog";
613
 
  argvl[i++] = "--title";
 
620
  GPtrArray *args;
 
621
 
 
622
  args = g_ptr_array_new ();
 
623
 
 
624
  append_argument (args, "zenity");
 
625
  append_argument (args, type);
 
626
  append_argument (args, "--display");
 
627
  append_argument (args, display);
 
628
  append_argument (args, "--class");
 
629
  append_argument (args, "mutter-dialog");
 
630
  append_argument (args, "--title");
614
631
  /* Translators: This is the title used on dialog boxes */
615
 
  argvl[i++] = _("Mutter");
616
 
  argvl[i++] = "--text";
617
 
  argvl[i++] = message;
618
 
  
 
632
  append_argument (args, _("Mutter"));
 
633
  append_argument (args, "--text");
 
634
  append_argument (args, message);
 
635
 
619
636
  if (timeout)
620
637
    {
621
 
      argvl[i++] = "--timeout";
622
 
      argvl[i++] = timeout;
 
638
      append_argument (args, "--timeout");
 
639
      append_argument (args, timeout);
623
640
    }
624
641
 
625
642
  if (ok_text)
626
643
    {
627
 
      argvl[i++] = "--ok-label";
628
 
      argvl[i++] = ok_text;
 
644
      append_argument (args, "--ok-label");
 
645
      append_argument (args, ok_text);
629
646
     }
630
647
 
631
648
  if (cancel_text)
632
649
    {
633
 
      argvl[i++] = "--cancel-label";
634
 
      argvl[i++] = cancel_text;
 
650
      append_argument (args, "--cancel-label");
 
651
      append_argument (args, cancel_text);
635
652
    }
636
 
  
 
653
 
637
654
  tmp = columns;
638
655
  while (tmp)
639
656
    {
640
 
      argvl[i++] = "--column";
641
 
      argvl[i++] = tmp->data;
 
657
      append_argument (args, "--column");
 
658
      append_argument (args, tmp->data);
642
659
      tmp = tmp->next;
643
660
    }
644
661
 
645
662
  tmp = entries;
646
663
  while (tmp)
647
664
    {
648
 
      argvl[i++] = tmp->data;
 
665
      append_argument (args, tmp->data);
649
666
      tmp = tmp->next;
650
667
    }
651
 
    
652
 
  argvl[i] = NULL;
 
668
 
 
669
  g_ptr_array_add (args, NULL); /* NULL-terminate */
653
670
 
654
671
  if (transient_for)
655
672
    {
660
677
 
661
678
  g_spawn_async (
662
679
                 "/",
663
 
                 (gchar**) argvl, /* ugh */
 
680
                 (gchar**) args->pdata,
664
681
                 NULL,
665
682
                 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
666
683
                 NULL, NULL,
671
688
  if (transient_for)
672
689
    unsetenv ("WINDOWID");
673
690
 
674
 
  g_free (argvl);
 
691
  g_ptr_array_free (args, TRUE);
675
692
 
676
693
  if (error)
677
694
    {
691
708
typedef struct
692
709
{
693
710
  guint id;
 
711
  guint ref_count;
694
712
  MetaLaterType when;
695
713
  GSourceFunc func;
696
714
  gpointer data;
707
725
static void ensure_later_repaint_func (void);
708
726
 
709
727
static void
 
728
unref_later (MetaLater *later)
 
729
{
 
730
  if (--later->ref_count == 0)
 
731
    {
 
732
      if (later->notify)
 
733
        {
 
734
          later->notify (later->data);
 
735
          later->notify = NULL;
 
736
        }
 
737
      g_slice_free (MetaLater, later);
 
738
    }
 
739
}
 
740
 
 
741
static void
710
742
destroy_later (MetaLater *later)
711
743
{
712
744
  if (later->source)
713
 
    g_source_remove (later->source);
714
 
  if (later->notify)
715
 
    later->notify (later->data);
716
 
  g_slice_free (MetaLater, later);
 
745
    {
 
746
      g_source_remove (later->source);
 
747
      later->source = 0;
 
748
    }
 
749
  later->func = NULL;
 
750
  unref_later (later);
717
751
}
718
752
 
719
753
/* Used to sort the list of laters with the highest priority
729
763
static gboolean
730
764
run_repaint_laters (gpointer data)
731
765
{
732
 
  GSList *old_laters = laters;
 
766
  GSList *laters_copy;
733
767
  GSList *l;
734
768
  gboolean keep_timeline_running = FALSE;
735
 
  laters = NULL;
736
769
 
737
 
  for (l = old_laters; l; l = l->next)
 
770
  laters_copy = NULL;
 
771
  for (l = laters; l; l = l->next)
738
772
    {
739
773
      MetaLater *later = l->data;
740
774
      if (later->source == 0 ||
741
775
          (later->when <= META_LATER_BEFORE_REDRAW && !later->run_once))
742
776
        {
743
 
          if (later->func (later->data))
744
 
            {
745
 
              if (later->source == 0)
746
 
                keep_timeline_running = TRUE;
747
 
              laters = g_slist_insert_sorted (laters, later, compare_laters);
748
 
            }
749
 
          else
750
 
            destroy_later (later);
 
777
          later->ref_count++;
 
778
          laters_copy = g_slist_prepend (laters_copy, later);
 
779
        }
 
780
    }
 
781
  laters_copy = g_slist_reverse (laters_copy);
 
782
 
 
783
  for (l = laters_copy; l; l = l->next)
 
784
    {
 
785
      MetaLater *later = l->data;
 
786
 
 
787
      if (later->func && later->func (later->data))
 
788
        {
 
789
          if (later->source == 0)
 
790
            keep_timeline_running = TRUE;
751
791
        }
752
792
      else
753
 
        laters = g_slist_insert_sorted (laters, later, compare_laters);
 
793
        meta_later_remove (later->id);
 
794
      unref_later (later);
754
795
    }
755
796
 
756
797
  if (!keep_timeline_running)
757
798
    clutter_timeline_stop (later_timeline);
758
799
 
759
 
  g_slist_free (old_laters);
 
800
  g_slist_free (laters_copy);
760
801
 
761
802
  /* Just keep the repaint func around - it's cheap if the list is empty */
762
803
  return TRUE;
783
824
 
784
825
  if (!later->func (later->data))
785
826
    {
786
 
      laters = g_slist_remove (laters, later);
787
 
      later->source = 0;
788
 
      destroy_later (later);
 
827
      meta_later_remove (later->id);
789
828
      return FALSE;
790
829
    }
791
830
  else
821
860
  MetaLater *later = g_slice_new0 (MetaLater);
822
861
 
823
862
  later->id = ++last_later_id;
 
863
  later->ref_count = 1;
824
864
  later->when = when;
825
865
  later->func = func;
826
866
  later->data = data;