LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File xdg-menu-twm.patch of Package xdg-menu (Project X11:common:Factory)

--- xdg_menu
+++ xdg_menu
@@ -1320,6 +1320,62 @@
 	return 1;
 }
 
+sub output_twm_menu ($;$$)
+{
+	my ($menu, $toplevel, $path) = @_;
+	
+	my $output = '';
+	
+	$path = '' unless defined $path;
+	
+	$toplevel = 1 unless defined $toplevel;
+
+	my $menu_name = $menu->{'PrepName'};
+	my $menu_id = "$path-" . $menu->{'Name'};
+	$menu_id =~ s/\s/_/g;
+	
+	$menu_id = 'xdg_menu' if $toplevel;
+	
+	foreach my $entry (@{$menu->{'entries'}}) {
+		if ($entry->{type} eq 'menu') {
+			$output .= output_twm_menu($entry->{'menu'}, 0, $menu_id);
+		}
+	}
+
+	$output .= "menu \"$menu_id\" {\n";
+	$output .= "\"$menu_name\" f.title\n";
+	
+	foreach my $entry (@{$menu->{'entries'}}) {
+		if ($entry->{type} eq 'desktop') {
+			my $desktop = $entry->{desktop};
+			
+			my $name = $desktop->{'PrepName'};
+			my $exec = $desktop->{'PrepExec'};
+			my $color = '';
+
+			$exec =~ s/"/\\"/g;
+			
+			$color = ' ("red":"grey")' if $desktop->{'X-KDE-SubstituteUID'} eq '1' || $desktop->{'X-KDE-SubstituteUID'} eq 'true';
+
+			$output .= "\"$name\"$color f.exec \"$exec&\"\n";
+		} 
+		elsif ($entry->{type} eq 'menu') {
+			my $name = $entry->{'menu'}{'PrepName'};
+			my $id = "$menu_id-" . $entry->{'menu'}{'Name'};
+
+			$id =~ s/\s/_/g;
+
+			$output .= "\"$name\" f.menu \"$id\"\n";
+		}
+		else {
+			print STDERR "wrong menu entry type: $entry->{type}";
+		}
+		
+	}
+	$output .= "}\n";
+	
+	return $output;
+}
 
 sub output_wmaker_menu ($;$)
 {
@@ -2101,6 +2157,11 @@
 
         $output = output_openbox3_pipe_menu($menu)
 }
+elsif ($format eq 'twm') {
+
+	print STDERR "WARNING: twm does not support umlauts. Parameter --language '' to output plain ASCII.\n" unless $language eq '';
+        $output = output_twm_menu($menu)
+}
 elsif ($format eq 'readable') {
 
 	$output = output_readable($menu)