Module: Yast::SoundJoyDialogInclude
- Defined in:
- ../../src/include/sound/joy_dialog.rb
Instance Method Summary (collapse)
-
- (Object) broken_id(index)
Create unique widget id for a broken joystick config.
-
- (Object) broken_index(id)
Get the joystick index from broken ID string.
-
- (Object) find_free_number
Find the index of the first unused joystick configuration.
-
- (Object) find_joystick(device)
Find detected joystick with requested device name.
-
- (Object) find_joystick_number(parent_id)
Find joystick index which is attached to a sound card.
-
- (Object) find_sound_card_id(sound_card)
Find index of the sound card in Sound::modules_conf.
- - (Object) initialize_sound_joy_dialog(include_target)
-
- (Object) input_mtime
Return modification time of /dev/input directory.
-
- (Object) is_broken(id)
Belogs the ID to a broken joystick?.
-
- (Object) is_usb(device)
Is the selected joystick connected via USB?.
-
- (Symbol) joy_dialog(joy_id, button, sound_card)
Joystick configuration dialog.
-
- (Object) joystick_bus_details(js, soundcards)
Get details about the joustick bus.
-
- (Object) joystick_overview
Display and run the main joystick dialog.
-
- (Object) joystick_table
Create content for the joystick overview table.
-
- (Object) refresh_table
Refresh the joystick table in the main configuration dialog.
-
- (Object) restart_joystick(num)
Save one joystick configuration and restart the joystick service to reload drivers.
-
- (Object) select_sound_card(gameport_cards)
Display dialog for selecting sound card to configure.
-
- (Object) sound_cards_with_joystick
Return the list of detected sound cards that support gameport.
-
- (Object) test_joystick(device)
Display and run the joystick test dialog.
-
- (Object) unconfigured_sound_cards(gameport_cards)
Return list of sound cards with gameport that do not have any joystick configured.
-
- (Object) update_sound_card_joy_config(card_id, start)
Update the sound card configuration of joystick.
Instance Method Details
- (Object) broken_id(index)
Create unique widget id for a broken joystick config
254 255 256 |
# File '../../src/include/sound/joy_dialog.rb', line 254 def broken_id(index) Builtins.sformat("broken_%1", index) end |
- (Object) broken_index(id)
Get the joystick index from broken ID string
268 269 270 271 272 273 274 |
# File '../../src/include/sound/joy_dialog.rb', line 268 def broken_index(id) num = Builtins.regexpsub(id, "broken_([0-9]+)", "\\1") return nil if num == nil Builtins.tointeger(num) end |
- (Object) find_free_number
Find the index of the first unused joystick configuration
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File '../../src/include/sound/joy_dialog.rb', line 748 def find_free_number i = 0 found = false Builtins.foreach( Convert.convert(Joystick.joystick, :from => "list", :to => "list <map>") ) do |j| if Ops.get_string(j, "JOYSTICK_MODULE", "") == "" found = true raise Break end i = Ops.add(i, 1) end ret = i ret = nil if !found Builtins.y2milestone("Unconfigured joystick at index: %1", ret) ret end |
- (Object) find_joystick(device)
Find detected joystick with requested device name
461 462 463 464 465 |
# File '../../src/include/sound/joy_dialog.rb', line 461 def find_joystick(device) Builtins.find(Joystick.Detected) do |j| Ops.get_string(j, "dev_name2", "") == device end end |
- (Object) find_joystick_number(parent_id)
Find joystick index which is attached to a sound card
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File '../../src/include/sound/joy_dialog.rb', line 720 def find_joystick_number(parent_id) i = 0 found = false Builtins.foreach( Convert.convert(Joystick.joystick, :from => "list", :to => "list <map>") ) do |j| if Ops.get_string(j, "attached_to", "") == parent_id found = true raise Break end i = Ops.add(i, 1) end ret = i ret = nil if !found Builtins.y2milestone( "Joystick index with parent id %1: %2", parent_id, ret ) ret end |
- (Object) find_sound_card_id(sound_card)
Find index of the sound card in Sound::modules_conf
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File '../../src/include/sound/joy_dialog.rb', line 74 def find_sound_card_id(sound_card) sound_card = deep_copy(sound_card) i = 0 ret = nil Builtins.foreach(Sound.modules_conf) do |card| if Ops.get_string(card, "unique_key", "") == Ops.get_string(sound_card, "unique_key", "") ret = i end i = Ops.add(i, 1) end ret end |
- (Object) initialize_sound_joy_dialog(include_target)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File '../../src/include/sound/joy_dialog.rb', line 11 def initialize_sound_joy_dialog(include_target) Yast.import "UI" textdomain "sound" Yast.import "Wizard" Yast.import "WizardHW" Yast.import "Joystick" Yast.import "Sound" Yast.import "Package" Yast.import "Label" Yast.import "Popup" Yast.import "String" Yast.include include_target, "sound/joysticks.rb" Yast.include include_target, "sound/ui.rb" Yast.include include_target, "sound/volume_routines.rb" Yast.include include_target, "sound/routines.rb" # notice about USB devices, used at several places @usb_notice = _( "USB joysticks do not need any configuration, just connect them." ) @gameport = "Gameport" end |
- (Object) input_mtime
Return modification time of /dev/input directory
819 820 821 822 823 824 825 |
# File '../../src/include/sound/joy_dialog.rb', line 819 def input_mtime Ops.get_integer( Convert.to_map(SCR.Read(path(".target.stat"), "/dev/input")), "mtime", 0 ) end |
- (Object) is_broken(id)
Belogs the ID to a broken joystick?
261 262 263 |
# File '../../src/include/sound/joy_dialog.rb', line 261 def is_broken(id) Builtins.regexpmatch(id, "broken_[0-9]+") end |
- (Object) is_usb(device)
Is the selected joystick connected via USB?
710 711 712 713 714 715 |
# File '../../src/include/sound/joy_dialog.rb', line 710 def is_usb(device) js = find_joystick(device) return false if js == nil Ops.get_string(js, "bus", "") == "USB" end |
- (Symbol) joy_dialog(joy_id, button, sound_card)
Joystick configuration dialog. Configuration of joystick attached to specified sound card.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File '../../src/include/sound/joy_dialog.rb', line 96 def joy_dialog(joy_id, , sound_card) sound_card = deep_copy(sound_card) return :back if joy_id == nil # find card name cardname = Ops.get_string(sound_card, "model", "") # dialog header - %1: card name (e.g "Soundblaster 16") caption = Builtins.sformat(_("Joystick Configuration - %1"), cardname) helptext = # help text for joystick configuration 1/4 _( "<P>In this dialog, specify your joystick type. If your\n" + "joystick type is not in the list, select <B>Generic Analog Joystick</B>.</p>\n" + "<p>You will not find any USB joysticks here. If you have a USB device, just plug in the joystick and start using it.</P>\n" ) joy = Ops.get_map(Joystick.joystick, joy_id, {}) mod = Ops.get_string(joy, "model", "") Builtins.y2milestone("Joystick configuration started, index: %1", joy_id) # translate model from /etc/sysconfig/joystick if mod == Joystick.generic_joystick mod = Joystick.generic_joystick_translated end # list of joystick drivers and models joylist = Builtins.maplist(@JoystickDB) do |modname, models| Builtins.maplist(models) { |model| [modname, model] } end joylist = Builtins.flatten( Convert.convert(joylist, :from => "list", :to => "list <list>") ) joylist = Builtins.sort( Convert.convert(joylist, :from => "list", :to => "list <list>") ) do |j1, j2| Ops.less_than(Ops.get_string(j1, 1, ""), Ops.get_string(j2, 1, "")) end joylist = Builtins.prepend( joylist, ["analog", Joystick.generic_joystick_translated] ) Builtins.y2debug("joylist: %1", joylist) index = 0 boxitems = [] Builtins.foreach( Convert.convert(joylist, :from => "list", :to => "list <list>") ) do |l| model = Ops.get_string(l, 1, "") if mod == model # preselect item boxitems = Builtins.add(boxitems, Item(Id(index), model, true)) else boxitems = Builtins.add(boxitems, Item(Id(index), model)) end index = Ops.add(index, 1) end Builtins.y2debug("for widget: %1", boxitems) contents = VBox( VSpacing(3), HBox( HSpacing(3), # label above list of joystick types SelectionBox(Id(:os), _("&Select your joystick type:"), boxitems), HSpacing(3) ), VSpacing(3) ) = { :finish => Label.FinishButton, :ok => Label.OKButton, :next => Label.NextButton } Wizard.OpenNextBackDialog Wizard.SetContents(caption, contents, helptext, true, true) Wizard.SetNextButton(:next, Ops.get_string(, ) do Label.NextButton end) Wizard.HideBackButton if !Mode.installation s = nil begin s = Convert.to_symbol(UI.UserInput) s = :skip_event if s == :abort && !ReallyAbort() if s == :next && UI.QueryWidget(Id(:os), :CurrentItem) == nil # warning message - user did not select any joystick type Popup.Warning( _( "Select the joystick type from the list\n" + "before pressing Next.\n" + "\n" ) ) s = :skip end end while !Builtins.contains([:next, :back, :abort, :cancel], s) if s == :next card_id = find_sound_card_id(sound_card) modname = Ops.get_string(Sound.modules_conf, [card_id, "module"], "") joy_entry = Sound.GetJoystickSettings(modname) joymodidx = Convert.to_integer(UI.QueryWidget(Id(:os), :CurrentItem)) joymod = Ops.get_string(joylist, [joymodidx, 0], "") if joymod == "" # selected none joystick joy_entry = {} else model = Ops.get_string(joylist, [joymodidx, 1], "") # do not translate model in /etc/sysconfig/joystick if model == Joystick.generic_joystick_translated model = Joystick.generic_joystick end Builtins.y2debug("selected joy module: %1, model: %2", joymod, model) Ops.set(joy_entry, "JOYSTICK_MODULE", joymod) Ops.set(joy_entry, "model", model) Ops.set( joy_entry, "attached_to", Ops.get_string(sound_card, "unique_key", "") ) end update_sound_card_joy_config(card_id, joymod != "") Ops.set(Joystick.joystick, joy_id, joy_entry) Joystick.modified = true Builtins.y2milestone("New joystick configuration: %1", joy_entry) end # restore previous `next button label (only if label was not Finish) Wizard.RestoreNextButton if != :finish Wizard.RestoreBackButton if !Mode.installation Wizard.CloseDialog s end |
- (Object) joystick_bus_details(js, soundcards)
Get details about the joustick bus
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File '../../src/include/sound/joy_dialog.rb', line 280 def joystick_bus_details(js, soundcards) js = deep_copy(js) soundcards = deep_copy(soundcards) ret = Ops.get_string(js, "bus", "") if ret == @gameport unique_key = Ops.get_string(js, "parent_unique_key", "") card = Builtins.find(soundcards) do |c| Ops.get_string(c, "unique_key", "") == unique_key end if card != nil # joystick details, %1 is the sound card name to which is the joystick connected ret = Builtins.sformat( _("%1 (%2)"), ret, Ops.get_string(card, "model", "") ) end end ret end |
- (Object) joystick_overview
Display and run the main joystick dialog
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
# File '../../src/include/sound/joy_dialog.rb', line 829 def joystick_overview = [ # menu item [:test, _("&Test selected joystick...")] ] # dialog title WizardHW.CreateHWDialog( _("Joysticks"), Ops.add( Ops.add( # help text _("<p><big><b>Joysticks</b></big></p>") + _("<p>Here is an overview of the detected joysticks.</p>") + _( "<p>To configure a new joystick connected to a Gameport press <b>Add</b> button.</p>" ) + "<p>", @usb_notice ), "</p>" ), # table header [_("Model"), _("Device name"), _("Attached to")], ) # create description for WizardHW items = joystick_table Builtins.y2debug("items: %1", items) WizardHW.SetContents(items) Wizard.SetNextButton(:next, Label.FinishButton) ret = :dummy mtime = input_mtime while !Builtins.contains([:abort, :back, :next], ret) ret = Convert.to_symbol(UI.TimeoutUserInput(2000)) # no user input, check for hotplug changes if ret == :timeout current_mtime = input_mtime if current_mtime != mtime # /dev/input has changed - rescan joysticks and refresh the table Builtins.y2milestone( "/dev/input has been changed, rescanning devices..." ) Joystick.Detect refresh_table mtime = current_mtime end next end ret = :abort if ret == :cancel device = WizardHW.SelectedItem if ret == :add jcards = sound_cards_with_joystick Builtins.y2milestone("Sound cards with gameport: %1", jcards) # no sound card with gameport if Builtins.size(jcards) == 0 = Ops.add( _("There is no soundcard with joystick support (gameport).") + "\n", @usb_notice ) Popup.Message() else # remove configured cards with joystick unconfigured = unconfigured_sound_cards(jcards) Builtins.y2milestone( "Gamport sound cards without joystick: %1", unconfigured ) if Builtins.size(unconfigured) == 0 = Ops.add( _("There is no soundcard with unconfigured joystick.") + "\n", @usb_notice ) Popup.Message() else # if there is just one card just use it otherwise ask user card = Builtins.size(unconfigured) == 1 ? Ops.get_map(unconfigured, 0, {}) : select_sound_card(unconfigured) joy_index = find_free_number # selection canceled? if card != nil joy_dialog(joy_index, :ok, card) restart_joystick(joy_index) refresh_table end end end elsif ret == :edit if is_usb(device) # popup message - pressed [Edit] when an USB joystick is selected Popup.Message("USB joysticks do not need any configuration.") else num = nil key = "" if is_broken(device) num = broken_index(device) j = Ops.get_map(Joystick.joystick, num, {}) key = Ops.get_string(j, "attached_to", "") else key = Ops.get_string( find_joystick(device), "parent_unique_key", "" ) num = find_joystick_number(key) end soundcards = Convert.convert( SCR.Read(path(".probe.sound")), :from => "any", :to => "list <map>" ) card = Builtins.find(soundcards) do |c| Ops.get_string(c, "unique_key", "") == key end ui = joy_dialog(num, :ok, card) if ui == :next || ui == :finish # restart joystick service to reload the driver restart_joystick(num) # refresh table content refresh_table end end elsif ret == :delete if is_usb(device) # popup message - pressed [Delete] when an USB joystick is selected Popup.Message("USB joysticks cannot be deleted, just unplug them.") else num = is_broken(device) ? broken_index(device) : find_joystick_number( Ops.get_string(find_joystick(device), "parent_unique_key", "") ) Builtins.y2milestone("Deleting joystick %1 (index %2)", device, num) # modify joystick config Ops.set(Joystick.joystick, num, {}) Joystick.modified = true # restart joystick service to reload the driver restart_joystick(num) # refresh table content refresh_table end elsif ret == :test if is_broken(device) # error popup Popup.Error( _( "The selected joystick configuration is not active.\n" + "\n" + "The joystick cannot be tested." ) ) else test_joystick(device) end end end Builtins.y2milestone("Final joystick config: %1", Joystick.joystick) Builtins.y2milestone("Joystick overview result: %1", ret) ret end |
- (Object) joystick_table
Create content for the joystick overview table
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File '../../src/include/sound/joy_dialog.rb', line 307 def joystick_table content = [] soundcards = Convert.convert( SCR.Read(path(".probe.sound")), :from => "any", :to => "list <map>" ) found_joysticks = [] Builtins.foreach(Joystick.Detected) do |js| Builtins.y2milestone("Adding joystick to table: %1", js) device = Ops.get_string(js, "dev_name2", "") model = Ops.get_string(js, "model", "") descr = [] if Ops.greater_than(Ops.get_integer(js, ["detail", "axes"], 0), 0) descr = Builtins.add( descr, Builtins.sformat( _("Number of axes: %1"), Ops.get_integer(js, ["detail", "axes"], 0) ) ) end if Ops.greater_than(Ops.get_integer(js, ["detail", "buttons"], 0), 0) descr = Builtins.add( descr, Builtins.sformat( _("Number of buttons: %1"), Ops.get_integer(js, ["detail", "buttons"], 0) ) ) end bus = Ops.get_string(js, "bus", "") # add the sound card name for gameport joysticks if bus == @gameport && Ops.greater_than( Builtins.size(Ops.get_string(js, "parent_unique_key", "")), 0 ) bus = joystick_bus_details(js, soundcards) unique_key = Ops.get_string(js, "parent_unique_key", "") i2 = 0 joy_index = nil while Ops.less_than(i2, 4) jconf = Ops.get_map(Joystick.joystick, i2, {}) if Ops.get_string(jconf, "attached_to", "") == unique_key joy_index = i2 break end i2 = Ops.add(i2, 1) end if joy_index != nil j_config = Builtins.find( Convert.convert( Joystick.joystick, :from => "list", :to => "list <map>" ) ) do |j2| Ops.get_string(j2, "attached_to", "") == unique_key end config_model = Ops.get_string(j_config, "model", "") if config_model != nil && config_model != "" Builtins.y2milestone("Adding joystick model: %1", config_model) model = Builtins.sformat("%1 (%2)", model, config_model) end found_joysticks = Builtins.add(found_joysticks, joy_index) end end j = { "id" => device, "table_descr" => [model, device, bus], "rich_descr" => WizardHW.CreateRichTextDescription(model, descr) } content = Builtins.add(content, j) end Builtins.y2milestone("Found joysticks at indices: %1", found_joysticks) i = 0 # check non-working joystick configurations Builtins.foreach( Convert.convert(Joystick.joystick, :from => "list", :to => "list <map>") ) do |js| if !Builtins.contains(found_joysticks, i) && Ops.get_string(js, "JOYSTICK_MODULE", "") != "" Builtins.y2milestone( "Found inactive joystick configuration at index %1: %2", i, js ) model = Ops.get_locale(js, "model", _("Unknown joystick model")) unique_key = Ops.get_string(js, "attached_to", "") bus = @gameport card = Builtins.find(soundcards) do |c| Ops.get_string(c, "unique_key", "") == unique_key end if card != nil # joystick details, %1 is the sound card name to which is the joystick connected bus = Builtins.sformat( "%1 (%2)", bus, Ops.get_string(card, "model", "") ) end j = { "id" => broken_id(i), # the joystick device was not found (the joystick is probably disconnected) "table_descr" => [ model, _("<not found>"), bus ], # add red warning about invalid configuration to the model name (%1) "rich_descr" => WizardHW.CreateRichTextDescription( Builtins.sformat( _("%1 - <font color=\"red\">Invalid configuration<font>"), model ), [ # help text _( "The configuration is not active - either the joystick is not connected or a wrong driver is used" ), # help text _( "Press <b>Edit</b> to change the joystick driver or <b>Delete</b> to remove the configuration" ) ] ) } content = Builtins.add(content, j) end i = Ops.add(i, 1) end deep_copy(content) end |
- (Object) refresh_table
Refresh the joystick table in the main configuration dialog
786 787 788 789 790 791 |
# File '../../src/include/sound/joy_dialog.rb', line 786 def refresh_table items = joystick_table WizardHW.SetContents(items) nil end |
- (Object) restart_joystick(num)
Save one joystick configuration and restart the joystick service to reload drivers
772 773 774 775 776 777 778 779 780 781 782 783 |
# File '../../src/include/sound/joy_dialog.rb', line 772 def restart_joystick(num) # restart joystick service to reload the driver Joystick.Stop Joystick.SaveOneJoystick(num) Joystick.WriteConfig Joystick.StartAndEnable # re-detect attached joysticks Joystick.Detect nil end |
- (Object) select_sound_card(gameport_cards)
Display dialog for selecting sound card to configure
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
# File '../../src/include/sound/joy_dialog.rb', line 654 def select_sound_card(gameport_cards) gameport_cards = deep_copy(gameport_cards) i = -1 tcont = Builtins.maplist( Convert.convert(gameport_cards, :from => "list", :to => "list <map>") ) do |card| i = Ops.add(i, 1) Item(Id(i), Ops.get_string(card, "model", "Sound card")) end dialog = HBox( VSpacing(10), VBox( Heading(_("Sound Cards with Joystick Support")), Table( Id(:cards), Header( # table header (card name) _("Sound card") ), tcont ), Label( _("To add an USB joystick close this dialog and just connect it.") ), ButtonBox( # button label PushButton(Id(:ok), _("&Configure joystick")), PushButton(Id(:cancel), Label.CancelButton) ) ) ) UI.OpenDialog(Opt(:decorated), dialog) # preselect the first card UI.ChangeWidget(Id(:cards), :CurrentItem, 0) ret = Convert.to_symbol(UI.UserInput) joy_card = Convert.to_integer(UI.QueryWidget(Id(:cards), :CurrentItem)) Builtins.y2milestone("Selected sound card: %1", joy_card) UI.CloseDialog if ret == :cancel || ret == :abort Builtins.y2milestone("Sound card selection canceled") return nil end Ops.get_map(gameport_cards, joy_card, {}) end |
- (Object) sound_cards_with_joystick
Return the list of detected sound cards that support gameport
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 |
# File '../../src/include/sound/joy_dialog.rb', line 795 def sound_cards_with_joystick sound_cards = Convert.convert( SCR.Read(path(".probe.sound")), :from => "any", :to => "list <map>" ) sound_cards = Builtins.filter(sound_cards) do |sound_card| driver = Ops.get_string(get_module(sound_card), "name", "") if driver == nil || driver == "" driver = String.Replace( Ops.get_string(sound_card, "driver_module", ""), "_", "-" ) end Ops.get_map(Sound.db_modules, [driver, "joystick"], {}) != {} end deep_copy(sound_cards) end |
- (Object) test_joystick(device)
Display and run the joystick test dialog
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File '../../src/include/sound/joy_dialog.rb', line 469 def test_joystick(device) js = find_joystick(device) if js == nil Builtins.y2error("Cannot find joystick %1", device) return end # generate appropriate dialog for the joystick joy_attrib = VBox() min = -32767 # see js_event.value in linux/joystick.h max = 32767 i = 0 while Ops.less_than(i, Ops.get_integer(js, ["detail", "axes"], 0)) # progress bar label = Builtins.sformat(_("Axis %1"), i) = Builtins.sformat("Axis %1", i) if UI.HasSpecialWidget(:Slider) joy_attrib = Builtins.add( joy_attrib, Slider(Id(), Opt(:disabled), , min, max, 0) ) else joy_attrib = Builtins.add( joy_attrib, IntField(Id(), Opt(:disabled), , min, max, 0) ) end joy_attrib = Builtins.add(joy_attrib, VSpacing(0.3)) i = Ops.add(i, 1) end = HBox() not_pressed = " " pressed = UI.Glyph(:CheckMark) i = 0 while Ops.less_than(i, Ops.get_integer(js, ["detail", "buttons"], 0)) # label = Builtins.sformat(_("Button %1"), i) = Builtins.sformat("Button %1", i) = Builtins.add( , Label(Id(), Ops.add(Ops.add(, " "), not_pressed)) ) = Builtins.add(, HSpacing(2)) i = Ops.add(i, 1) end joy_attrib = Builtins.add(joy_attrib, ) UI.OpenDialog( Opt(:decorated), HBox( HSpacing(1.5), VSpacing(18), VBox( HSpacing(50), VSpacing(0.5), # Popup label Heading(_("Joystick Test")), VSpacing(0.5), # label - joystick details (%1 is model name, %2 is bus name) Left( Label( Builtins.sformat( _("Joystick: %1, attached to: %2"), Ops.get_string(js, "model", ""), joystick_bus_details( js, Convert.convert( SCR.Read(path(".probe.sound")), :from => "any", :to => "list <map>" ) ) ) ) ), #`VSpacing(0.5), joy_attrib, VSpacing(1), PushButton(Id(:done), Opt(:default), Label.OKButton), VSpacing(1) ), HSpacing(1.5) ) ) command = Builtins.sformat( "/usr/bin/jstest --event '%1'", String.Quote(device) ) process = Convert.to_integer( SCR.Execute(path(".process.start_shell"), command) ) ret = nil begin if SCR.Read(path(".process.running"), process) == false Builtins.y2error("Unexpected exit") break end out = Convert.to_string(SCR.Read(path(".process.read_line"), process)) if out != nil Builtins.y2debug("jstest output: %1", out) # the output is like "Event: type 2, time 26263500, number 0, value 0" type_str = Builtins.regexpsub(out, "type ([0-9]+)", "\\1") number_str = Builtins.regexpsub(out, "number ([0-9]+)", "\\1") value_str = Builtins.regexpsub(out, "value ([-]{0,1}[0-9]+)", "\\1") if type_str != nil && number_str != nil && value_str != nil type = Builtins.tointeger(type_str) number = Builtins.tointeger(number_str) value = Builtins.tointeger(value_str) if type == 1 # button state changed UI.ChangeWidget( Id(Builtins.sformat("Button %1", number)), :Value, Ops.add( Ops.add( # label text ("Button" is joystick's button no. %1) Builtins.sformat(_("Button %1"), number), " " ), value == 1 ? pressed : not_pressed ) ) elsif type == 2 # change in some axis UI.ChangeWidget( Id(Builtins.sformat("Axis %1", number)), :Value, value ) end end end ret = Convert.to_symbol(UI.PollInput) end while ret == nil Builtins.y2milestone("killing") SCR.Execute(path(".process.kill"), process) # release the process from the agent SCR.Execute(path(".process.release"), process) UI.CloseDialog nil end |
- (Object) unconfigured_sound_cards(gameport_cards)
Return list of sound cards with gameport that do not have any joystick configured
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 |
# File '../../src/include/sound/joy_dialog.rb', line 630 def unconfigured_sound_cards(gameport_cards) gameport_cards = deep_copy(gameport_cards) ret = Builtins.filter( Convert.convert(gameport_cards, :from => "list", :to => "list <map>") ) do |card| Builtins.find( Convert.convert( Joystick.joystick, :from => "list", :to => "list <map>" ) ) do |j| Ops.get_string(j, "attached_to", "") == Ops.get_string(card, "unique_key", "") end == nil end Builtins.y2milestone("Unconfigured gameport cards: %1", ret) deep_copy(ret) end |
- (Object) update_sound_card_joy_config(card_id, start)
Update the sound card configuration of joystick
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File '../../src/include/sound/joy_dialog.rb', line 41 def update_sound_card_joy_config(card_id, start) = Ops.get_map(Sound.modules_conf, [card_id, "options"], {}) modname = Ops.get_string(Sound.modules_conf, [card_id, "module"], "") return false if !Builtins.haskey(Sound.joystick_configuration, modname) joy_option = Ops.get_map(Sound.joystick_configuration, modname, {}) opname = "" value = "0" # there should be only one entry Builtins.foreach(joy_option) do |name, val| opname = name value = val end default_value = Ops.get_string( Sound.db_modules, [modname, "params", opname, "default"], "0" ) if start && Ops.get_string(, opname, default_value) == default_value || !start && Ops.get_string(, opname, default_value) != default_value Ops.set(, opname, start ? value : default_value) Ops.set(Sound.modules_conf, [card_id, "options"], ) return true end false end |